Solved

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

Posted on 2004-10-12
21
539 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now