From the computer of: seamonkey420
(131 recipes)
Created: Aug 18, 2007
This is a pretty basic batch file to get a user's default printer.
The following code will:
1. create a date variable of the current date in YYYYMMDD format
2. create a user variable based on the users logged in
3. find the default printer via the registry for the user
4. output information into a text file
---START CODE---
@echo off
REM Set drive to save device to, be sure to keep format
REM ie D:\ or E:\
REM Also create current user logged in as user variable
SET saveLoc = "C:\"
for /f "tokens=3 delims=\" %%i in ("% USERPROFILE%") do (set user=%%i) 2>&1
REM create date variable
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%
FOR /F "TOKENS=2 DELIMS=Z" %%A IN ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v device') DO echo %user%:%%A > %saveLoc%%date%_%user%_printer.txt
---END CODE---
so lets say i'm logged on and the batch file is set to run upon startup; a file called: 20070818_Seamonkey420_printer.txt would be created on my C:\ drive.
In this file, you would see something like this (i do not have any real printers installed, only my Adobe PDF printer)
Seamonkey420: Adobe PDF,winspool,Ne02:
Finally, once you have all of the text files w/the default printers in a single directory you can then combine the text files into one big one using this comand:
type *printer.txt > allusers.txt
so lets say i have 3 users and their text files:
20070818_John_printer.txt
20070817_Sally_printer.txt
20070819_Bob_printer.txt
my allusers.txt file will look something like this:
Bob: Adobe PDF,winspool,Ne02:
John: Send to Onenote2003,winspool,Ne02:
Sally: Canon i320,winspool,Ne02:
You can in turn import the allusers.txt file into Excel and use ; as a delimiter. Just open up Excel, go to File > Open. Change the Files of Type to All files and open our allusers.txt file.
When it asks for a delimiter, type in a semicolon (;) and click OK.
Voila, easy spreadsheet of users default printer! Easy printer info gathering!
TIPS/NOTES:
-in the inital batch file, you can set the saveLoc variable to a shared network drive/location to make things easier.
-you could possible implement a runas command and add a function to check all users profiles on a machine and then have the runas command run the reg query command for each user
-this same concept and use of the reg query command can be used to get all kinds of info from a pc such as installed apps, netwokr info, etc.
-other useful/related techrx recipes
http://www.tech-recipes.com/batch_file_programming.html
Subscribe to the Tech-Recipes Newsletter
You can get tips like this delivered in your email every week!
We will never, ever sell your email address or spam you.
Related recipes:
Supress Responses From Commands In Batch Files
Supressing Prompts In Batch Files While Deleting All Files
Using variables in Windows batch files
XP batch files: Create variable for current user account and find current user
Windows XP/Vista: Use a Batch File for Quickly Restarting explorer.exe
Create Batch File to Start or End Window Services
XP Batch Files: Copy images from camera to pc and organize by date
XCOPY command : Using the /EXCLUDE flag
Batch File Converting of Video Files: SageTV example
Date Calculation In Batch Files XP/2000
Sponsored links
Login
Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.Search
Tech Recipes
· Home
· Mac OS X
· Solaris
· Windows
· Programming
· UNIX
· Cisco
· MySQL
· Google
· Instant messaging
· Add recipes
· Leave feedback
· Recommend us
· RSS Syndication
Hot recipes
Make XP look like Windows Vista / Longhorn for free!
SMS through E-Mail: Cingular, Nextel, Sprint, T-Mobile, Verizon, Virgin Mobile
XP: Small, Free Way to Use and Mount Images (ISO files) Without Burning Them
Vista: Should I Install 64-bit or 32-bit Version? (x64 vs x86)
How Do I Use or Open Bin, Cue, or ISO Files?
Hacks to Beat Rapidshare Download Limits and Waiting Time
MySpace Hack: View Pictures and Comments on a Private Profile
MySpace: Hack to Download Any Song on MySpace
Who's Online
There are currently, 2854 guest(s) and 1 member(s) that are online.
You are Anonymous user. You can register for free by clicking here
Information
Wish to advertise with us?
All logos and trademarks in this site are property of their respective owner. The comments and forum posts are property of their posters, all the rest © 2003-2007 by QD Ideas, LLC.
Users of this site are legally bound by the Terms and conditions and Disclaimer. Do not use this web site if you do not agree with these policies.
The members, admins, and authors of this website respect your privacy.
Page Generation: 0.81 Seconds
Fri Aug 8 13:53:02 2008