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!
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]" <ne...@microsoft.com> wrote in message
news:e50ZKqtp...@TK2MSFTNGP06.phx.gbl...
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@home> wrote in message
news:e7zQrI0p...@TK2MSFTNGP03.phx.gbl...
Also, your program seems to be written in VB or VBA rather than VBScript.
Are you sure you are in the right newsgroup?
/Al
Replying to me or to the OP?
The OP. Sorry for not stating that more explicitly...
/Al