Page 1 of 1 1
Topic Options
#153456 - 2005-12-15 11:01 AM Best way to check if a registry value exists
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Iīm gonna generate Outlook profiles for users who hasnīt got one. Iīm gonna check for the existance of the DefaultProfile value. Is this a secure way determine if the value exist?
Code:
 $Outlook = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsytem\Profiles", "DefaultProfile")
If not @ERROR = 0
command to generate Outlook Profile
Endif


Top
#153457 - 2005-12-15 01:27 PM Re: Best way to check if a registry value exists
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You are putting the result of the reg key/value check into a variable and the check on @error. Why not check on the variable like this.

Code:

$Outlook = ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsytem\Profiles", "DefaultProfile")
If $outlook = 0
command to generate Outlook Profile
Endif



BTW: HKEY_CURRENT_USER is the same as HKCU. A little code golfing can’t hurt now and then
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#153458 - 2005-12-15 01:54 PM Re: Best way to check if a registry value exists
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Thanx Mart
Didnīt know what a nonexisting value would give as returncode. Nice tip on HKCU.
Regards Lars

Top
#153459 - 2005-12-15 02:19 PM Re: Best way to check if a registry value exists
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Iīve run your suggestion and I didnīt get it to work. However
Code:
 $Outlook = ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsytem\Profiles", "DefaultProfile")
If $outlook =""
command to generate Outlook Profile
Endif

did work. Do you see any problems with this check. The value "DefaultProfile" does only exist on users with Outlook configured. I wanna be careful with this so I donīt mess up hundreds of Citrix users.
Regards Lars

Top
#153460 - 2005-12-15 03:21 PM Re: Best way to check if a registry value exists
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could always do a $outlook <> "1".
This will work when it is 0 and when it's empty.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#153461 - 2005-12-15 05:14 PM Re: Best way to check if a registry value exists
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Incorrect VarType... tsk, tsk, tsk
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153462 - 2005-12-15 06:27 PM Re: Best way to check if a registry value exists
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Is there any reason you can't just check for the outlook key?

Code:

if not KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsytem\Profiles\Outlook")
;Create profile
endif


Top
#153463 - 2005-12-15 07:14 PM Re: Best way to check if a registry value exists
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#153464 - 2005-12-15 08:23 PM Re: Best way to check if a registry value exists
lawe009 Offline
Fresh Scripter

Registered: 2004-04-14
Posts: 36
Reply to maciep
The reason not to check for a key but to check for a value is that the key can have any name as a user can delete and create a profile with any name. Probably all have the same name but to check for a value insted of a key seems safer.


Edited by lawe009 (2005-12-15 08:26 PM)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.124 seconds in which 0.088 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org