Page 1 of 1 1
Topic Options
#158946 - 2006-03-13 04:47 PM AddPrinterConnection problem
Qbakies Offline
Fresh Scripter

Registered: 2006-03-13
Posts: 11
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.

Top
#158947 - 2006-03-13 04:52 PM Re: AddPrinterConnection problem
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
Can you the user manually add a printer? possibly a permissions prob
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#158948 - 2006-03-13 04:55 PM Re: AddPrinterConnection problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158949 - 2006-03-13 05:25 PM Re: AddPrinterConnection problem
Qbakies Offline
Fresh Scripter

Registered: 2006-03-13
Posts: 11
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.

Top
#158950 - 2006-03-13 05:29 PM Re: AddPrinterConnection problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Most likely you don't have the GPO set to run the script visible. Put the error info into a popup GUI window then.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158951 - 2006-03-13 05:35 PM Re: AddPrinterConnection problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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$"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158952 - 2006-03-13 05:40 PM Re: AddPrinterConnection problem
Qbakies Offline
Fresh Scripter

Registered: 2006-03-13
Posts: 11
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?

Top
#158953 - 2006-03-13 05:42 PM Re: AddPrinterConnection problem
Qbakies Offline
Fresh Scripter

Registered: 2006-03-13
Posts: 11
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.

Top
#158954 - 2006-03-13 05:55 PM Re: AddPrinterConnection problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The MessageBox() function will popup a GUI window.

I realize that shares ending in $ are hidden.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#158955 - 2006-03-13 05:57 PM Re: AddPrinterConnection problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good les, now you have learned something new today too
_________________________
!

download KiXnet

Top
#158956 - 2006-03-13 07:00 PM Re: AddPrinterConnection problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158957 - 2006-03-13 07:27 PM Re: AddPrinterConnection problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
run your script manaully in a DOS window to preserve any output text that may be helpful.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158958 - 2006-03-13 07:52 PM Re: AddPrinterConnection problem
Qbakies Offline
Fresh Scripter

Registered: 2006-03-13
Posts: 11
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.

Top
#158959 - 2006-03-13 08:14 PM Re: AddPrinterConnection problem
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.063 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org