Solved

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

Posted on 2004-10-12
21
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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