Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-12
21
Medium Priority
?
555 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:mrochac
  • 9
  • 7
  • 4
  • +1
21 Comments
 
LVL 16

Expert Comment

by:robrandon
ID: 12286505
0
 
LVL 9

Expert Comment

by:CDCOP
ID: 12286654
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
 
LVL 1

Author Comment

by:mrochac
ID: 12286748
Got the installation process working, now i need to kno what their default printer is? name and type.

MCR
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 16

Expert Comment

by:robrandon
ID: 12287277
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
 
LVL 1

Author Comment

by:mrochac
ID: 12287346
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
 
LVL 10

Accepted Solution

by:
Longbow earned 2000 total points
ID: 12287808
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
 
LVL 1

Author Comment

by:mrochac
ID: 12287946
perfect, now how do i make it so it goes to a remote machine and gives me the information?

MCR
0
 
LVL 10

Expert Comment

by:Longbow
ID: 12288223
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
 
LVL 1

Author Comment

by:mrochac
ID: 12290845
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
 
LVL 16

Expert Comment

by:robrandon
ID: 12291302
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
 
LVL 1

Author Comment

by:mrochac
ID: 12291346
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
 
LVL 1

Author Comment

by:mrochac
ID: 12298819
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
 
LVL 16

Expert Comment

by:robrandon
ID: 12299094
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
 
LVL 16

Expert Comment

by:robrandon
ID: 12299600
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
 
LVL 1

Author Comment

by:mrochac
ID: 12300207
funny, cause i have this script and i get the same error as yours, i get no value..!!!

MCR
0
 
LVL 16

Expert Comment

by:robrandon
ID: 12300330
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
 
LVL 1

Author Comment

by:mrochac
ID: 12300523
it doesn't. what happens is it gives me a blank value, as if there was no default printer.

MCR
0
 
LVL 16

Expert Comment

by:robrandon
ID: 12300664
what if you put the computername of the computer that you are using in there?  same results or it gives you output?
0
 
LVL 1

Author Comment

by:mrochac
ID: 12301370
It works fine if i use my own computer.

MCR
0
 
LVL 10

Expert Comment

by:Longbow
ID: 12318553
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
 
LVL 10

Expert Comment

by:Longbow
ID: 12318593
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question