Hi
I'm trying to install a registry key only if the registry key does not already exist but when I run the code the script installs the key regardless.
CODE:
'-----------------------------------------------
On Error Resume Next
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set ws = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
strCMD = "CMD /k" & " " & "REG DELETE " & strComputer & "HKLMSoftwareTestKey"
ws.Run strCMD
If Err.Number 0 Then
'WScript.Echo strComputer & " " & "Error: " & Err.Number
WScript.Echo strComputer & " " & "Registry key found"
Err.Clear
ELSE
strCMD2 = "CMD /k" & " " & "REG ADD " & strComputer & "HKLMSoftwareTestKey"
ws.Run strCMD2
End If
Next
'-------------------------------------------------
Thanks
Trouble with error handling
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Trouble with error handling
That is because of a number of things. First you are always deleting the key. Second you are never testing the key.
With VBScript ther eis no need to use REG externally. This is much harder to manage. Use ReqRead/RegWrite to check and update the registry.
http://msdn.microsoft.com/en-us/library ... s.84).aspx
With VBScript ther eis no need to use REG externally. This is much harder to manage. Use ReqRead/RegWrite to check and update the registry.
http://msdn.microsoft.com/en-us/library ... s.84).aspx