I have the below VBScript (values and names changed)
Dim InstanceName
Set objShell = WScript.CreateObject("WScript.Shell")
Set objEnv = objShell.Environment("USER")
objEnv("PLUGIN") = "plugin"
objEnv("CONF") = "location"
Set ArgObj=Wscript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("path.txt", 1)
AbsolutePath = objTextFile.ReadLine
objTextFile.Close
directory = "C:\Program Files\"&AbsolutePath&"\bin"
executable = directory&"\app-"&InstanceName&".exe"
objShell.CurrentDirectory = directory
objShell.Run Chr(34) & executable & Chr(34), 1, false
Set objShell = Nothing
My program uses the environment variables PLUGIN and CONF. However, the first time the program is launched using the script, it cannot find the environment variables. The subsequent launches work fine as the environment variables are already set.
I can see them when I check in control panel even after the first launch but the executable doesn't seem to pick them up.
How can I make the variables be set correctly for the executable the first time the script is run?
Thanks!
The problem is that the values are not being stored as User environment variables. Reading through the documentation you want to make sure that you set the Environment property of the WScript.Shell object to the correct set of environment variables, as per the documentation the values are;
Would recommend changing the code to use;
Set objEnv = objShell.Environment("SYSTEM")
and go from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With