Page 1 of 1 1
Topic Options
#130489 - 2004-12-02 06:33 PM Assist in my code
Googlezx Offline
Fresh Scripter

Registered: 2004-12-02
Posts: 6
This is the portion of my code
I have two File servers (FS1 and FS2)
Basically what script will do is check for a group that has a prefix of "_" and then assign the first group membership to letter S: then if user is a member of another group I then J.
What I want to do is if a user is a member of a group called _PTK it will map it to letter N: which is then pointing to my third File server called FS3.
Any idea how the code will looks like.

Cannot make it to work

Code:

$x="$$"
$v="\\FS1.xyz.org\"
; add
$w="\\FS2.xyz.org\"
; call the users drive
$u=@userid
$dir=$v+$u+$x

:COMMENT
$s = instr(@COMMENT,"(")
$e = instr(@COMMENT,")")
$l = ($e - $s) - 1
IF $s = 0
$g = "NONE"
ELSE
IF $e > 0
$g = SUBSTR(@COMMENT,$s+1,$l)
ELSE
$g = "NONE"
ENDIF
ENDIF

$grp=$w+$g+$x

:HOME
; REM NET USE HOME DIRECTORY
USE F: $dir
:SETGROUP
SET "GROUP=$g"
DIM $Group[20]
$i=0
$j=0
do
if substr(ENUMGROUP($i),1,1) = "_"
$j=$j+1
$Group[$j] = substr ENUMGROUP ($i),2,Len (ENUMGROUP($i))-1)
? $i " " $j " " $Group[$j]
?
endif
$i=$i+1
UNTIL Len(ENUMGROUP($i)) = 0 OR $i=20

$grp0=$w+$Group[1]+$x
$grp1=$w+$Group[2]+$x
$grp2=$w+$Group[3]+$x
$grp3=$w+$Group[4]+$x
$grp4=$w+$Group[5]+$x
$grp5=$w+$Group[6]+$x
$global="GLOBAL"
$gl=$w+$global+$x
USE L: $gl
if $j > 0
USE S: $grp0
endif
if $j > 1
USE I: $grp1
endif
if $j > 2
USE J: $grp2
endif
if $j > 3
USE K: $grp3
endif



Edited by Jooel (2004-12-03 09:07 AM)

Top
#130490 - 2004-12-02 07:05 PM Re: Assist in my code
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Please edit your post to include CODE tags and proper indenting.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#130491 - 2004-12-03 08:54 AM Re: Assist in my code
Googlezx Offline
Fresh Scripter

Registered: 2004-12-02
Posts: 6
I did the editing sorry I'm not good in programing that much.My NT groups are named with an underscore "_" and if a user is a mamber of firstoup it will map to Drive S then to next drive L etc etc. this script is working I just want to seperate a group called _PTK and assigne it to diffirent File server if of course a user who login is a mamber of that group.
Top
#130492 - 2004-12-03 09:09 AM Re: Assist in my code
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
quess you just didn't listen or are afraid to say you don't know how.
_________________________
!

download KiXnet

Top
#130493 - 2004-12-03 09:19 AM Re: Assist in my code
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, now as there are code tags...
can understand why you said you are not that good coder.

to be honest, I would drop that code above totally and sit down.
draw it on paper what you actually want.
I think what you are doing here is making it harder than it really is.
I bet your code should be something like:
Code:

if ingroup("_mygroup1")
use S: "\\fs1\groupdrive"
endif
if ingroup("_mygroup2")
use J: "\\fs2\groupdrive"
endif
if ingroup("_mygroup3")
use N: "\\fs3\groupdrive"
endif



well, at least that's how it reads in your explanations.
_________________________
!

download KiXnet

Top
#130494 - 2004-12-03 11:10 AM Re: Assist in my code
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I have a similar system, although my groups are name "MAP x share", where "share" is a share mnemonic, and "x" is the drive letter that I want to map it it. I prefer this becasue it keeps the drive letters consistent.

The following code should work for you:

Code:
Break ON
$=SetOption("Explicit","ON")

Dim $sHidden, $sFS1, $sFS2, $sFS3
Dim $iIndex, $sGroup, $sGroupRN
Dim $sDriveList

; Define constants
$sHidden="$$"
$sFS1="bar.com"
$sFS2="foo.com"
$sFS3="other.com"

$sDriveList="S:I:J:"

$iIndex=0 $sGroup=EnumGroup($iIndex)
While Not @ERROR AND $sGroup <> ""
; Drop domain name.
$sGroupRN=SubStr($sGroup,InStr($sGroup,"\")+1)
Select
Case $sGroupRN="_PTK"
If MapDrive("N:","\\"+$sFS3+"\"+"PTKSHARE"+$sHidden)
"ERROR: Cannot map drive 'N:' to path '"+"\\"+$sFS3+"\PKTSHARE"+$sHidden+"'"+@CRLF
"REASON: ["+@ERROR+"] "+@SERROR+@CRLF
EndIf
Case Left($sGroupRN,1)="_"
; Handle special group mappings.
If $sDriveList
If MapDrive(Left($sDriveList,2),"\\"+$sFS2+"\"+SubStr($sGroupRN,2)+$sHidden)
"ERROR: Cannot map drive '"+Left($sDriveList,2)+"' to path '"+"\\"+$sFS2+"\"+SubStr($sGroupRN,2)+$sHidden+"'"+@CRLF
"REASON: ["+@ERROR+"] "+@SERROR+@CRLF
Else
$sDriveLetter=SubStr($sDriveLetter,3)
EndIf
Else
"ERROR: Exhausted drive letters."+@CRLF
" Cannot map share for group "+$sGroup+@CRLF
EndIf
Case "Default"
"No special handling for group "+$sGroup+@CRLF
EndSelect
$iIndex=$iIndex+1 $sGroup=EnumGroup($iIndex)
Loop

Exit 0

Function MapDrive($d,$p)
Use $d /delete /persistent
Use $d $p
$MapDrive=@ERROR
Exit $MapDrive
EndFunction



This will map _PTK to a hardcoded path (on drive N:).

The first group starting "_" (which is not _PTK) will be mapped to S:, the next to I:, and the third to "J:". Any "_" group after that will issue an error message.

If you want to add more drive letters to the available pool, just change the $sDriveLetters variable.

Top
#130495 - 2004-12-03 04:09 PM Re: Assist in my code
Googlezx Offline
Fresh Scripter

Registered: 2004-12-02
Posts: 6
Thanks for your input Richard. Actually I just it need for testing and that is why I need to insert a liite codes to isolate of of the shares to a static drive.

$sFS3="FS-nas4000"
.
.
.

I tried to insert your function and this line
If MapDrive("N:","\\"+$sFS3+"\"+"PTKshare"+$sHidden)
EndIf

Function MapDrive($d,$p)
Use $d /delete /persistent
Use $d $p
$MapDrive=@ERROR
Exit $MapDrive
EndFunction

But it didnt work!
I know your codes is almost same with me but I dont have time so recode mine to have a similar like yours just to reflect what I want(just need it for testing).

Can you assist please how it should like to my code.

Sorry for all of these.




Edited by orlando2 (2004-12-03 04:19 PM)

Top
#130496 - 2004-12-05 04:46 PM Re: Assist in my code
Googlezx Offline
Fresh Scripter

Registered: 2004-12-02
Posts: 6
Hi
It is me again. I tried to revise my existing code and replace it with yours to see if this will help me achieve what I want.

However, I got an error when I run it.
Script Error: Expected Expression!
$=SetOption("Explicit","ON")
Is there any idea how to check this error.






Top
#130497 - 2004-12-05 05:04 PM Re: Assist in my code
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
While explicit on is a very good habit to get into, it is not for newbies that don't yet understand the implications of it and don't understand that it is not supported in all versions of KiX.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#130498 - 2004-12-05 05:35 PM Re: Assist in my code
Googlezx Offline
Fresh Scripter

Registered: 2004-12-02
Posts: 6
I managed to get ride of that error by upgrading to kix32 ver 4.22 and the script managed to run successuly.
However it didnt map to any drive and got some error

No special handling for group Everyone
No special handling for group Interactive
No special handling for group Authenticated USers
No special handling for group mylocalmachine\Administrators
No special handling for group mylocalmachine\Users
No special handling for group mylocalmachine\Power Users


Can you have a look one more time please maybe I'm missing something. Thank you



Top
#130499 - 2004-12-05 05:58 PM Re: Assist in my code
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
So, what were you running beforehand? If you don't specify the KiXtart version in your questions, then we assume you're running the latest version.
_________________________
There are two types of vessels, submarines and targets.

Top
#130500 - 2004-12-06 09:50 AM Re: Assist in my code
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Post the code that you have.

If you've been cherry-picking bits out of the code I posted you may have a version which is no longer functional.

You can also try adding some diagnostic debug messages to see what is going on. A good example would be the MapDrive() function:
Code:
Function MapDrive($d,$p)
"[DEBUG] Mapping '"+$d+"' to '"+$p+"'"+@CRLF
Use $d /delete /persistent
Use $d $p
$MapDrive=@ERROR
"[DEBUG] MapDrive exit status is:"+@CRLF
" "+@ERROR+": "+@SERROR+@CRLF
Exit $MapDrive
EndFunction


Top
Page 1 of 1 1


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

Who's Online
0 registered and 1955 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.08 seconds in which 0.052 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