#206040 - 2012-10-19 01:05 PM
Just Starting out With Kix
|
Dariusvw
Fresh Scripter
Registered: 2012-02-11
Posts: 11
Loc: South Africa
|
Greetings
I'm just starting out with Kix scripts, and got some help setting up my 1st one. Nothing Grand. I would just like some idea on how to improve it.
Currently I am doing Printers first then network drives. I have trimmed the code below so not all the printer and drive Groups are shown, but I figure once you see the pattern you don't need all of them.
So any suggestions will be appreciated, bearing in mind i am just starting out 
Thank you
; *******************
$objSysInfo = CreateObject("ADSystemInfo")
"Computer dn: "+$objSysInfo.computername+@CRLF
$OU = +$objSysInfo.computername+@CRLF
Select
case INSTR ($OU , 'CC-ADMIN')
ADDPRINTERCONNECTION ("\\TWCPRT01\AfM")
ADDPRINTERCONNECTION ("\\TWCPRT01\AfC")
Sleep 3
SetDefaultPrinter ("\\TWCPRT01\AfM")
MessageBox ("Connecting you CC-ADMIN printers", "IT Department", 0, 4)
case INSTR ($OU , 'L-BABBAGE')
ADDPRINTERCONNECTION ("\\TWCPRT01\AfM")
ADDPRINTERCONNECTION ("\\TWCPRT01\LibraryM")
ADDPRINTERCONNECTION ("\\TWCPRT01\Libraryc")
ADDPRINTERCONNECTION ("\\TWCPRT01\AfC")
Sleep 3
SetDefaultPrinter ("\\TWCPRT01\AfM")
MessageBox ("Connecting you to the Aficio printer", "IT Department", 0, 4)
CASE 1
MessageBox ("No Printers Connected", "IT Department", 0, 4)
ENDSELECT
; -------
;Mapped Drive
use k: "\\zeus\Intranet$"
use q: "\\zeus\Photos$"
use s: "\\zeus\Sherston$"
use o: "\\zeus\staff-pupil$"
use x: "\\zeus\applications"
use y: "\\zeus\%username%$"
If InGroup ("GROUP-ADMIN")
use j: "\\TWC-3cx\Sync"
use r: "\\zeus\Reports$"
use w: "\\zeus\Staffdata$"
EndIf
;End_of_Script
:End
Exit
|
|
Top
|
|
|
|
#206042 - 2012-10-19 04:35 PM
Re: Just Starting out With Kix
[Re: Dariusvw]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Add a dummy variable in front of all the functions to catch the return code and prevent 1's and 0's from popping up on a console.
Change these...
ADDPRINTERCONNECTION ("\\TWCPRT01\AfM") To this...
$nul = ADDPRINTERCONNECTION ("\\TWCPRT01\AfM")
Same goes for SetDefaultPrinter, and MessageBox
Edited by ShaneEP (2012-10-19 04:36 PM)
|
|
Top
|
|
|
|
#206044 - 2012-10-19 04:44 PM
Re: Just Starting out With Kix
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
You also have some weird characters up top, like the random '+'. And since I'm picky about proper indentation. I would indent it all correctly as well. Are you using GOTO's somewhere else in the script? If not the :END label at the bottom is not needed.
; *******************
$OU = CreateObject("ADSystemInfo").computername
"Computer dn: "+$OU ?
Select
case INSTR($OU, 'CC-ADMIN')
$nul = AddPrinterConnection("\\TWCPRT01\AfM")
$nul = AddPrinterConnection("\\TWCPRT01\AfC")
$nul = SetDefaultPrinter("\\TWCPRT01\AfM")
$nul = MessageBox("Connecting you CC-ADMIN printers", "IT Department", 0, 4)
case INSTR($OU, 'L-BABBAGE')
$nul = AddPrinterConnection("\\TWCPRT01\AfM")
$nul = AddPrinterConnection("\\TWCPRT01\LibraryM")
$nul = AddPrinterConnection("\\TWCPRT01\Libraryc")
$nul = AddPrinterConnection("\\TWCPRT01\AfC")
$nul = SetDefaultPrinter("\\TWCPRT01\AfM")
$nul = MessageBox("Connecting you to the Aficio printer", "IT Department", 0, 4)
CASE 1
$nul = MessageBox("No Printers Connected", "IT Department", 0, 4)
EndSelect
; -------
;Mapped Drive
use k: "\\zeus\Intranet$"
use q: "\\zeus\Photos$"
use s: "\\zeus\Sherston$"
use o: "\\zeus\staff-pupil$"
use x: "\\zeus\applications"
use y: "\\zeus\%username%$"
If InGroup("GROUP-ADMIN")
use j: "\\TWC-3cx\Sync"
use r: "\\zeus\Reports$"
use w: "\\zeus\Staffdata$"
EndIf
;End_of_Script
:End
Exit
Edited by ShaneEP (2012-10-19 04:50 PM)
|
|
Top
|
|
|
|
#206049 - 2012-10-20 05:29 PM
Re: Just Starting out With Kix
[Re: ShaneEP]
|
Dariusvw
Fresh Scripter
Registered: 2012-02-11
Posts: 11
Loc: South Africa
|
The sleep 3 was put in because the user was not getting their default Printer "selected". All the printers were loading, i just did not set one as default.
The assumption was that the printers had not finished loading when it was trying to set the default.
Sleep 3, solved the problem.
|
|
Top
|
|
|
|
#206437 - 2012-12-11 11:08 AM
Re: Just Starting out With Kix
[Re: Dariusvw]
|
Dariusvw
Fresh Scripter
Registered: 2012-02-11
Posts: 11
Loc: South Africa
|
Greetings
Sorry it has been awhile, things have been a tad hectic over here. I have however run into a problem.
If I use this code, the user who is a member of Group-admin gets her Y Drive and no others.
;Mapped Drive
use Y: "\\zeus\%username%$"
If InGroup ("Group-Junior")
use N: "\\zeus\academic$"
use S: "\\zeus\Sherston$"
use Y: "\\zeus\%username%$"
If InGroup ("GROUP-ADMIN")
;use K: "\\zeus\Intranet$"
use J: "\\TWC-3cx\Sync"
;use Q: "\\zeus\Photos$"
;use R: "\\zeus\Reports$"
use V: "\\twcstore01\Staff & Pupil"
use W: "\\twcstore01\Resources-S"
use X: "\\zeus\applications"
But if i use this code She gets nothing @ all.
;Mapped Drive
If InGroup ("Group-Junior")
use N: "\\zeus\academic$"
use S: "\\zeus\Sherston$"
use Y: "\\zeus\%username%$"
If InGroup ("GROUP-ADMIN")
;use K: "\\zeus\Intranet$"
use J: "\\TWC-3cx\Sync"
;use Q: "\\zeus\Photos$"
;use R: "\\zeus\Reports$"
use V: "\\twcstore01\Staff & Pupil"
use W: "\\twcstore01\Resources-S"
use X: "\\zeus\applications"
use Y: "\\zeus\%username%$
"Group-admin" is a Active Directory "universal" "security Group". If that helps any.
Should I be Using something like
$OU = CreateObject("ADSystemInfo").computername
"Computer dn: "+$OU ?
but for a user group not a PC group.
Thanks all
|
|
Top
|
|
|
|
#206440 - 2012-12-11 05:40 PM
Re: Just Starting out With Kix
[Re: BradV]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Just to elaborate with an example of what Mart and BradV pointed out.
$nul = SetOption("NoVarsInStrings","ON") ; Place these setoptions at the top of your script to ensure that dollar
$nul = SetOption("NoMacrosInStrings","ON") ; signs and @'s inside of quotes are not seen as kix variables or macros.
;Mapped Drive
If InGroup ("Group-Junior")
use N: "\\zeus\academic$"
use S: "\\zeus\Sherston$"
use Y: "\\zeus\"+@UserID+"$" ; Remove macros and variables from inside strings like so.
EndIf ; Make sure that you always include ENDIFs to close an IF block.
If InGroup ("GROUP-ADMIN")
;use K: "\\zeus\Intranet$"
use J: "\\TWC-3cx\Sync"
;use Q: "\\zeus\Photos$"
;use R: "\\zeus\Reports$"
use V: "\\twcstore01\Staff & Pupil"
use W: "\\twcstore01\Resources-S"
use X: "\\zeus\applications"
use Y: "\\zeus\"+@UserID+"$"
Endif
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2312 anonymous users online.
|
|
|