How to find out a users default printer remotely....

can someone help me out on how i can find out what a users default printer is? I need to find this out so it can be used on a script to re-install the same printer bu point it to lpt3. its a windows 2000 enviroment, with windows nt4 print server and no ad.

MCR.
LVL 1
mrochacAsked:
Who is Participating?
 
LongbowConnect With a Mentor Commented:
Set WshShell = WScript.CreateObject("WScript.Shell")
bkey =  WshShell.RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
msgbox (bkey)

Put the above in a .vbs file.
0
 
robrandonCommented:
0
 
CDCOPCommented:
My thoughts excatly robrandon,
http://www.experts-exchange.com/Operating_Systems/Win2000/Q_21137747.html
You can read from registry and then determine what you would like to do.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
mrochacAuthor Commented:
Got the installation process working, now i need to kno what their default printer is? name and type.

MCR
0
 
robrandonCommented:
You can browse that that registry path manually by connecting to the remote registry.  Or are you looking for a vbscript type of thing?  I don't know of an app that would do it.

0
 
mrochacAuthor Commented:
a vbscript kind of thing would be exacly what i am looking for. i got this...

strComputer = "houkes"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "Location: " & objPrinter.Location
Next

but here with this script it does let me input the computer name manually, i have to edit the script put the name in and execute the script, also it doesn't find me just the default printer, it gives me al the printers installed. So if i can have this ask me the computer name and bring back the default printer then i am laughing..

MCR
0
 
mrochacAuthor Commented:
perfect, now how do i make it so it goes to a remote machine and gives me the information?

MCR
0
 
LongbowCommented:
Download the Pstools Suite from http://www.sysinternals.com
Execute the syntax :
psexec \\Computername -u Administrator - p Password "cscript" c:\path\DefPRN.vbs - i

And change "msgbox" to "wscript.echo" in the .vbs file

psexec /? for more information
0
 
mrochacAuthor Commented:
Help....
why this gives me a run time error?

Dim Input
Input = InputBox("Enter computername")
strComputer = input
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Printer Where Default = true")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "Location: " & objPrinter.Location
Next

MCR
0
 
robrandonCommented:
I think it is failing if it is trying to get the info off a remote computer.  If I put in my local computer name it works.  If you do:
cscript filename.vbs

and do a remote computer, the Name and Location fields don't work because they are blank.
0
 
mrochacAuthor Commented:
if you remove the " where default=true" from the seveth line, it will work. For some reason the bolean expression is causing it not to work. or maybe the bolean expression is incorrect. But i know it works if i remove that.

MCR
0
 
mrochacAuthor Commented:
OK, this is gone up to 2000 points, i finally figured out that a reg key must be read remotely for this to work. I will post 3 other questions for the extra points.


MCR
0
 
robrandonCommented:
I found your code on a MS page with the following interesting text:

Use the Win32_Printer class, and check whether the Default property is True.
==>Windows 2000, Windows NT, Windows 98, and Windows 95:  The Default property is not available.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Default = True")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo objPrinter.Name
Next

Still looking for a solution for you.
0
 
robrandonCommented:
getting closer:

     strComputer = "prod-1"
     Const HKEY_CURRENT_USER = &H80000001
     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
     strKeyPath = "SOFTWARE\Microsoft\Windows nt\CurrentVersion\Windows"
     strValueName = "Device"
     oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
     Wscript.echo "Device Key Value: " & strvalue

only problem is that if there is more than one profile on the computer, it is not necessarily grabbing the currently logged on user - which I understand is a problem.  I don't know how to get around it.  Maybe somebody else does.

0
 
mrochacAuthor Commented:
funny, cause i have this script and i get the same error as yours, i get no value..!!!

MCR
0
 
robrandonCommented:
In the most recent script, you need to replace prod-1 with the computername you want to connect to.  We can have it prompt you, but for now I'd like to see if it works at all.
0
 
mrochacAuthor Commented:
it doesn't. what happens is it gives me a blank value, as if there was no default printer.

MCR
0
 
robrandonCommented:
what if you put the computername of the computer that you are using in there?  same results or it gives you output?
0
 
mrochacAuthor Commented:
It works fine if i use my own computer.

MCR
0
 
LongbowCommented:
Win2K Detect Default Printer? :

'Put this in a .vbs file
'I can't test it. I am actually under NT4 Workstation.

Set oWMIsvc    = GetObject("winmgmts:\\.\root\cimv2")
Set colPrinters = oWMIsvc.ExecQuery("Select * from Win32_Printer",,48)
      For Each oThing in colPrinters

             If oThing.Default Then sDefPrinter = oThing.ShareName

      Next
msgbox sDefPrinter

' for Windows 2000 replace the above line : If oThing.Attributes And 2^(3-1) Then sDefPrinter = oThing.ShareName
'http://groups.google.com/groups?th=ae8f3db6aba125e7
0
 
LongbowCommented:
Even change the first script line by this one and change it with your computername :

Set oWMISvc = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.