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

Need a little help with my IF command

Status
Not open for further replies.

Pyro777

MIS
Jul 14, 2006
47
US
Hello,
I am writing a script to check if an image name/date has been written into the registry. if not, I create the regirtry key and add a value for the Data. Everything is working fine with the exception that even though a key/the data exists, it will still write another key entry in the Image folder.

Here is small piece of the script...

ImageVer=objshell.RegRead ("HKEY_LOCAL_MACHINE\Software\Tools\Image")

If ImageVer = "" Then ' Checks to see if the key exists, if not it creates the key and value

ImageValueName = "Date&Time" & " " &MyDateTime & " " & SystemName
' WScript.Echo(ImageValueName)
Set ImageReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\root\default:StdRegProv")
ImageReg.CreateKey HKEY_LOCAL_MACHINE,Imageverpath
ImageReg.SetStringValue HKEY_LOCAL_MACHINE,Imageverpath,ImageValuename,MyDateTime

ImageVer=objshell.RegRead("HKEY_LOCAL_MACHINE\Software\Tools\Image")
F.WriteLine "Your Current Image Version is: " & ImageValuename

Else
F.WriteLine "Your Current Image Version is: " & ImageValuename
End If


My company wants to have the time/date and workstation number (IE: SystemName) as the key name and the time/date are the registry key data.

When I use the If Imagever = "" command, it thinks there is no key written and writes another key into the registry.

Is there another way to write the If command to check for part of the registry key, if it is found then to continue on to the else command ???

Here is an example of my key name and data for that key...
Registry Key Name:
Date&Time 12-10-08 11:14 WS8870

Registry Key Data:
12-10-08 11:14
 
My guess is that you are trying to compare null to "" and they are not at all equal. Try doing a

WScript.Echo VarType(ImageVer)

when you know that the registry value will be missing to see if it is null.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top