Hi all,

I have done some scripting but I am no expert. I need to check if a registry
key (not a string value) exists on a client computer. If the key exists it
should add some value to the HKCU runonce hive. If the key does exists it
should do nothing and run the rest in the script.

How do I do that?

Bye
Mariette Knap
www.smallbizserver.net

Re: Check if registry registry key exists and then add values to runonce by Steven

Steven
Wed Aug 17 09:53:29 CDT 2005

Const HKEY_CURRENT_USER = &H80000001
Dim strComputer, strKeyPath, strValueName
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer &
"\root\default:StdRegProv")
strKeyPath = "[Path you want to check]"
strValueName = "[Value you want to check for]"
objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If NOT IsNull(dwValue) Then
'// The key exists, write to it
Dim objWSH
Set objWSH = WScript.CreateObject("WScript.Shell")
'// Requires: [Name, value, REG_type]
objWSH.RegWrite
"HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce\", "[Value]"
,"[REG_TYPE]"
Set objWSH = Nothing
End If
Set objRegistry = Nothing
'// Rest of your script here

Hope this helps :o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Mariette Knap [SBS MVP]" <mariette@smallbizserver.local> wrote in message
news:uMfLgLzoFHA.3912@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I have done some scripting but I am no expert. I need to check if a
registry
> key (not a string value) exists on a client computer. If the key exists it
> should add some value to the HKCU runonce hive. If the key does exists it
> should do nothing and run the rest in the script.
>
> How do I do that?
>
> Bye
> Mariette Knap
> www.smallbizserver.net
>
>



Re: Check if registry registry key exists and then add values to runonce by Mariette

Mariette
Wed Aug 17 10:33:14 CDT 2005

In news:%23sME2tzoFHA.3256@tk2msftngp13.phx.gbl,
Steven Burn <somewhere@in-time.invalid> wrote:

> Const HKEY_CURRENT_USER = &H80000001
> Dim strComputer, strKeyPath, strValueName
> strComputer = "."
> Set objRegistry = GetObject("winmgmts:\\" & strComputer &
> "\root\default:StdRegProv")
> strKeyPath = "[Path you want to check]"
> strValueName = "[Value you want to check for]"
> objRegistry.GetDWORDValue
> HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
>
> If NOT IsNull(dwValue) Then
> '// The key exists, write to it
> Dim objWSH
> Set objWSH = WScript.CreateObject("WScript.Shell")
> '// Requires: [Name, value, REG_type]
> objWSH.RegWrite
> "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce\", "[Value]"
> ,"[REG_TYPE]"
> Set objWSH = Nothing
> End If
> Set objRegistry = Nothing
> '// Rest of your script here
>
> Hope this helps :o)

This is the problem I saw too. I do not have any Values to check. I only
need to know if a Key does exist.



Re: Check if registry registry key exists and then add values to runonce by Steven

Steven
Wed Aug 17 10:48:29 CDT 2005

Just set strValueName = ""

... just tried it here and it worked fine :o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Mariette Knap [SBS MVP]" <mariette@smallbizserver.local> wrote in message
news:uY6Z#D0oFHA.576@TK2MSFTNGP15.phx.gbl...
> In news:%23sME2tzoFHA.3256@tk2msftngp13.phx.gbl,
> Steven Burn <somewhere@in-time.invalid> wrote:
>
> > Const HKEY_CURRENT_USER = &H80000001
> > Dim strComputer, strKeyPath, strValueName
> > strComputer = "."
> > Set objRegistry = GetObject("winmgmts:\\" & strComputer &
> > "\root\default:StdRegProv")
> > strKeyPath = "[Path you want to check]"
> > strValueName = "[Value you want to check for]"
> > objRegistry.GetDWORDValue
> > HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
> >
> > If NOT IsNull(dwValue) Then
> > '// The key exists, write to it
> > Dim objWSH
> > Set objWSH = WScript.CreateObject("WScript.Shell")
> > '// Requires: [Name, value, REG_type]
> > objWSH.RegWrite
> > "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce\", "[Value]"
> > ,"[REG_TYPE]"
> > Set objWSH = Nothing
> > End If
> > Set objRegistry = Nothing
> > '// Rest of your script here
> >
> > Hope this helps :o)
>
> This is the problem I saw too. I do not have any Values to check. I only
> need to know if a Key does exist.
>
>



Re: Check if registry registry key exists and then add values to runonce by Mariette

Mariette
Wed Aug 17 11:04:23 CDT 2005

In news:OkWQlM0oFHA.3408@tk2msftngp13.phx.gbl,
Steven Burn <somewhere@in-time.invalid> wrote:

> Just set strValueName = ""
>
> ... just tried it here and it worked fine :o)

But then it should write the runonce hive when the key does NOT exist :-)
How do you fix that? And it should also add a key to the runonce hive. I did
this as follows:

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

strEntryName = "1"
strValue = "outlook.exe /importprf \\srvfile01\netlogon\outlook.prf"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue

How would you do that?



Re: Check if registry registry key exists and then add values to runonce by Steven

Steven
Wed Aug 17 11:47:55 CDT 2005

Nevermind, had a brain fart.......... here you go.....

'// regKeyExists
Dim objWSH, blnKey
Set objWSH = WScript.CreateObject("WScript.Shell")
On Error Resume Next
blnKey =
objWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001
\")
If Err.Number <> 0 Then '// Key exists
'// Code to create the key
On Error Resume Next
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", 1, "REG_SZ"
'// Code to add the value
On Error Resume Next
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\",
"outlook.exe /importprf \\srvfile01\netlogon\outlook.prf", "REG_SZ"
End If
Set objWSH = Nothing
WScript.Echo "Key added"

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Mariette Knap [SBS MVP]" <mariette@smallbizserver.local> wrote in message
news:O0D#WV0oFHA.2180@TK2MSFTNGP15.phx.gbl...
> In news:OkWQlM0oFHA.3408@tk2msftngp13.phx.gbl,
> Steven Burn <somewhere@in-time.invalid> wrote:
>
> > Just set strValueName = ""
> >
> > ... just tried it here and it worked fine :o)
>
> But then it should write the runonce hive when the key does NOT exist :-)
> How do you fix that? And it should also add a key to the runonce hive. I
did
> this as follows:
>
> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001"
> objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
>
> strEntryName = "1"
> strValue = "outlook.exe /importprf \\srvfile01\netlogon\outlook.prf"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
>
> How would you do that?
>
>



Re: Check if registry registry key exists and then add values to runonce by Mariette

Mariette
Wed Aug 17 12:36:34 CDT 2005

In news:u9hnyt0oFHA.3256@TK2MSFTNGP12.phx.gbl,
Steven Burn <somewhere@in-time.invalid> wrote:

> Nevermind, had a brain fart.......... here you go.....
>
> '// regKeyExists
> Dim objWSH, blnKey
> Set objWSH = WScript.CreateObject("WScript.Shell")
> On Error Resume Next
> blnKey =
> objWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001
> \")
> If Err.Number <> 0 Then '// Key exists
> '// Code to create the key
> On Error Resume Next
> objWSH.RegWrite
> "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", 1,
> "REG_SZ" '// Code to add the value
> On Error Resume Next
> objWSH.RegWrite
> "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\",
> "outlook.exe /importprf \\srvfile01\netlogon\outlook.prf", "REG_SZ"
> End If
> Set objWSH = Nothing
> WScript.Echo "Key added"

Thanks Steven. If I use a batch file like:

cmdow @ /HID
@echo off

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Installing Applications" /f

REG ADD %KEY%\001 /VE /D "Configuring Outlook..." /f
REG ADD %KEY%\001 /V 1 /D "outlook.exe /importprf C:\outlook.prf"

I get the correct result. With the above script the registry keys for the
runonce entries are not correct. Can you have a look at that please?

Bye
Mariette



Re: Check if registry registry key exists and then add values to runonce by Mariette

Mariette
Wed Aug 17 12:41:48 CDT 2005

I exported the correct values of the runonce entry:

Key Name:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx
Class Name: <NO CLASS>
Last Write Time: 8/17/2005 - 7:37 PM
Value 0
Name: <NO NAME>
Type: REG_DWORD
Data: 0x0

Value 1
Name: TITLE
Type: REG_SZ
Data: Installing Applications


Key Name:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001
Class Name: <NO CLASS>
Last Write Time: 8/17/2005 - 7:37 PM
Value 0
Name: <NO NAME>
Type: REG_SZ
Data: Importing Registry Tweaks

Value 1
Name: 1
Type: REG_SZ
Data: outlook.exe /importprf C:\outlook.prf





Re: Check if registry registry key exists and then add values to runonce by Mariette

Mariette
Wed Aug 17 13:00:30 CDT 2005

Got it but something is still wrong:

'// regKeyExists
Dim objWSH, blnKey
Set objWSH = WScript.CreateObject("WScript.Shell")
On Error Resume Next
blnKey = objWSH.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office")
If Err.Number <> 0 Then '// Key exists
'// Code to create the key
On Error Resume Next
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", 1, "REG_SZ"
'// Code to add the value
On Error Resume Next
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Title",
"Installing Applications", "REG_SZ"
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", "Installing
Outlook", "REG_SZ"
objWSH.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\1",
"outlook.exe /importprf C:\outlook.prf", "REG_SZ"
End If
Set objWSH = Nothing
WScript.Echo "Key added"

Even with HKEY_CURRENT_USER\Software\Microsoft\Office available it adds the
runonce entries??????



Re: Check if registry registry key exists and then add values to r by tony

tony
Wed Aug 17 16:07:12 CDT 2005

hi i have been looking for a simiaalr scipt all day i wonder if you could
help me
i need to be able to check to see if the automatically detect settings in
internet exploreris on or off then give the users the option to change on or
off this is because i cannot access certain sites from our intranet unless
its on the to access the internal ones i have to turn it back off
thanks in advance tony

"Mariette Knap [SBS MVP]" wrote:

> In news:OkWQlM0oFHA.3408@tk2msftngp13.phx.gbl,
> Steven Burn <somewhere@in-time.invalid> wrote:
>
> > Just set strValueName = ""
> >
> > ... just tried it here and it worked fine :o)
>
> But then it should write the runonce hive when the key does NOT exist :-)
> How do you fix that? And it should also add a key to the runonce hive. I did
> this as follows:
>
> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001"
> objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
>
> strEntryName = "1"
> strValue = "outlook.exe /importprf \\srvfile01\netlogon\outlook.prf"
> objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
>
> How would you do that?
>
>
>