Page 1 of 1 1
Topic Options
#194247 - 2009-06-15 01:14 PM Creating Registry Entries with KIX
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
Hi Guys and Girls

I am looking to add a registry key for all my users. There is a known issue with one of the apps we use and it requires a registry key to be in the users hive.

The key is:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1

Now I have a check for key syntax already for another issue I had which is

$ReturnCode = KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles")

If $ReturnCode = 0

RUN "E:\PROGRA~1\MICROS~1\OFFICE11\OUTLOOK.EXE /importprf E:\PROGRA~1\MICROS~1\custom11.prf"

EndIF

If $ReturnCode = 1
EXIT

But I now need to adapt this to say if the key exists then exit which I assume is the last IF statement but if it doesn't I need it to add it - thats the bit I don't know

Any help would be most appreciated and the response I got from my last post was just superb so I am expecting great things \:\)

Thanks

Top
#194248 - 2009-06-15 01:42 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
A simple ELSE construct should suffice. You can also leverage the return code directly, instead of assigning it to a var and then testing that var.
 Code:
If KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles")
  ; exists - just exit
  Exit 0
Else
  Shell 'E:\PROGRA~1\MICROS~1\OFFICE11\OUTLOOK.EXE /importprf E:\PROGRA~1\MICROS~1\custom11.prf'
  ; can check for status??
EndIf
Couple of points:
Using single quotes in the SHELL and RUN commands allow you to embed the double quotes that command lines prefer.

You can simplify this to
 Code:
If Not KeyExist
("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles")
  Shell 'E:\PROGRA~1\MICROS~1\OFFICE11\OUTLOOK.EXE /importprf E:\PROGRA~1\MICROS~1\custom11.prf'
  ; can check for status?? Exit w/ error code?
EndIf
Exit 0
but this logic form may not be as comfortable as it uses negative logic. Either one will work equally well.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#194252 - 2009-06-15 02:12 PM Re: Creating Registry Entries with KIX [Re: Glenn Barnas]
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
Hi Glen

Thanks for the response - sorry I didn't make myself clear and is my fault. That Outlook key I have working already and was using it as an example to what I want. What I need is something that says

If KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1")
; exists - just exit
Exit 0
Else

*INSERT THIS KEY WITH VALUE OF 1* HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1

EndIf

Is that bit I don't know - how to add that key in via the script if its missing with the value of 1 to be enabled.

Hope you can help!

Top
#194254 - 2009-06-15 02:21 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
That is quite easy.

 Code:
If Not KeyExist("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1")
	$rc = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1", "1", "Data Type")
EndIf



All you need to do is change "Data type" to the data type you need.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194257 - 2009-06-15 03:51 PM Re: Creating Registry Entries with KIX [Re: Mart]
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
Mart - you know far too much - do they pay you enough???

Thanks very much - I will test it out \:\)

Top
#194258 - 2009-06-15 04:14 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: BackForBreakfast
Mart - you know far too much - do they pay you enough???

Thanks very much - I will test it out \:\)


Nope. The never pay me enough. That much money is not available
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194260 - 2009-06-15 04:29 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
Mart

Just tried your script but unfortunately it didn't work. I substituted HKCU for HKEY_CURRENT_USER just in case my version of KIX didn't like it but it made no odds. I am getting this error when it tries to write the $rc line

ERROR: invalid method/function call: missing required parameter 4!

I assume I was meant to put REG_DWORD in the 'Data Type' bit or have I been a bit of a scope in doing so ????

Top
#194261 - 2009-06-15 04:33 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Oh sorry, my bad.

It should be like this:
 Code:
$rc = WriteValue("Registry key", "Registry value", "Data for the value", "Data Type")


HKCU or HKEY_CURRENT_USER should be ok. I’m not sure when the short names were introduced but if you use a recent version it should be ok.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194262 - 2009-06-15 04:44 PM Re: Creating Registry Entries with KIX [Re: Mart]
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
If KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1")
; exists - just exit
Exit 0
Else

If Not KeyExist("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1")
$rc = WriteValue("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyHttp1.1", "1", "Data Type")
EndIf


This is how I have it at the moment - is that right ? - just so you know there is nothing else in this script file apart from what is written above \:\)


Edited by BackForBreakfast (2009-06-15 04:45 PM)

Top
#194263 - 2009-06-15 04:58 PM Re: Creating Registry Entries with KIX [Re: BackForBreakfast]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I think you are missing something.
Have a look at the explanation below.

A cleaner version for your script would be like this:
 Code:
If Not KeyExist("Registry key to check goes here")
	$rc = WriteValue("Registry key", "Registry value", "Data", "Data Type")
Else
	Exit 0
EndIf


What Writevalue wants:
- Registry key: The "folders" in the left pane of regedit.
- Registry value: The entries in the right pane of regedit.
- Data: What should the registry value hold?
- Data type: Type of the registry value.

Data type can be:

REG_NONE
REG_SZ
REG_EXPAND_SZ
REG_BINARY
REG_DWORD
REG_DWORD_LITTLE_ENDIAN
REG_DWORD_BIG_ENDIAN
REG_LINK
REG_MULTI_SZ
REG_RESOURCE_LIST
REG_FULL_RESOURCE_DESCRIPTOR


Edited by Mart (2009-06-15 04:58 PM)
Edit Reason: Typo.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#194265 - 2009-06-15 05:24 PM Re: Creating Registry Entries with KIX [Re: Mart]
BackForBreakfast Offline
Fresh Scripter

Registered: 2009-06-08
Posts: 8
Loc: England
That did it!!!!

Thanks again Mart - sorry my n00bish ways have troubled you!!!

Look forward to the next solution to my woes ;\)

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 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.07 seconds in which 0.032 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