cdavis
(Just in Town)
2009-11-18 10:52 PM
Checking for existing registry key, then modifying it

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.


Glenn BarnasAdministrator
(KiX Supporter)
2009-11-19 01:20 AM
Re: Checking for existing registry key, then modifying it

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.


cdavis
(Just in Town)
2009-11-22 05:04 AM
Re: Checking for existing registry key, then modifying it

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