Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript setting environment variables but executable not picking up them up

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!

like image 615
Paragon_ Avatar asked Mar 19 '26 09:03

Paragon_


1 Answers

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;

  • System
  • User
  • Volatile
  • Process

Would recommend changing the code to use;

Set objEnv = objShell.Environment("SYSTEM")

and go from there.

like image 59
user692942 Avatar answered Mar 23 '26 23:03

user692942



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!