I've written some scripts for the registry, but I want to know how to get a
return value if a key exsists. It doesn't appear to allow me to return a
number if the key exisits or not.

Example:

This script was taken from the Script Center
(http://www.microsoft.com/technet/community/scriptcenter/registry/scrreg08.m
spx)

Script Start
------------

const HKEY_LOCAL_MACHINE = &H80000002
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

strComputer = "."

Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Test Application"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
WScript.Echo Err.number, Err.Description

For i=0 To UBound(arrValueNames)
StdOut.WriteLine "Value Name: " & arrValueNames(i)
Select Case arrValueTypes(i)
Case REG_SZ
StdOut.WriteLine "Data Type: String"
StdOut.WriteBlankLines(1)
Case REG_EXPAND_SZ
StdOut.WriteLine "Data Type: Expanded String"
StdOut.WriteBlankLines(1)
Case REG_BINARY
StdOut.WriteLine "Data Type: Binary"
StdOut.WriteBlankLines(1)
Case REG_DWORD
StdOut.WriteLine "Data Type: DWORD"
StdOut.WriteBlankLines(1)
Case REG_MULTI_SZ
StdOut.WriteLine "Data Type: Multi String"
StdOut.WriteBlankLines(1)
End Select
Next

Script End
-----------

How can I have this script let me know if the key exisits? It doesn't seem
to return an error until it hits the UBound (of course). Any ideas? I don't
cafre about the values in the key if it does exsist, I just want to know if
it is there or not.


Thanks

Re: Scripting for the registry, and getting return codes... by Paul

Paul
Tue Jun 22 09:39:36 CDT 2004

Thanks Tom.

I agree with your statement, and thanks for the example. However it still
doesn't tell me if that key is in the registry. Because I can't find values
doesn't determine if the key does exsist.

I'll try to incorporate your suggestion into my solution.

Thanks again

-Paul

"Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message
news:E3BE35E9-6102-478A-B8BE-93C79EE5CAE6@microsoft.com...
> I would use the IsArray() function to test the result before the start of
the For loop, something like ...
>
> if isArray(arrValueName) then
> for each ...
> ...
> next
> Else
> wsh.echo "The item:", strKeyPath, "does not exist"
> End if
>
> The Script Center scripts are great illustrative samples, but are not
particularly robust. I don't fault the authors for that. Making a script
robust is often very complicated and if applied to the samples would detract
from their value, I think.
>
> Tom Lavedas
> ===========
>
>
> "Paul E. Surette" wrote:
>
> > I've written some scripts for the registry, but I want to know how to
get a
> > return value if a key exsists. It doesn't appear to allow me to return
a
> > number if the key exisits or not.
> >
> > Example:
> >
> > This script was taken from the Script Center
> >
(http://www.microsoft.com/technet/community/scriptcenter/registry/scrreg08.m
> > spx)
> >
> > Script Start
> > ------------
> >
> > const HKEY_LOCAL_MACHINE = &H80000002
> > const REG_SZ = 1
> > const REG_EXPAND_SZ = 2
> > const REG_BINARY = 3
> > const REG_DWORD = 4
> > const REG_MULTI_SZ = 7
> >
> > strComputer = "."
> >
> > Set StdOut = WScript.StdOut
> > Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> > strComputer & "\root\default:StdRegProv")
> >
> > strKeyPath = "SOFTWARE\Test Application"
> >
> > oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames,
arrValueTypes
> > WScript.Echo Err.number, Err.Description
> >
> > For i=0 To UBound(arrValueNames)
> > StdOut.WriteLine "Value Name: " & arrValueNames(i)
> > Select Case arrValueTypes(i)
> > Case REG_SZ
> > StdOut.WriteLine "Data Type: String"
> > StdOut.WriteBlankLines(1)
> > Case REG_EXPAND_SZ
> > StdOut.WriteLine "Data Type: Expanded String"
> > StdOut.WriteBlankLines(1)
> > Case REG_BINARY
> > StdOut.WriteLine "Data Type: Binary"
> > StdOut.WriteBlankLines(1)
> > Case REG_DWORD
> > StdOut.WriteLine "Data Type: DWORD"
> > StdOut.WriteBlankLines(1)
> > Case REG_MULTI_SZ
> > StdOut.WriteLine "Data Type: Multi String"
> > StdOut.WriteBlankLines(1)
> > End Select
> > Next
> >
> > Script End
> > -----------
> >
> > How can I have this script let me know if the key exisits? It doesn't
seem
> > to return an error until it hits the UBound (of course). Any ideas? I
don't
> > cafre about the values in the key if it does exsist, I just want to know
if
> > it is there or not.
> >
> >
> > Thanks
> >
> >
> >



Re: Scripting for the registry, and getting return codes... by Tim

Tim
Tue Jun 22 10:19:26 CDT 2004

You could try enumerating subkeys from the parent, looking for the Key in
question:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE"strSrchKey = "Test Application"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
StdOut.WriteLine subkey
Next
"Paul E. Surette" <Paul.Surette@lcbo.com_removethis> wrote in message
news:e0qE$aGWEHA.3380@TK2MSFTNGP11.phx.gbl...
> Thanks Tom.
>
> I agree with your statement, and thanks for the example. However it still
> doesn't tell me if that key is in the registry. Because I can't find
values
> doesn't determine if the key does exsist.
>
> I'll try to incorporate your suggestion into my solution.
>
> Thanks again
>
> -Paul
>
> "Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message
> news:E3BE35E9-6102-478A-B8BE-93C79EE5CAE6@microsoft.com...
> > I would use the IsArray() function to test the result before the start
of
> the For loop, something like ...
> >
> > if isArray(arrValueName) then
> > for each ...
> > ...
> > next
> > Else
> > wsh.echo "The item:", strKeyPath, "does not exist"
> > End if
> >
> > The Script Center scripts are great illustrative samples, but are not
> particularly robust. I don't fault the authors for that. Making a script
> robust is often very complicated and if applied to the samples would
detract
> from their value, I think.
> >
> > Tom Lavedas
> > ===========
> >
> >
> > "Paul E. Surette" wrote:
> >
> > > I've written some scripts for the registry, but I want to know how to
> get a
> > > return value if a key exsists. It doesn't appear to allow me to
return
> a
> > > number if the key exisits or not.
> > >
> > > Example:
> > >
> > > This script was taken from the Script Center
> > >
>
(http://www.microsoft.com/technet/community/scriptcenter/registry/scrreg08.m
> > > spx)
> > >
> > > Script Start
> > > ------------
> > >
> > > const HKEY_LOCAL_MACHINE = &H80000002
> > > const REG_SZ = 1
> > > const REG_EXPAND_SZ = 2
> > > const REG_BINARY = 3
> > > const REG_DWORD = 4
> > > const REG_MULTI_SZ = 7
> > >
> > > strComputer = "."
> > >
> > > Set StdOut = WScript.StdOut
> > > Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> > > strComputer & "\root\default:StdRegProv")
> > >
> > > strKeyPath = "SOFTWARE\Test Application"
> > >
> > > oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames,
> arrValueTypes
> > > WScript.Echo Err.number, Err.Description
> > >
> > > For i=0 To UBound(arrValueNames)
> > > StdOut.WriteLine "Value Name: " & arrValueNames(i)
> > > Select Case arrValueTypes(i)
> > > Case REG_SZ
> > > StdOut.WriteLine "Data Type: String"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_EXPAND_SZ
> > > StdOut.WriteLine "Data Type: Expanded String"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_BINARY
> > > StdOut.WriteLine "Data Type: Binary"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_DWORD
> > > StdOut.WriteLine "Data Type: DWORD"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_MULTI_SZ
> > > StdOut.WriteLine "Data Type: Multi String"
> > > StdOut.WriteBlankLines(1)
> > > End Select
> > > Next
> > >
> > > Script End
> > > -----------
> > >
> > > How can I have this script let me know if the key exisits? It doesn't
> seem
> > > to return an error until it hits the UBound (of course). Any ideas? I
> don't
> > > cafre about the values in the key if it does exsist, I just want to
know
> if
> > > it is there or not.
> > >
> > >
> > > Thanks
> > >
> > >
> > >
>
>



Re: Scripting for the registry, and getting return codes... by Tim

Tim
Tue Jun 22 10:22:40 CDT 2004

My apologies, premature SEND:

You could try enumerating subkeys from the parent, looking for the Key in
question:

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE"
strSrchKey = "Test Application"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
if subkey = strSrchKey then
StdOut.WriteLine subkey
endif
Next

"Paul E. Surette" <Paul.Surette@lcbo.com_removethis> wrote in message
news:e0qE$aGWEHA.3380@TK2MSFTNGP11.phx.gbl...
> Thanks Tom.
>
> I agree with your statement, and thanks for the example. However it still
> doesn't tell me if that key is in the registry. Because I can't find
values
> doesn't determine if the key does exsist.
>
> I'll try to incorporate your suggestion into my solution.
>
> Thanks again
>
> -Paul
>
> "Tom Lavedas" <tlavedas@hotmail.remove.com> wrote in message
> news:E3BE35E9-6102-478A-B8BE-93C79EE5CAE6@microsoft.com...
> > I would use the IsArray() function to test the result before the start
of
> the For loop, something like ...
> >
> > if isArray(arrValueName) then
> > for each ...
> > ...
> > next
> > Else
> > wsh.echo "The item:", strKeyPath, "does not exist"
> > End if
> >
> > The Script Center scripts are great illustrative samples, but are not
> particularly robust. I don't fault the authors for that. Making a script
> robust is often very complicated and if applied to the samples would
detract
> from their value, I think.
> >
> > Tom Lavedas
> > ===========
> >
> >
> > "Paul E. Surette" wrote:
> >
> > > I've written some scripts for the registry, but I want to know how to
> get a
> > > return value if a key exsists. It doesn't appear to allow me to
return
> a
> > > number if the key exisits or not.
> > >
> > > Example:
> > >
> > > This script was taken from the Script Center
> > >
>
(http://www.microsoft.com/technet/community/scriptcenter/registry/scrreg08.m
> > > spx)
> > >
> > > Script Start
> > > ------------
> > >
> > > const HKEY_LOCAL_MACHINE = &H80000002
> > > const REG_SZ = 1
> > > const REG_EXPAND_SZ = 2
> > > const REG_BINARY = 3
> > > const REG_DWORD = 4
> > > const REG_MULTI_SZ = 7
> > >
> > > strComputer = "."
> > >
> > > Set StdOut = WScript.StdOut
> > > Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> > > strComputer & "\root\default:StdRegProv")
> > >
> > > strKeyPath = "SOFTWARE\Test Application"
> > >
> > > oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames,
> arrValueTypes
> > > WScript.Echo Err.number, Err.Description
> > >
> > > For i=0 To UBound(arrValueNames)
> > > StdOut.WriteLine "Value Name: " & arrValueNames(i)
> > > Select Case arrValueTypes(i)
> > > Case REG_SZ
> > > StdOut.WriteLine "Data Type: String"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_EXPAND_SZ
> > > StdOut.WriteLine "Data Type: Expanded String"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_BINARY
> > > StdOut.WriteLine "Data Type: Binary"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_DWORD
> > > StdOut.WriteLine "Data Type: DWORD"
> > > StdOut.WriteBlankLines(1)
> > > Case REG_MULTI_SZ
> > > StdOut.WriteLine "Data Type: Multi String"
> > > StdOut.WriteBlankLines(1)
> > > End Select
> > > Next
> > >
> > > Script End
> > > -----------
> > >
> > > How can I have this script let me know if the key exisits? It doesn't
> seem
> > > to return an error until it hits the UBound (of course). Any ideas? I
> don't
> > > cafre about the values in the key if it does exsist, I just want to
know
> if
> > > it is there or not.
> > >
> > >
> > > Thanks
> > >
> > >
> > >
>
>



Re: Scripting for the registry, and getting return codes... by Torgeir

Torgeir
Tue Jun 22 11:20:00 CDT 2004

Paul E. Surette wrote:

> I've written some scripts for the registry, but I want to know how to get a
> return value if a key exsists. It doesn't appear to allow me to return a
> number if the key exisits or not.
Hi

To check if a registry key or value exists, you can use the
RegKeyExists and RegValueExists functions in the scripts in
the links below.


With WMI:

http://groups.google.com/groups?selm=4027FB99.5DFF5864%40hydro.com


With the WshShell's RegRead method ("pure" WSH code):

http://groups.google.com/groups?selm=%23t94ENtLEHA.2532%40TK2MSFTNGP10.phx.gbl



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx

Re: Scripting for the registry, and getting return codes... by Paul

Paul
Tue Jun 22 13:10:31 CDT 2004

Excellent this is what I've been looking for!

Thanks!

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:uFFeaUHWEHA.3476@tk2msftngp13.phx.gbl...
> Paul E. Surette wrote:
>
> > I've written some scripts for the registry, but I want to know how to
get a
> > return value if a key exsists. It doesn't appear to allow me to return
a
> > number if the key exisits or not.
> Hi
>
> To check if a registry key or value exists, you can use the
> RegKeyExists and RegValueExists functions in the scripts in
> the links below.
>
>
> With WMI:
>
> http://groups.google.com/groups?selm=4027FB99.5DFF5864%40hydro.com
>
>
> With the WshShell's RegRead method ("pure" WSH code):
>
>
http://groups.google.com/groups?selm=%23t94ENtLEHA.2532%40TK2MSFTNGP10.phx.gbl
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/community/scriptcenter/default.mspx