Page 1 of 1 1
Topic Options
#206040 - 2012-10-19 01:05 PM Just Starting out With Kix
Dariusvw Offline
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

 Code:
; *******************

$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 Moderator Offline
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...
 Code:
ADDPRINTERCONNECTION ("\\TWCPRT01\AfM")
To this...
 Code:
$nul = ADDPRINTERCONNECTION ("\\TWCPRT01\AfM")


Same goes for SetDefaultPrinter, and MessageBox


Edited by ShaneEP (2012-10-19 04:36 PM)

Top
#206043 - 2012-10-19 04:37 PM Re: Just Starting out With Kix [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Also, the 'Sleep 3' lines are not needed. It should work fine (and faster) without them.
Top
#206044 - 2012-10-19 04:44 PM Re: Just Starting out With Kix [Re: ShaneEP]
ShaneEP Moderator Offline
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.

 Code:
; *******************

$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 Offline
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 Offline
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.

 Code:
;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.
 Code:
;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

 Code:
$OU = CreateObject("ADSystemInfo").computername
"Computer dn: "+$OU ?


but for a user group not a PC group.

Thanks all

Top
#206438 - 2012-12-11 11:19 AM Re: Just Starting out With Kix [Re: Dariusvw]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
A few things that stand out.

  • Every If needs an EndIf. I do not see them in your code.
  • You are using %username%. This is possible but kix has the same info in the @UserID macro.
  • Do not use variables in strings. You can simple say $test = "1234" + @UserID for example.
  • You have some hidden shares. They use the dollar character at the end which is also the first character of a kix variable. You may need to double up on all of them so kix leaves them alone.

I would temporarily add an else statement to all failing If statements so you can see if the group check actually returns what it should.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#206439 - 2012-12-11 12:34 PM Re: Just Starting out With Kix [Re: Mart]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Like Mart said, the missing end ifs are probably your problem. Assuming she is not a member of group-junior, kix fails the first if and is searching for the endif. Since it doesn't find it, it never executes the group-admin if.
Top
#206440 - 2012-12-11 05:40 PM Re: Just Starting out With Kix [Re: BradV]
ShaneEP Moderator Offline
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.

 Code:
$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
Page 1 of 1 1


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

Who's Online
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.07 seconds in which 0.034 seconds were spent on a total of 13 queries. Zlib compression enabled.

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