Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - enumerate registry subkeys

Reply
 
Old 08-25-2008   #1 (permalink)
knothead


 
 

enumerate registry subkeys

I am trying to enumerate printer subkeys and the output is not it should be.
The goal is to list out the printer name, location, port number and share
name. When I run it the it echo the printer name (subkey) but not the
location, port number and sharename.

any suggestions? thanks.

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

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

strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

strValueNameLocation = "Location"
strValueNamePort = "Port"
strValueNameShareName = "Share Name"

For Each subkey In arrSubKeys
StdOut.WriteLine subkey
oReg.GetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameLocation,strValue
StdOut.WriteLine "Location: " & strValue
oReg.GetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNamePort,strValue
StdOut.WriteLine "Port: " & strValue
oReg.GetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameShareName,strValue
StdOut.WriteLine "ShareName: " & strValue
StdOut.WriteBlankLines(1)
Next

My System SpecsSystem Spec
Old 08-25-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: enumerate registry subkeys

Instead of extracting these details from the registry, you could use the
PrintMaster object:

sComputerName = "" 'Could be "\\NetBIOSName"
Set oMaster = CreateObject("PrintMaster.PrintMaster.1")

For Each oPrinter In oMaster.Printers(sComputerName)
WScript.Echo "Location =" & oPrinter.Location
WScript.Echo "Comment =" & oPrinter.Comment
WScript.echo "Name =" & oPrinter.PrinterName
WScript.Echo "Port =" & oPrinter.PortName
WScript.Echo "Share =" & oPrinter.ShareName
WScript.echo
Next


"knothead" <knothead@xxxxxx> wrote in message
news:16EF5F56-262E-4B38-AC83-3D0E848D7AC8@xxxxxx
Quote:

>I am trying to enumerate printer subkeys and the output is not [what] it
>should be.
> The goal is to list out the printer name, location, port number and share
> name. When I run it the[n] it echo[s] the printer name (subkey) but not
> the
> location, port number and sharename.
>
> any suggestions? thanks.
>
> const HKEY_LOCAL_MACHINE = &H80000002
> strComputer = "."
> Set StdOut = WScript.StdOut
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
> strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers"
> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> strValueNameLocation = "Location"
> strValueNamePort = "Port"
> strValueNameShareName = "Share Name"
>
> For Each subkey In arrSubKeys
> StdOut.WriteLine subkey
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameLocation,strValue
> StdOut.WriteLine "Location: " & strValue
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNamePort,strValue
> StdOut.WriteLine "Port: " & strValue
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameShareName,strValue
> StdOut.WriteLine "ShareName: " & strValue
> StdOut.WriteBlankLines(1)
> Next

My System SpecsSystem Spec
Old 08-25-2008   #3 (permalink)
ekkehard.horner


 
 

Re: enumerate registry subkeys

knothead schrieb:
Quote:

> I am trying to enumerate printer subkeys and the output is not it should be.
> The goal is to list out the printer name, location, port number and share
> name. When I run it the it echo the printer name (subkey) but not the
> location, port number and sharename.
>
> any suggestions? thanks.
>
> const HKEY_LOCAL_MACHINE = &H80000002
> strComputer = "."
> Set StdOut = WScript.StdOut
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
> strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Printers"
> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> strValueNameLocation = "Location"
> strValueNamePort = "Port"
> strValueNameShareName = "Share Name"
>
> For Each subkey In arrSubKeys
> StdOut.WriteLine subkey
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameLocation,strValue
> StdOut.WriteLine "Location: " & strValue
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNamePort,strValue
> StdOut.WriteLine "Port: " & strValue
> oReg.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,subkey,strValueNameShareName,strValue
> StdOut.WriteLine "ShareName: " & strValue
> StdOut.WriteBlankLines(1)
> Next
According to

http://msdn.microsoft.com/en-us/libr...88(VS.85).aspx
http://www.microsoft.com/technet/scr...5/hey1222.mspx

the .GetStringValue method takes four parameters

objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, strValue

and returns 0 (success) or an errorcode. So try:

lRet = oReg.GetStringValue( _
HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strValueNameLocation, strValue _
)
StdOut.WriteLine "Location: " & strValue & " (" & lRet & ")"



My System SpecsSystem Spec
Old 08-26-2008   #4 (permalink)
knothead


 
 

Re: enumerate registry subkeys

this is what cam out of the discussion: thanks for the help
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from
Win32_Printer")
For Each objPrinter in colInstalledPrinters
WScript.echo " "
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Location: " & objPrinter.Location
Wscript.Echo "PortName: " & objPrinter.PortName
WScript.Echo "ShareName: " & objPrinter.ShareName
Next
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to enumerate classes from a DLL .NET General
Missing Subkeys needed to fix DVD Autoplay Vista hardware & devices
Finding and removing values in registry subkeys PowerShell
Cannot delete a registry key (or subkeys) --- ??? Vista General
Info: I need to compare Registry Subkeys between a Model Server and a Server PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46