WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printing Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Add a Printer Port

Keywords:   adding a printer port

Question:

I've been digging around in a lot of samples, and can add printers dynamically like a champ. However, I am having a problem in figuring out how to add a printer port to a workstation - does anyone know how to get WinBatch to add a port to a workstation?

The port I want to add is just a local file port, that will print to the file c:\temp\temp.txt using the Generic/Text Only printer driver...any ideas? I am running Windows NT4 Service Pack 5, Winbatch 99k.

We're on NT and nothing in win.ini at all unfortunately. I can see the registry changes that are being made, and can also capture them into a repackage using SMS. However, when I actually run the repackage on a fresh workstation, it makes the registry changes but the printer never actually shows up even after starting/stopping the spooler service. I was just curious if there were any built in functions inside of WinBatch for adding a printer port...I figured I would have better luck with that instead of hacking the registry apart myself =)

Answer:

Here's the code snippet below.

You can then use the standard pAddPrinter() function to add a Generic / Text Only printer to the workstation.

:AddPort
Message("Notice", "Adding Port To Workstation")
ParameterLine = strcat("/c echo ", Password, "| c:\winnt\system32\su.exe ", UserName)
ParameterLIne = strcat(ParameterLine,' "net stop spooler"')
RunShell("c:\winnt\system32\cmd.exe",ParameterLine,"c:\",@HIDDEN,@WAIT)

regkey=RegCreateKey(@REGMACHINE, "Software\Microsoft\Windows NT\CurrentVersion\Ports")
RegSetValue(regkey, "[c:\temp\eform.prn]", "")
RegCloseKey(regkey)

ParameterLine = strcat("/c echo ", Password, "| c:\winnt\system32\su.exe ", UserName)
ParameterLIne = strcat(ParameterLine,' "net start spooler"')
RunShell("c:\winnt\system32\cmd.exe",ParameterLine,"c:\",@HIDDEN,@WAIT)
return

Article ID:   W15673
File Created: 2003:05:13:11:29:26
Last Updated: 2003:05:13:11:29:26