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!

Read registry key which may exist ... without error ! 2

Status
Not open for further replies.

gmail2

Programmer
Jun 15, 2005
987
IE
Hi all

I'm writing a script which will be used to check a registry key named version under HKLM\Software\software-name and if the version is below a certain number, copy a file and increment the version number.

However, at the moment, HKLM\Software\software-name\version does not exist so my script keeps giving an error. Obviously it works fine if I put ON ERROR RESUME NEXT at the top of the script, but is there any other way of getting around this ?

Thanks in advance

Irish Poetry - Karen O'Connor
Irish Poetry and Short Stories - Doghouse Books
Garten und Landschaftsbau
 
Use WMI as PHV has suggested or go with what you already know. Use On Error Resume Next in conjunction with checking for the Err.Number or Err.Description. You don't have to put On Error Resume Next at the top of your script. You can put it just before the registry read and then turn it off afterwords with On Error GoTo 0. Don't forget to do an Err.Clear after checking your error.

Many people have an aversion to using On Error Resume Next, I don't understand the hesitation. Used properly it is a valuable tool for troubleshooting and taking corrective actions based on unforeseen circumstances. That is good programming technique. If abused it can of course just mask poor programming. Strive for the former rather than the latter.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top