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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Variable for System enviroment Variables Another Pain HELP!!!!

Status
Not open for further replies.

hannable80

Technical User
Apr 5, 2006
28
GB
Hi,

I can manipulate the User variable in the system enviroment variable!!!! I need this to be done through WMI as i have half the sript working fine over the network.....I need to find out how to add a User enviroment variable.....I have done this using wsh (previous post) Can anyone help cant find any info on the net!!!


' This script manipualtes the system environment var's fine.

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
' Each value in the Array must end with a semicolon ";"
strArraySearchFor=Array("c:\log;", "c:\logs;")
' WMI Section which connects to registry (StdRegProv)
' Gets value for strValue (GetExpandedStringValue)
Set objReg=GetObject _
("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" _
& strComputer & "\root\default:StdRegProv")
PathToAdd = "P:\working test!!!"
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strEntryName = "path"
objReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
strEntryName,strValue
If Not (InStr(1, strValue, PathToAdd & ";") Or Right(strValue, Len(PathToAdd)) = PathToAdd) Then 'If it already exists, don't add it again
If Right(strValue, 1) <> ";" Then strValue = strValue & ";" 'check for semi colon at the end
strValue = strValue & PathToAdd
'MsgBox Path
WshSysEnv.Item("PATH") = strValue
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top