Solved

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

Posted on 2013-05-10
8
778 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

11 Experts available now in Live!

Get 1:1 Help Now