none
vbs script will run on xp but not on Windows 7 - permission denied

    Question

  • I have a vbs script that would run on XP, but will not run on windows 7.
    I have simplified the script as follows:

    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("SYSTEM")
    WshSysEnv("Test") = "1234"

    If I run this in a command prompt as administartor the script runs without any issues.

    If I run this by double clicking the file, I get:

    Error: permission denied
    Code: 800A0046

    I realise this is something to do with security in windows 7, but am unsure how to resolve it.
    I am logged in as a local admin and domain admin.
    My goal is for standard users to be able to run the script.

    I am not sure how I can make the script work. Is there a way of elevating the security of the script etc...
    Any help would be welcome. If you need any further info, please ask.

    This is my first time in the forum, so if I am doing anything wrong, please let me know.

    Friday, March 05, 2010 11:53 AM

Answers

All replies

  • Mike,

    Your trying to change a "system" envrioment variable and only adminstrators  have the permissions to do this.
    A standart user can only change "user" envroiment variables.

    So try this ...
    Set WshShell = CreateObject("WScript.Shell")
    Set WshSysEnv = WshShell.Environment("USER")
    WshSysEnv("Test") = "1234"
    
    What is the difference between "System" and "User".

    For example you define a system variable %SYSVAR%.
    All the users who logon to your machine can use the %SYSVAR%.

    If you define for the user DFT a user variable %USERVAR%.
    Then is the %USERVAR% only aviable for the user DFT.
    And all other users who logon on your machine can't use the %USERVAR%.

    That is allso the reason why you need admin permissions for system and not for user.

    Kind Regards
    DFT


    IM me - TWiTTer: @DFTER
    • Proposed as answer by daft Friday, March 05, 2010 1:07 PM
    Friday, March 05, 2010 1:06 PM
  • DFT

    Thanks for the quick response.
    I am aware of that this is a system variable rather than a user variable, however I am logged in as an administrator (I am a member of the local administrators group). This worked with no issues in Windows XP, but is not allowed in windows 7.

    I realise the security has been increased with windows 7, but there must be a way of telling windows to accept certain scripts or "elevate" the permissions of a script without a user having to run the script as administrator?

    Any help would be much appreciated.

    Regards Mike
    Friday, March 05, 2010 4:34 PM
  • Hi,

    I would like to share you the following article:
     
    Group-Aware Logon Scripts

    Meanwhile, Windows 7 forum is only focus on Windows 7 feature and configuration. Regarding the Script issue, I suggest you create a new thread in following forum.

    Windows Forms General

    Thanks,
    Novak
    • Marked as answer by Novak Wu Wednesday, March 17, 2010 2:04 AM
    Wednesday, March 10, 2010 4:19 AM