Page 1 of 1 1
Topic Options
#196757 - 2009-11-18 10:52 PM Checking for existing registry key, then modifying it
cdavis Offline
Just in Town

Registered: 2009-11-18
Posts: 2
Loc: Texas
Hey guys, just started using Kixtart today and having some n00b troubles.

Basically I want to accomplish this:

IF specific registry folder does NOT exist

END

BUT IF registry folder DOES exist

RUN COMMAND

Here's what I have so far:

 Code:
If Not Exist("HKEY_CURRENT_USER\SOFTWARE\Citrix")
End

If KeyExist("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL")
  ; Delete Key
  DelValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent", "Config URL")
Else
  AddKey("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL")
  WriteValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL","Enabled",
    "http://xxx.xxx.xxx.xxx/Citrix/PNAgent/config.xml", "REG_SZ")
  

If KeyExist("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Application Cache")
   ; Delete Key
   DelValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent", "Application Cache")
Else
   AddKey("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Application Cache")
   WriteValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Application Cache","Enabled",
    "C:\Documents and Settings\%username%\Application Data\Citrix\PNAgent\AppCache", "REG_SZ")

; can check for status??
EndIf


I feel like I'm right there... just can't figure out the logic.

Thanks.


Edited by Glenn Barnas (2009-11-19 01:23 AM)
Edit Reason: code tags, long line

Top
#196761 - 2009-11-19 01:20 AM Re: Checking for existing registry key, then modifying it [Re: cdavis]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Welcome! There's plenty of talent here to give you a good nudge (or shove) in the right direction!

"End" isn't valid - use Exit 0, or wrap the entire process in a positive logic If statement -
 Code:
If KeyExist('HKEY_CURRENT_USER\SOFTWARE\Citrix')
  ; do your thing
EndIf
Exit 0
Your statement was "if exist", which checks for files.. change it as shown so it looks for a reg key.

Your other logic is missing EndIf statements, add those and you should be ok.
 Code:
If KeyExist('HKEY_CURRENT_USER\SOFTWARE\Citrix')
  ; do your thing
  If KeyExist("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL")
    ; Delete Key
    $Rv = DelValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent", "Config URL")
  Else
    AddKey("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL")
    $Rv = WriteValue("HKEY_CURRENT_USER\SOFTWARE\Citrix\Program Neighborhood Agent\Config URL","Enabled",
    "http://xxx.xxx.xxx.xxx/Citrix/PNAgent/config.xml", "REG_SZ")
  EndIf

  ; now do  your other thing... you get the idea!

EndIf
Exit 0

Also - be sure to use the $Rv = xxxx to capture the return values, or your screen will be littered with zeros (and possibly other numbers, which are error codes!) Any variable name is OK, but RC or RV are commonly used here to capture and discard the return values (RV) or return codes (RC) depending on what you call them.

Glenn

PS - wrap your code in [ CODE] code tags [ /code ] (without the spaces) to preserve your formatting.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#196810 - 2009-11-22 05:04 AM Re: Checking for existing registry key, then modifying it [Re: Glenn Barnas]
cdavis Offline
Just in Town

Registered: 2009-11-18
Posts: 2
Loc: Texas
Glenn,

Thank you for your reply! I modified my code the other day and it worked great. I am starting to understand the functions in kixtart more as I go along.

Thanks again

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 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.05 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

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