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

x
?
Solved

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

Posted on 2013-05-10
8
Medium Priority
?
817 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 

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

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.

Question has a verified solution.

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

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

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