hannable80
Technical User
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
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