![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||