Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding network printers through a startup script 1

Status
Not open for further replies.

bobolito

IS-IT--Management
Nov 6, 2003
60
US
After searching for a while I was unsuccessful finding a solution to my problem which I am sure many people have had after upgrading to XP.

Previously I was using Windows 2000 Pro in a building with several computer classrooms. In Windows 2000, I used to add printers using the Startup Script in the Group Policy in Active Directory. That used to work fine. Users in my school were able to login to any computer in the building and the Startup Script would automatically connect them to the corresponding network printer for their location. I used the command:

START \\SERVER\PRINTER

This same command works great in the Logon Script, so this is what I am using as a temporary solution. However, it doesn't work in the Startup Script for Windows XP clients. It used to work in Windows 2000 clients, though. However, I don't want to add it to the Logon Script because that will connect users to the wrong printer if they log in from a computer in another room.

Basically, I've concluded that the Startup Script is running just fine in the XP clients, because when the client computer is booting, I can see a small pop box that quickly flashes before the user logs in and it says that it is connecting the printer. However, when the user logs in, the printer does not exist in the Printers window. The same happens no matter which user logs in to the computer, including the Administrator. I am suspecting this has something to do with permissions but I haven't been able to nail it.

Is there any way to connect to a network printer using Startup Scripts in the Group Policy?

I am using a Windows 2000 Server with Windows XP Pro clients and they have to connect to HP Laserjet networked printers.

Thanks so much!
 
Thanks guys, but the NET USE command is incorrect for installing printers this way. I learned that when I figured that the START \\SERVER\PRINTER was the command that works in Windows 2000. However, the problem now is that it doesn't work on XP in the Startup Script of the Group Policy.

I had already found this article in the Microsoft support site and I read this only works with Logon Scripts. However, I am still clueless as to what would be a solution to get printers to install using the Startup Script.

It seems irrational to me that Microsoft provides a clear and easy solution to install printers using only Logon Scripts when it makes more sense to install printers using Startup Scripts instead. Using Logon Scripts to install printers is pretty much useless when you have users bouncing around in different computers all over a school or business.
 
You do not have access to network resources at the time the startup script runs; you do with a logon script.
 
So, is there any way to have a printer installed from Group Policy for all users? It is really not practical to use a logon script for this.
 
Thanks so much...

I ran the following:

rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\%2
start /wait sc \\%1 stop spooler
start /wait sc \\%1 start spooler

and it installs the printer correctly.

Now, I also want to make the printer installed by this command the default since the machines already have another printer driver installed which is currently the default. So I added the /y option to make it the default but that didn't work. It gave me an error message: "Operation could not be completed. Either the printer name was typed incorrectly, or the specified printer has lost its connection to the server."

However, I noticed that running the script again works fine and actually makes the printer the default.

So I decided to remove the /y option and put it on a line on its own. So basically the resulting script was:

rundll32 printui.dll,PrintUIEntry /ga /c\\%1 /n\\%2
rundll32 printui.dll,PrintUIEntry /y /c\\%1 /n\\%2
start /wait sc \\%1 stop spooler
start /wait sc \\%1 start spooler

I still got the same error message. So I removed the line with the /y option from the command altogether and created another script file with just that line with the /y. I then had a batch file call both scripts one after the other. One to install the printer and then the other to make the printer the default. That didn't work either!! The printer installed fine, but when the second script tried to run I got the same error.

So basically, the commands work fine as long as I run them separately and run them manually. In other words, I have to run the commands myself. I cannot have a batch file call both scripts or even have both commands in the same script because the "make default" command gives me an error.

Is there any way to make both of these scripts work without me having them to manually run them individually? or better yet, is there any way to use the /y option some other way so that installing the printer and making it the default is all in one script?
 
Try:

rundll32 printui.dll,PrintUIEntry /ga /c \\%1 /n \\%2
rundll32 printui.dll,PrintUIEntry /in /n /c \\%1 \\%2
rundll32 printui.dll,PrintUIEntry /in /n /c \\%1 \\%2 /y

But note the first line really needs only to be run when the printer is missing from the global catalogue of available printers for that workstation.
 
I screwed that up:

rundll32 printui.dll,PrintUIEntry /ga /c \\%1 /n \\%2
rundll32 printui.dll,PrintUIEntry /in /c \\%1 /n \\%2
rundll32 printui.dll,PrintUIEntry /in /c \\%1 /n \\%2 /y
 
Unfortunately what those lines do is add two instances of the same printer. The first one is the global connection (per machine) to the printer and the second one is the "per user" connection which only shows for the user who created it. Finally, it makes that one the default printer instead of the first one (global). There was no error message, but it is not exactly what I am trying to do. What I need is to make the global printer the default. Any other suggestions?

Thanks...
 
This line:
rundll32 printui.dll,PrintUIEntry /ga /c \\%1 /n \\%2
Adds the printer. This can be done remotely. It only needs to be done once. The printer is now installed on the workstation and available for each user.

The logon script would then determine which printer is to be set as the default. You do not need a /ga type entry if it was made previously, nor do you need a /c parameter if the script is in the local machine logon.

; make network printer connection
;%2 is \\server_name\printer_name
rundll32 printui.dll,PrintUIEntry /in /n\\%2

; set as the default printer
rundll32 printui.dll,PrintUIEntry /in /n\\%2 /y




 
Once again, thanks...
I am making progress, but I'm not there yet. I figured that in order to make the global printer the default, the line to make the network printer connection is not needed. This was just creating a second instance of the same printer. I only put this line in the logon script:

rundll32 printui.dll,PrintUIEntry /in /n\\%2 /y

The line with the /ga option I am running remotely.

So far this seems to accomplish part of the job. However, it introduces a new problem: Whenever the users login to a different machine in a different room (or another user comes in the same room), the logon script won't set their default printer appropriately because in a different room, we use a different printer. That's why I wanted to stay away from using the logon script, because I need to setup the printers on a "per machine" basis, not per user as users can login to any machine and use different printers depending on where they are.

Normally, when users move to another room, they want to use the printer in the room where they are in. I am surprised Microsoft didn't think of this very common scenario and didn't design Group Policy to add printers so that it works this way. But then again, Microsoft barely thinks of anything. ;) This is why I can't get anything to work in the Startup Script which would be ideal. But the Startup Script is practically useless since it doesn't run any network related commands.

I am thinking of eliminating all printers installed in the clients and just install the default one. This way, as soon as it is added it will automatically make it the default for all users and I won't need a script setting up the default printer.

I tried to run the line to set the default printer remotely, as a way to set the default printer for all users, but that doesn't seem to work.

rundll32 printui.dll,PrintUIEntry /in /c\\%1 /n\\%2 /y

where %1 is the computer name and %2 the network path to the printer.

I get the error message "Operation could not be completed." I am guessing that this doesn't support the /c and can only be run locally?
 
After brainstorming a bit more, I believe I found the ultimate solution which seems to be effectively working just right!!

I created a script AddPrinter.cmd and put it on a shared folder in the server. This one has the following two lines:

rundll32 printui.dll,PrintUIEntry /in /n\\%1
rundll32 printui.dll,PrintUIEntry /in /n\\%1 /y

%1 is the path to the printer.

I then created a registry file (AddPrinter.reg) which adds the following string to the registry:

"\\ServerName\SharedFolder\AddPrinter.cmd" ServerName\Printer

where ServerName\Printer is the argument passed to the .cmd file.

The .reg file is automatically added to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry key which runs for all users. This means that for all users the AddPrinter.cmd script runs, installs and makes the printer the default.

The .reg file is imported into the registry for all machines in the Group Policy Object using a Startup script with the line:

REGEDIT /S "\\servername\SharedFolder\AddPrinter.reg"

Once the registry silently imports that file, the next time any user logs in the network printer I want is installed automatically and also made the default. Since the same script runs regardless of which user logs in, this means that no matter who logs in, they get the appropriate printer.

For other printers, which will use a different path, I just modify the .reg file since it contains the argument being passed to the .cmd file. So all I have to do now is create one .reg file for each printer and run the appropriate one for each room. This will be set in the Startup Scripts for each GPO.

I still have to do more testing to make sure it works properly under all circumstances, but I have confidence that this is the solution I was looking for.

Thanks for all your help. You guided me in the right direction.
 
I tried to run the line to set the default printer remotely, as a way to set the default printer for all users, but that doesn't seem to work.

rundll32 printui.dll,PrintUIEntry /in /c\\%1 /n\\%2 /y
"

It is not a question of it not being able of being run remotely, it is a question that the line has to appear twice, as I wrote above in several threads:

; make network printer connection
;%2 is \\server_name\printer_name
rundll32 printui.dll,PrintUIEntry /in /n\\%2

; set as the default printer
rundll32 printui.dll,PrintUIEntry /in /n\\%2 /y


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top