Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Enviroment Variables DONT WORK

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,46611
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Enviroment Variables DONT WORK
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Enviroment Variables DONT WORK - 5/3/2007 7:37:13 PM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
Iam having a hard time. Maybe someone can help me out. I need to set a envirmoent variable and retrive by a cmd using %variable%. yes i have googled a lot... the code:

Set objShell = WScript.CreateObject("WScript.Shell")
Set colUsrEnvVars = objShell.Environment("PROCESS")
colUsrEnvVars("TEMP") = "Upgraded"
Wscript.Echo ObjShell.ExpandEnvironmentStrings("%TEMP%")

then I go to cmd and and type
echo %temp%

and IT IS NOT the value I set!!!! HELP MEEEeeee

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net
 
 
Post #: 1
 
 RE: Enviroment Variables DONT WORK - 5/3/2007 10:10:02 PM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
First of all, you shouldn't reuse an existing variable name like TEMP.  If the desktop is running Win2000 or later you should use SYSTEM

Set objShell = WScript.CreateObject("WScript.Shell")
Set colUsrEnvVars = objShell.Environment("SYSTEM")
colUsrEnvVars("myVar") = "Upgraded"
Wscript.Echo colUsrEnvVars("myVar")

You also won't see the new variable until you open a new CMD window. 

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to 4scriptmoni)
 
 
Post #: 2
 
 RE: Enviroment Variables DONT WORK - 5/4/2007 12:46:10 AM   
  4scriptmoni


Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
temp was just a example.
still if open a new cmd window i lose the purpose of what i was trying to do...
i was passing a sys variable to a .exec cmd
like:
("cmd /c logoff  %sessionid%  /server:" & servername )       


but i have figured out another way.
like:
("cmd /c logoff " & resultid & " /server:" & servername )       
duhh..

thanks anyways for the post.

_____________________________

Enterprise Microsoft Scripts
Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc...
http://www.felipeferreira.net

(in reply to SAPIENScripter)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Enviroment Variables DONT WORK Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts