![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | WshShell.RegRead I am trying to use WshShell.RegRead to get the driver and port that a printer is connected to. The Key in the registry is HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts The problem is that the value name is "\\my_server\PrinterName" Of course if I use the Key with the valuename as the argument for the RegRead it trys to use HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\\my_server\" as the key and "PrinterName" as the value name and I get an error that the key does not exist. How can I read this registry value? Thanks for any help Fred |
My System Specs![]() |
| | #2 (permalink) |
| | Re: WshShell.RegRead "Fred" <leavemealone@xxxxxx> wrote in message news:ee5nGCppJHA.1248@xxxxxx Quote: >I am trying to use WshShell.RegRead to get the driver and port that a >printer is connected to. > The Key in the registry is HKCU\Software\Microsoft\Windows > NT\CurrentVersion\PrinterPorts > > The problem is that the value name is "\\my_server\PrinterName" > Of course if I use the Key with the valuename as the argument for the > RegRead it trys to use > HKCU\Software\Microsoft\Windows > NT\CurrentVersion\PrinterPorts\\my_server\" as the key and "PrinterName" > as the value name and I get an error that the key does not exist. > > How can I read this registry value? > > Thanks for any help > Fred > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: WshShell.RegRead The VB procedure below tries to set the default printer but the RegRead fails with "no such key". Obviously appending PrterName (which is the registry's value name) to the Key actually changes the key. The Key becomes "Original Key\\\myServer\" and value name becomes PrinterName. How else can I read the registry value data at key: "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices\" and value name: "\\myServer\PrinterName" or is there another way I can set the default printer. Thanks Fred Sub SetDefaultPrinter(PrterName As String) 'PrterName is the printer name in the form \\myServer\PrinterName Dim FPrinter As String, WShell As Object Set WShell = CreateObject("WScript.Shell") FPrinter = WShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices\" & PrterName) If FPrinter <> "" Then WShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\device", FPrinter, REG_SZ End If Set WShell = Nothing End Sub "Pegasus [MVP]" <news@xxxxxx> wrote in message news:e50ZKqtpJHA.5832@xxxxxx Quote: > > "Fred" <leavemealone@xxxxxx> wrote in message > news:ee5nGCppJHA.1248@xxxxxx Quote: >>I am trying to use WshShell.RegRead to get the driver and port that a >>printer is connected to. >> The Key in the registry is HKCU\Software\Microsoft\Windows >> NT\CurrentVersion\PrinterPorts >> >> The problem is that the value name is "\\my_server\PrinterName" >> Of course if I use the Key with the valuename as the argument for the >> RegRead it trys to use >> HKCU\Software\Microsoft\Windows >> NT\CurrentVersion\PrinterPorts\\my_server\" as the key and "PrinterName" >> as the value name and I get an error that the key does not exist. >> >> How can I read this registry value? >> >> Thanks for any help >> Fred >> > Let's have a look at your script! > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: WshShell.RegRead I'm getting a little confused. In your first post you mentioned this registry value: HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts which has now become HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices I also note that your program treats REG_SZ as a variable or as a constant whereas in fact it should be a string, to be surrounded with double quotes. About your main problem of being unable to extract registry data when the value name refers to a remote machine: AFAIK, the RegRead method of the Wscript Shell object is incapable of dealing with such value names. You need to use WMI instead, e.g. like so in VB Script: sPrinter = "\\Server\HPLJ4" Const HKCU = &H80000001 sKey = "Software\Microsoft\Windows NT\CurrentVersion\Devices" Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") iSuccess = oReg.GetStringValue(HKCU, sKey, sPrinter, sData) "Fred" <leavemealone@xxxxxx> wrote in message news:e7zQrI0pJHA.1248@xxxxxx Quote: > The VB procedure below tries to set the default printer but the RegRead > fails with "no such key". Obviously appending PrterName (which is the > registry's value name) to the Key actually changes the key. The Key > becomes "Original Key\\\myServer\" and value name becomes PrinterName. > > How else can I read the registry value data at key: > "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices\" > and value name: > "\\myServer\PrinterName" > > or is there another way I can set the default printer. > > Thanks > Fred > > > Sub SetDefaultPrinter(PrterName As String) > 'PrterName is the printer name in the form \\myServer\PrinterName > Dim FPrinter As String, WShell As Object > > Set WShell = CreateObject("WScript.Shell") > FPrinter = WShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows > NT\CurrentVersion\Devices\" & PrterName) > If FPrinter <> "" Then > WShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows > NT\CurrentVersion\Windows\device", FPrinter, REG_SZ > End If > Set WShell = Nothing > End Sub > > > "Pegasus [MVP]" <news@xxxxxx> wrote in message > news:e50ZKqtpJHA.5832@xxxxxx Quote: >> >> "Fred" <leavemealone@xxxxxx> wrote in message >> news:ee5nGCppJHA.1248@xxxxxx Quote: >>>I am trying to use WshShell.RegRead to get the driver and port that a >>>printer is connected to. >>> The Key in the registry is HKCU\Software\Microsoft\Windows >>> NT\CurrentVersion\PrinterPorts >>> >>> The problem is that the value name is "\\my_server\PrinterName" >>> Of course if I use the Key with the valuename as the argument for the >>> RegRead it trys to use >>> HKCU\Software\Microsoft\Windows >>> NT\CurrentVersion\PrinterPorts\\my_server\" as the key and "PrinterName" >>> as the value name and I get an error that the key does not exist. >>> >>> How can I read this registry value? >>> >>> Thanks for any help >>> Fred >>> >> Let's have a look at your script! >> > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: WshShell.RegRead "Pegasus [MVP]" <news@xxxxxx> wrote in message news:%23iXcmy0pJHA.5332@xxxxxx Quote: > I'm getting a little confused. In your first post you mentioned this > registry value: > HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts > which has now become > HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices > > I also note that your program treats REG_SZ as a variable or as a constant > whereas in fact it should be a string, to be surrounded with double > quotes. > > About your main problem of being unable to extract registry data when the > value name refers to a remote machine: AFAIK, the RegRead method of the > Wscript Shell object is incapable of dealing with such value names. You > need to use WMI instead, e.g. like so in VB Script: > > sPrinter = "\\Server\HPLJ4" > Const HKCU = &H80000001 > sKey = "Software\Microsoft\Windows NT\CurrentVersion\Devices" > Set oReg = > GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") > iSuccess = oReg.GetStringValue(HKCU, sKey, sPrinter, sData) Are you sure you are in the right newsgroup? /Al Quote: > "Fred" <leavemealone@xxxxxx> wrote in message > news:e7zQrI0pJHA.1248@xxxxxx Quote: >> The VB procedure below tries to set the default printer but the RegRead >> fails with "no such key". Obviously appending PrterName (which is the >> registry's value name) to the Key actually changes the key. The Key >> becomes "Original Key\\\myServer\" and value name becomes PrinterName. >> >> How else can I read the registry value data at key: >> "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices\" >> and value name: >> "\\myServer\PrinterName" >> >> or is there another way I can set the default printer. >> >> Thanks >> Fred >> >> >> Sub SetDefaultPrinter(PrterName As String) >> 'PrterName is the printer name in the form \\myServer\PrinterName >> Dim FPrinter As String, WShell As Object >> >> Set WShell = CreateObject("WScript.Shell") >> FPrinter = >> WShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows >> NT\CurrentVersion\Devices\" & PrterName) >> If FPrinter <> "" Then >> WShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows >> NT\CurrentVersion\Windows\device", FPrinter, REG_SZ >> End If >> Set WShell = Nothing >> End Sub >> >> >> "Pegasus [MVP]" <news@xxxxxx> wrote in message >> news:e50ZKqtpJHA.5832@xxxxxx Quote: >>> >>> "Fred" <leavemealone@xxxxxx> wrote in message >>> news:ee5nGCppJHA.1248@xxxxxx >>>>I am trying to use WshShell.RegRead to get the driver and port that a >>>>printer is connected to. >>>> The Key in the registry is HKCU\Software\Microsoft\Windows >>>> NT\CurrentVersion\PrinterPorts >>>> >>>> The problem is that the value name is "\\my_server\PrinterName" >>>> Of course if I use the Key with the valuename as the argument for the >>>> RegRead it trys to use >>>> HKCU\Software\Microsoft\Windows >>>> NT\CurrentVersion\PrinterPorts\\my_server\" as the key and >>>> "PrinterName" as the value name and I get an error that the key does >>>> not exist. >>>> >>>> How can I read this registry value? >>>> >>>> Thanks for any help >>>> Fred >>>> >>> >>> Let's have a look at your script! >>> >> > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: WshShell.RegRead "Al Dunbar" <alandrub@xxxxxx> wrote in message news:O1E%23Yb1pJHA.4108@xxxxxx Quote: > > > Also, your program seems to be written in VB or VBA rather than VBScript. > Are you sure you are in the right newsgroup? |
My System Specs![]() |
| | #7 (permalink) |
| | Re: WshShell.RegRead "Pegasus [MVP]" <news@xxxxxx> wrote in message news:%23wr0mh1pJHA.4840@xxxxxx Quote: > > "Al Dunbar" <alandrub@xxxxxx> wrote in message > news:O1E%23Yb1pJHA.4108@xxxxxx Quote: >> >> >> Also, your program seems to be written in VB or VBA rather than VBScript. >> Are you sure you are in the right newsgroup? > Replying to me or to the OP? /Al |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| WshShell.Exec workaround | VB Script | |||
| some questions about 'username' and 'WSHshell.run' | VB Script | |||
| Using WshShell.Exec and retrieving output | VB Script | |||
| Need to read 64-bit registry from 32-bit RegRead | VB Script | |||
| Supplying a variable to wshshell.Run | VB Script | |||