Qbakies
(Fresh Scripter)
2006-03-13 04:47 PM
AddPrinterConnection problem

I'm writing a simple login script to get drives and printers mapped at login based on groups. The drives are mapping correcty but the printers don't install. The following is the portion of code for the printers:
Code:
 ;Map Personal and Public shares
$L= "\\ares\" + @USERID
$X= \\ares\hsfdrv + "$"
$N= \\ares\daytonpub
Use L: $L
Use X: $X
Use N: $N

;Group shares
If InGroup("Legal")
$M= \\ares\secure + "$"
Use M: $M
AddPrinterConnection("\\janus\Execs_4100")
AddPrinterConnection("\\janus\Execs_Color")
AddPrinterConnection("\\janus\Execs_Lanier")
SetDefaultPrinter("\\janus\Execs_4100")
EndIf

If InGroup("Call Center")
$M=\\ares\callcenter + "$"
Use M: $M
AddPrinterConnection("\\janus\Call Center 1")
AddPrinterConnection("\\janus\Call Center 2")
AddPrinterConnection("\\janus\Call Center 3")
AddPrinterConnection("\\janus\CC_Lanier")
EndIf

If InGroup("CC Mgmt")
$M=\\ares\callcenter + "$"
$O=\\ares\ccmgmt + "$"
$P=\\chaos2\training + "$"
Use M: $M
Use O: $O
Use P: $P

If @USERID="CForester"
AddPrinterConnection("\\janus\Ops")
AddPrinterConnection("\\janus\Ops_Lanier")
AddPrinterConnection("\\janus\Train_Color")
SetDefaultPrinter("\\janus\Ops")
EndIF
EndIf

If InGroup("Sales")
$M=\\ares\sales + "$"
Use M: $M
AddPrinterConnection("\\janus\Sales")
AddPrinterConnection("\\janus\Train_Color")
AddPrinterConnection("\\janus\Execs_Lanier")
SetDefaultPrinter("\\janus\Sales")
EndIf



'janus' is the name of my print server. The printer names are the same as the share names. Any help would be appreciated.


AzzerShaw
(Seasoned Scripter)
2006-03-13 04:52 PM
Re: AddPrinterConnection problem

Can you the user manually add a printer? possibly a permissions prob

Howard Bullock
(KiX Supporter)
2006-03-13 04:55 PM
Re: AddPrinterConnection problem

When Windows NT connects to the printer, it may copy printer driver files to the local computer. If the user does not have permission to copy files to the appropriate location, ADDPRINTERCONNECTION fails, and @ERROR returns ERROR_ACCESS_DENIED

check @error, @serror after you call AddPrinterConnection. what is @serror returning?


Qbakies
(Fresh Scripter)
2006-03-13 05:25 PM
Re: AddPrinterConnection problem

Yes, the user can manually install the network printer through the "Add Printer" wizard.

I'm not sure I'm doing the error check correctly. I don't even get a console screen that pops up when the script runs. This is what I added:
Code:

If InGroup("Call Center")
$M=\\ares\callcenter + "$"
Use M: $M
AddPrinterConnection("\\janus\Call Center 1")
? "Error" + @ERROR + "Win32 Error" + @SERROR
AddPrinterConnection("\\janus\Call Center 2")
? "Error" + @ERROR + "Win32 Error" + @SERROR
AddPrinterConnection("\\janus\Call Center 3")
? "Error" + @ERROR + "Win32 Error" + @SERROR
AddPrinterConnection("\\janus\CC_Lanier")
? "Error" + @ERROR + "Win32 Error" + @SERROR
EndIf


My test user is in the "Call Center" group and the netwrk drives map correctly.


Les
(KiX Master)
2006-03-13 05:29 PM
Re: AddPrinterConnection problem

Most likely you don't have the GPO set to run the script visible. Put the error info into a popup GUI window then.

Les
(KiX Master)
2006-03-13 05:35 PM
Re: AddPrinterConnection problem

BTW, why do you do this odd concatenation?
$M=\\ares\callcenter + "$"

Strings should always be in quotes.
$M="\\ares\callcenter$"

Why not just use the string inline?
USE M: "\\ares\callcenter$"


Qbakies
(Fresh Scripter)
2006-03-13 05:40 PM
Re: AddPrinterConnection problem

I did set the GPO option for 'Run logon scripts visible' to 'Enabled' so it puzzles me as to why I can't see the console window.

How do you use a popup window?


Qbakies
(Fresh Scripter)
2006-03-13 05:42 PM
Re: AddPrinterConnection problem

Quote:

BTW, why do you do this odd concatenation?
$M=\\ares\callcenter + "$"

Strings should always be in quotes.
$M="\\ares\callcenter$"

Why not just use the string inline?
USE M: "\\ares\callcenter$"




The share I'm mapping to is a hidden share so I thought I would need to enclose the $ in quotes in order to display it in the path.


Les
(KiX Master)
2006-03-13 05:55 PM
Re: AddPrinterConnection problem

The MessageBox() function will popup a GUI window.

I realize that shares ending in $ are hidden.


LonkeroAdministrator
(KiX Master Guru)
2006-03-13 05:57 PM
Re: AddPrinterConnection problem

good les, now you have learned something new today too

Howard Bullock
(KiX Supporter)
2006-03-13 07:00 PM
Re: AddPrinterConnection problem

Comment on strings (clarifying Les' comment):

$M=\\ares\callcenter + "$"

The text "\\ares\callcenter" is a string and should be enclosed in quotes. You code does not have quotes.


Howard Bullock
(KiX Supporter)
2006-03-13 07:27 PM
Re: AddPrinterConnection problem

run your script manaully in a DOS window to preserve any output text that may be helpful.

Qbakies
(Fresh Scripter)
2006-03-13 07:52 PM
Re: AddPrinterConnection problem

Thanks for the advice about the strings. I took over this network and have been making adjustments to a script written in KiXtart about 5 years ago and have been using that as an example for my code. I'm migrating to a single domain/multiple site AD 2003 network and need to do quite a bit of house cleaning which is one of the reasons I'm rewriting the login script. I cleaned it up (but leaving in the error checks)...

Code:
;Script Options
SETOPTION("ASCII", "ON")
BREAK ON
$= SetConsole("Alwaysontop")
Color w+/B

;Delete shares
Use L: /delete /persistent
Use M: /delete /persistent
Use N: /delete /persistent
Use O: /delete /persistent
Use P: /delete /persistent
Use X: /delete /persistent

;Map Personal and Public shares
Use L: "\\ares\" + @USERID
Use X: "\\ares\hsfdrv$"
Use N: "\\ares\daytonpub"

;Group shares
If InGroup("Legal")
Use M: "\\ares\secure$"
AddPrinterConnection("\\janus\Execs_4100")
AddPrinterConnection("\\janus\Execs_Color")
AddPrinterConnection("\\janus\Execs_Lanier")
SetDefaultPrinter("\\janus\Execs_4100")
? "Error" + @ERROR + "Win32 error" + @SERROR
EndIf

If InGroup("Call Center")
Use M: "\\ares\callcenter$"
AddPrinterConnection("\\janus\Call Center 1")
AddPrinterConnection("\\janus\Call Center 2")
AddPrinterConnection("\\janus\Call Center 3")
AddPrinterConnection("\\janus\CC_Lanier")
? "Error" + @ERROR + "Win32 error" + @SERROR
EndIf

If InGroup("CC Mgmt")
Use M: "\\ares\callcenter$"
Use O: "\\ares\ccmgmt$"
Use P: "\\chaos2\training$"

If @USERID="CForester"
AddPrinterConnection("\\janus\Ops")
? "Error" + @ERROR + "Win32 error" + @SERROR
AddPrinterConnection("\\janus\Ops_Lanier")
? "Error" + @ERROR + "Win32 error" + @SERROR
AddPrinterConnection("\\janus\Train_Color")
? "Error" + @ERROR + "Win32 error" + @SERROR
SetDefaultPrinter("\\janus\Ops")
EndIF
EndIf

If InGroup("Sales")
Use M: "\\ares\sales$"
AddPrinterConnection("\\janus\Sales")
AddPrinterConnection("\\janus\Train_Color")
AddPrinterConnection("\\janus\Execs_Lanier")
SetDefaultPrinter("\\janus\Sales")
? "Error" + @ERROR + "Win32 error" + @SERROR
EndIf


Exit



...and ran it locally (as a test user in the Call Center group) from a DOS window and this is what I got.

OFF0000
Error0Win32 errorThe operation completed successfully.

The printers did map when I ran it locally.


Howard Bullock
(KiX Supporter)
2006-03-13 08:14 PM
Re: AddPrinterConnection problem

You should be capturing the return code from AddPrinterConnection("\\janus\Call Center 1")


See the manual...

$RC = AddPrinterConnection("\\janus\Call Center 1")

This will keep the extraneous character from being displayed. It will also give you the opportunity to perform and IF...EndIf to evaluate the success or failure of each command. Doing this will give you an idea of what is happening during the logon process.