×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

displaying default printer using vbscript

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

RE: displaying default printer using vbscript

You just need to split your results a few times to get what you are looking for.  This edited script will do the trick:


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

(OP)
Markdmac, Thank you


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

Cartwfh,

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

i would brush up on getting/mamipulating drive and printer connections. retrieving ipaddress, machine name, username, File and Drive objects.

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

(OP)
Gentlemen, Thank you both for taking the time out to read, assist and teach on this subject.

Fred

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close