locked
VB Script access denied error on WshSystemEnv (setting environment variable) Help? RRS feed

  • Question

  • I have a vbs script which sets permanent environmental variables in Vista..

    I get an access denied when it tries to run the line with WshSystemEnv("test")...

    Does anyone know how to make this work (with UAC turned on) in Vista?

    Here is the code:

    Set WshShell = CreateObject("WScript.Shell")

    ' makes environment settings permanent
    Set WshSystemEnv = WshShell.Environment("SYSTEM")


    ' Set environment variable
    WshSystemEnv("test") = "1234"

    Thanks!

    Thursday, February 1, 2007 4:32 PM

Answers

All replies

  • I was able to get this to work (sortof) via a GPO and a wmi filter based on 32bit address width values:

    Problem I have now is this:

     

    I want to set a new variable such as ProgramFilesx86 (note the lack of parenthesis) = c:\program files if 32bit and c:\program files (x86) if 64bit..

    but I need that c drive to be variable.. ie:  reflect %systemdrive% instead...

    If I put %systemdrive% in the GPO adm template.. it just remains in that form for the environment variable value.. ie:  it doesnt become C: or G: etc..

    Any ideas on how to do this part?

     

     

    Here is the adm code that doesnt quite work with the %variable%

     

    CLASS MACHINE
    CATEGORY "Env Variables"
     POLICY "Set 32BIT"
      KEYNAME "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
      PART "ProgramFilesx86"
      EDITTEXT
      VALUENAME "ProgramFilesx86"
      DEFAULT "%SystemDrive%:\Program Files"
      END PART
     END POLICY
    END CATEGORY

     

     

     

     

    Thursday, February 1, 2007 8:24 PM
  • Try this area as a good source of information for Programing Vista Apps

     

    http://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=24&SiteID=1

    Wednesday, February 14, 2007 5:10 PM