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
Solved

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

Posted on 2013-05-10
8
785 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
User laptop information 6 143
How do I set up sharing between Macbook Pro and Dell Win XP laptops? 18 169
outlook PST max size limit 3 126
different catridges 8 100
We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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…

828 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