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

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.
murrycAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tim_mcgueCommented:
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
murrycAuthor Commented:
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
oBdACommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

tim_mcgueCommented:
It looks like oBda nailed it.  Give oBda the points (as long as you agree).

Tim McGue
0
murrycAuthor Commented:
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
oBdACommented:
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
murrycAuthor Commented:
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
oBdACommented:
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
murrycAuthor Commented:
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
oBdACommented:
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
ehaleyCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.