Solved

PRNMNGR.vbs supplement with output for Logged on user, computername?

Posted on 2013-05-10
8
774 Views
1 Endorsement
Last Modified: 2013-05-17
Hi

I have very basic scripting skills. In DOS.What I need is

- Script to read from a bulk list of computers in a text file

- Query remote machine to determine Logged on user, default printer

- Output to .csv or similar

This query will be against XP OS

The prnmngr.vbs is great to determine the remote default printer, but the output to >> *.text file does not give me the host name

Thanks in advance!
1
Comment
Question by:Electricdog2013
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:Dave
ID: 39157902
There is a listusers.vbs file here:-

http://blogs.msdn.com/b/alejacma/archive/2008/03/04/how-to-get-the-logged-on-user-with-wmi-vbscript.aspx

replace the line which says:-

strComputer = "machineName"   ' use "." for local computer

with this

strcomputer = WScript.Arguments.Item(0)

and delete (or comment out the next two)  and save as "listusers.vbs"

then you can do

"cscript listusers.vbs computername"

to get the logged in users. (even on XP there may be more than one if the user has used "runas" or three are services running with different credentials)

To get all the outputs in a single file create a wrapper batch file, say "listall.bat" that does something like this:-

echo %1 >>output.txt
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.v
s %1 -l >>output.txt
cscript listusers.vbs %1 >>output.txt
0
 

Author Comment

by:Electricdog2013
ID: 39157960
Hi
Thanks - I am a bit confused. Can this parse a bulk list of computernames or do I need to run it seperately against each machine?

%1 - does that = server (computername)

Also, for each of these scripts - where would I insert the credentials? Will being logged on as the admin account and running Cscript suffice?

Would it be:
echo %1 >>output.txt
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.v
s %1 -l - U/ xx - w/xx >>output.txt
cscript listusers.vbs %1 -U xxx -W xxx  >>output.txt
0
 

Author Comment

by:Electricdog2013
ID: 39157968
Also, just looking at the following
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vb
s %1 -g >>output.txt

Is there a way to pipe the output & the computername into the text file to assist me in analysing the data
so what I am after is
Computername (server)
"The default printer is \\xxx"
0
 
LVL 12

Expert Comment

by:Dave
ID: 39158055
Ok ..

Lets take this in stages. First we create a batch file that will when passed a computer name as its argument:-

1. Echo its argument to the "output.txt" file
2. Run the prnmngr.vbs file and echo the output from that to "output.txt"
3. Run the "listusers.vbs" and send its output to "output,txt"

So if we call that "getinfo.bat" then if we do

"getinfo.bat <computername>"

we get the info you want into the file for a single computer. If you want to do this for a list of computers in a file "mydomain.txt" then you can do

for  /m %c in (mydomain.txt) DO getinfo.bat %c

whats in the batch file, well the three commands :-


echo %1 >>output.txt
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs %1 -l >>output.txt
cscript listusers.vbs %1 >>output.txt 

Open in new window

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:Electricdog2013
ID: 39159083
Thanks
The problem seems to be with PRNMNGR - it is unable to detect the default printer of the currently logged on user on a remote machine.
Is it possible to incorporate the listusers.vbs with the default printer for currently logged on user?
0
 
LVL 12

Accepted Solution

by:
Dave earned 500 total points
ID: 39159207
I think to do that it has to run in the context of the currently logged in user and to do that you need to know their user names and passwords....

... Assuming the machines are on a domain it might be simpler to record this every time a user logs in via the logon script. So if you create a share on a server every on can see and write to, say:-

\\server1\defaultprinters

 then add the following lines to the end of the logon script

echo %username% >>\\server\defaultprinters\%computername%.txt
Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs  -d  >>\\server\defaultprinters\%computername%.txt

Open in new window


you will get a file for each computer showing the user name and their default printer each time they logon. Of course you will need to clear this directory from time to time to prevent it growing too big. You could instead name the files %computername%.%username%.txt and simply use the replace ">" output operator then you would get a file for each user on each computer.
0
 

Author Comment

by:Electricdog2013
ID: 39172790
Hi
Thanks for the advice on the scripting component. It occured to me that network printer settings must be stored elsewhere in the registry.
What I now have is a script that finds logged on user, identifies their SID, and extracts the list of networ printers against that SID in the HKEY_USERS\Printers\Connections key.
Takes a bit of time to return the result, but it works a treat
Cheers
0
 
LVL 12

Expert Comment

by:Dave
ID: 39173962
I was going to suggest that but I couldn't find any code to get the SID of the logged on user....
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

22 Experts available now in Live!

Get 1:1 Help Now