displaying default printer using vbscript
displaying default printer using vbscript
(OP)
Hello,
I am trying ( as much as a beginner can try) to write a script that will display a users default printer among other things. Here is the portion of the script that That I have so far that does indeed echo the default printer, but I would like to learn how to extract the printer name only and not the other superfluous information. This script is going to reside on the end users desk top and will serve as a tool for gathering pc information that will assist the helpdesk before we establish remote control connections.
dim defaultprn
Set WshShell = CreateObject("WScript.Shell")
defaultprn = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
msgbox defaultprn
the out put form this script is "\\printserver\prn4424,winspool,Ne06:"
The actual printer name buried in this string that would be recognizable to an end user is "prn4424" because that is the network name of the printer. I am curious to know how to parse or separate out that part of the line , leave the rest behind and display that value in a popup or text box.
Any help on this would be greatly appreciated.
Fred
I am trying ( as much as a beginner can try) to write a script that will display a users default printer among other things. Here is the portion of the script that That I have so far that does indeed echo the default printer, but I would like to learn how to extract the printer name only and not the other superfluous information. This script is going to reside on the end users desk top and will serve as a tool for gathering pc information that will assist the helpdesk before we establish remote control connections.
dim defaultprn
Set WshShell = CreateObject("WScript.Shell")
defaultprn = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
msgbox defaultprn
the out put form this script is "\\printserver\prn4424,winspool,Ne06:"
The actual printer name buried in this string that would be recognizable to an end user is "prn4424" because that is the network name of the printer. I am curious to know how to parse or separate out that part of the line , leave the rest behind and display that value in a popup or text box.
Any help on this would be greatly appreciated.
Fred
RE: displaying default printer using vbscript
dim defaultprn
Set WshShell = CreateObject("WScript.Shell")
defaultprn = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
arrPrnStr = Split(defaultprn,",")
fullPrinterString = arrPrnStr(0)
arrFullPrnStr = Split(fullPrinterString,"\")
shortPrinterName= arrFullPrnStr(Ubound(arrFullPrnStr))
MsGBox shortPrinterName
I hope you find this post helpful. Please let me know if it was.
Regards,
Mark
RE: displaying default printer using vbscript
That is exactly what I needed!
Any suggestions on what areas of scripting I should bone up on to continue improving in this particular area? I read through my scripting book and found nothing close to the code you have there.
Again, Thanks for the quick and accurate response
RE: displaying default printer using vbscript
I was thinking more on this and you should use this code instead:
dim defaultprn
Set WshShell = CreateObject("WScript.Shell")
defaultprn = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
arrPrnStr = Split(defaultprn,",")
fullPrinterString = arrPrnStr(0)
If Left(fullPrinterString,2) = "\\" Then
arrFullPrnStr = Split(fullPrinterString,"\")
shortPrinterName= arrFullPrnStr(Ubound(arrFullPrnStr))
Else
shortPrinterName = fullPrinterString
End If
MsGBox shortPrinterName
The difference here is that I realized if the default printer was a local printer you would probably get an error since it would not have a UNC path.
As for references, I think the WSH documentation is a great start. Also I suggest you get a copy of the Script Repository from the MS site. microsoft.com/scripting.
Also, take a look within this forum. You will find lots of examples and will get lots of ideas from other people. Review the many postings even if you don't have the same problem. I think you will find the posts from the forum MVPs the most helpfull.
A suggestion too is that when you find something helpfull, give someone a star, even if it wasn't for one of your own questions.
I hope you find this post helpful. Please let me know if it was.
Regards,
Mark
RE: displaying default printer using vbscript
That way you can include things like
ipaddress
machinename
username
C drive space
mapped printers
mapped drives
that way you can include an 'audit' section into the users current logonscript. get this logon script to write the information to a central server in the form of a text file.
that way when the user rings up you wont have to ask them to run files and tell you the results etc, the information will be there already. whats more you can start of actively look at the files to pre-empt problems
regards
rich
RE: displaying default printer using vbscript
Fred