Solved

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

Posted on 2003-11-11
11
1,241 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
ID: 9726342
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
ID: 9731983
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 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 9733362
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 3

Expert Comment

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

Tim McGue
0
 

Author Comment

by:murryc
ID: 9825891
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
 
LVL 84

Expert Comment

by:oBdA
ID: 9826339
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
ID: 9826488
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 84

Expert Comment

by:oBdA
ID: 9827495
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
ID: 9850742
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 84

Expert Comment

by:oBdA
ID: 9851801
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
ID: 12423973
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need the Best Data Leakage Protection (Cloud Based) 1 360
Images sometimes not printed 6 484
Video card with drivers for Windows 2000 8 149
Can you expand C: in Windows 2000? 5 137
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…
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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