Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a session environment variable??

Status
Not open for further replies.

sparkbyte

Technical User
Sep 20, 2002
879
0
0
US
I need to be able to set a session based environment variable for an application to run properly.

Code:
Dim objShell
set objShell = CreateObject("wscript.Shell")

        sExePath = "E:\PROGRA~1\CoreDir\CORE_M~1\SYNERG~1\dbl\bin\dbr.exe"
        sSwitches = "BIN:MNUMNU"
            objShell.exec [red][b]"SET E:\PROGRA~1\CoreDir\Users\" & strUser & "\BK" & strBank[/b][/red] &_ 
            " && " & Chr(34) & sExePath & Chr(34) & " " & sSwitches

This fails with a cannot find file error. I assume this is because of the SET ... && ... (trying to run 2 commands from one command line input.

Can someone help me here? It needs to be done as a session only variable because using the "USER" of "SYSTEM" setting causes problems with our support staff because the envionment variable set at that level makes it so they cannot deal with multiple open sessions set to different banks.

Thanks


Thanks

John Fuhrman
Titan Global Services
faq329-6766
 
Anyway, the SET instruction is wrong.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, hit submit too fast.
Furthermore you have to execute the command interpreter:
objShell.exec "CMD /C SET yourVariable=E:\PROGRA~1\CoreDir\Users\" & strUser & "\BK" & strBank & _
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, I have tried adding the comspec and this did help. What happens now is that the environment variable gets set but the 2nd command is never ran and the DOS windows is stuck open until you kill the process for CMD.

Thanks

Thanks

John Fuhrman
Titan Global Services
faq329-6766
 
Dim WshShell: Set WshShell = CreateObject("Wscript.Shell")

'Write to Users env variables

WshShell.Environment("USER").Item("TMP") = "C:\%systemroot%\TMP"
WshShell.Environment("USER").Item("TEMP") = "C:\%systemroot%\TEMP"

'Write to System env variables
WshShell.Environment("SYSTEM").Item("YourName3") = "world"
 
You can use the code below to obtain an existing environment variable:

set objShell=CreateObject("wscript.shell")
strTemp=objShell.ExpandEnvironmentStrings("%temp%")


I believe there is a related function to set a variable aswell - just not sure exactly what it is !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top