Solved

Need to keep local printer default after running con2prt batch file to install network printers.

Posted on 2003-11-11
11
1,221 Views
Last Modified: 2008-08-15
I am running a bacth file with con2prt that installs several network printers to the local user when they logon.  The batch deletes current printers and reinstalls the list each time the user logs on.  I have left all of the con2prt commands as /c not having any of them install as default, knowing that the first one in the list gets tagged as default, by default.  The problem is that when a user with a local printer logs on, their local printer gets thrown out as default and the first network printers takes that position as default.  The user always needs to keep their local printer as default, if they have a local printer.  Otherwise, the batch works in setting the first network printer as default which is okay.  How do I keep the local printer default during this process.
0
Comment
Question by:murryc
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:tim_mcgue
Comment Utility
Have you thought about approaching the way you are deleting printers?  You can only delete network printers leaving the local printers (and ports) present with the following command:

RUNDLL32 PRINTUI.DLL,PrintUIEntry /dn <printer name>

To get the list of printers assigned to the user in your logon script enumerate the values (starting with "\\") in the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

Also, you can use the same utility to set a printer as a default.  For instance:

rundll32 printui.dll,PrintUIEntry /y /n "printer"

You would have to search for a local printer on the machine in your script and then set it to default with the last command above.
0
 

Author Comment

by:murryc
Comment Utility
I am having the script delete the installed network printers each time the user logs on so that any changes in printer configurations or if the user deletes a printer or has trouble with the driver, the whole setup will be re setup on each logon.  Also, if a printer goes down, that printer will not show up for the user to use as I will disable it in the script while it is down.  This cuts down on my support calls.  I am a little new at using the rundll32 command.  Can you give me more details on how I can use it to search for the local LPT1 or USB printer installed and set it as the deault once all of the script is finsihed installing the network printers?  Just to make sure you understand my position, the script delates and installs ONLY the network printers, but in this process the default is taken away from the local printer and palced on the first network printer installed even though I do not the con2prt /CD command for any of the network printers.  I just use the /C command to make the connection.
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
You can try the brute-force approach: Save the user's standard printer, map your network printers, restore the standard printer (and if there was no default printer, don't restore ...)
This uses reg.exe from the Support Tools; just put it in the netlogon share.
If you haven't installed the Support Tools yet, don't install them from the CD; go to http://www.microsoft.com/windows2000/downloads/servicepacks/ and get the package matching your service pack level.
As usual: No warranties, use it at your own risk, test it before you apply it in earnest ...

====8<----[logon.cmd]----
@echo off
setlocal
:: *** Save the current standard printer:
for /f "skip=3 tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device') do set StdPrt=%%b
::*** Put your printer mappings here:
con2prt.exe /f


:: *** Restore the standard printer if necessary:
if not "%StdPrt%"=="" reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device /d "%StdPrt%" /f >NUL
====8<----[logon.cmd]----
0
 
LVL 3

Expert Comment

by:tim_mcgue
Comment Utility
It looks like oBda nailed it.  Give oBda the points (as long as you agree).

Tim McGue
0
 

Author Comment

by:murryc
Comment Utility
oBda....when I run your addition to my script it tells me the registry key cannot be found.  I browsed the registry and found the key, but maybe I am entering it wrong.  Here are a few questions.  Is HKCU the correct way to reference that key and is it able to reference Windows NT or does it need Windows_NT, WindowsNT?  Any other helpful hints for me?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 82

Expert Comment

by:oBdA
Comment Utility
If you use copy and paste to transfer the line into your script, you should be fine.
"HKCU" can (well, "should", to be more precise) be used with reg.exe.
Does it work when you start it from the command line?
0
 

Author Comment

by:murryc
Comment Utility
Excuse my lask of experience.  I tried running reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device at the command prompt and it returns unable to find the registry value
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Now you have me flabbergasted. I just tested exactly your line (copy and paste) on three different machines: reg.exe v2.0 on W2k, reg.exe v1.05 (with a slightly modified command line due to a different argument syntax) and v2.0 on NT4, and reg.exe v2.0 and v3.0 on Windows XP. It worked in all cases.
Which version of reg.exe ("reg /?") are you using, and what is your OS (I'm assuming W2k)?
0
 

Author Comment

by:murryc
Comment Utility
You were correct.  It does run great on an administrator account, but says it is not able to find registry key when I run it on a standard user account.  Is there some way to have the scripts run in administrator mode, kind of like the run-as command on programs, so that it can access the registry to perfrom this task.  The concept is perfect and does exactly what I need it to do except that it only runs on admin accounts.
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
This is a HKEY_CURRENT_USER registry access, so it's not a rights issue. Have you checked if the user you used to run the command has a default printer installed at all?
If so, have you checked with regedit if the specified key exists for this user's registry?
If it's just because the user doesn't have a default printer (in which case it can't be restored anyway), simply add "2^>NUL" to the reg-line to suppress the error output:

====8<----[logon.cmd]----
@echo off
setlocal
:: *** Save the current standard printer:
for /f "skip=3 tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device 2^>NUL') do set StdPrt=%%b
::*** Put your printer mappings here:
con2prt.exe /f


:: *** Restore the standard printer if necessary:
if not "%StdPrt%"=="" reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device /d "%StdPrt%" /f >NUL
====8<----[logon.cmd]----
0
 
LVL 1

Expert Comment

by:ehaley
Comment Utility
Hi oBdA,

 Any chance I can get you to comment on my post:
http://www.experts-exchange.com/Operating_Systems/Win2000/Q_21183412.html

  It's only 250 pts but I would much appreciate your expertise here..

Thanks,
-Mike-
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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