I am trying to use the UDF "fnMapped" function to no avail. I am new to the UDF world and am probably missing something.... I am including some lines of script for review. Only the "fnMapped" portion is failing. Any ideas?
;---------------------- MAPPED DRIVE ERROR CHECKING ------------------------- ; ;USE L: /DELETE ;(FOR DEBUGGING) ; $DL="F:\" IF EXIST ("F:\") GOSUB "CHECKG" ELSE GOTO "ERROR" ENDIF ; :CHECKG $DL="G:\" IF EXIST ("G:\") GOSUB "CHECKG2" ELSE GOTO "ERROR" ENDIF ; :CHECKG2 fnMapped(\\ADMIN\COMMON) ? IF fnMapped(\\ADMIN\COMMON)=(G:\) GOSUB "CHECKH" ELSE GOTO "MISDIRECT" ENDIF ; :CHECKH $DL="H:\" IF EXIST ("H:\") GOSUB "CHECKI" ELSE GOTO "ERROR" ENDIF ; :CHECKI $DL="I:\" IF EXIST ("I:\") GOSUB "LOGON" ELSE GOTO "ERROR" ENDIF ; ; ;---------------------- MESSAGE BOX PROMPTED TO USER ------------------------ ; :MISDIRECT BEEP MESSAGEBOX ("Your login to the SUSD Network has reported an error." + CHR(10) + "Some network resources may not be available." + CHR(10) + "Your $DL network drive did not connect correctly." + CHR(10) + "Please report this to your I.T. Department." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!" + CHR(10) + "", "Sunnyside USD #12 - ERROR - $DL Drive Failed to Connect", 48, 45) GOSUB "END" ; :ERROR BEEP MESSAGEBOX ("Your login to the SUSD Network has reported an error." + CHR(10) + "Some network resources may not be available." + CHR(10) + "Your $DL network drive did not connect correctly." + CHR(10) + "Please report this to your I.T. Department." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!" + CHR(10) + "", "Sunnyside USD #12 - ERROR - $DL Drive Missing", 48, 45) GOSUB "END" ; ; ; ; :LOGON MESSAGEBOX ("Welcome to the Sunnyside USD Computer Network." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!!", "Sunnyside USD #12 - LOGIN SUCCESSFUL !!!", 64, 45) ; :END ;----------- TELLS THE SCRIPT INTERPRETER THAT THE SCRIPT IS DONE ----------- COOKIE1 EXIT ; ; UDF DEFINITIONS ;---fnMapped--- Function fnMapped($sUNC) Dim $oDrives,$oDrive $oDrives = CreateObject("Scripting.FileSystemObject").Drives If Not VarType($oDrives) & 9 Exit 1 EndIf For Each $oDrive in $oDrives If $oDrive.DriveType = 3 AND $sUNC = $oDrive.ShareName $fnMapped = $oDrive.DriveLetter + ":" EndIf Next EndFunction
Thank you ...(sigh)...I've been looking at it too long now. Still no success though....I ran debug and it does not see a problem but the function(UDF)simply does not run..? I have appended(pasted from source)the UDF in question to bottom of my script and saved. Is there another step? Insatallation of some kind that I am missing?
Affirmative, I just discovered that by noticing the output echoed back to the screen was G: as opposed to G:\ and through various changes in repetition. You are right on the money. And it works nicely at this point. Thank you for all your input. An isolated section of script looks as follows: ;fnMapped("\\ADMIN\NOGROUP$") ? ;(Uncomment to echo drive letter output to window.) IF NOT fnMapped("\\ADMIN\NOGROUP$") = (G:) GOSUB "CHECKH" ELSE GOTO "MISDIRECT" ENDIF
OK, I am just going to post the script entirely here and the let you guys have a look at it. Anything you'll can do to help, I'm all ears. Yes I know the code is a bit cavemanish but, I've been trying to teach myself.... The script does work correctly, but I'm sure is not very graceful in motion...
Here it is: ------------------------------------------------------------------------------- ; DOADMIN.KIX ; ; Logon Script for SUSD ; ; ; ; ; Script Author: Michael Ingrando ; Date: 10-21-05 ; ;------- OVERWRITE THIS SECTION TO KEEP THE LAST KNOWN EDITOR CURRENT ------- ; ; Last Modified by: ; Date: ; ;DEBUG ON ;(Uncomment for debugging feature) ; ;------------------------ CANCEL SCRIPT IF SERVER --------------------------- ; IF @wksta = "ADM-DC1" OR @wksta = "ADM-PRT" OR @wksta = "ADMIN-DO" OR @wksta = "ADM-GHT" OR @wksta = "ADMIN" OR @wksta = "ADMIN-IT" OR @wksta = "ADMININET" OR @wksta = "HMSQ" ; COOKIE1 EXIT ENDIF ; ; ;--------------------- PROGRESS DIALOG BOX PRESENTED ------------------------ ; CLS SMALL $TopLeftRow = 0 $TopLeftCol = 0 $BtmRtRow = 30 ;Height $BtmRtCol = 80 ;Width ; Color c/c BOX($TopLeftRow, $TopLeftCol, $BtmRtRow, $BtmRtCol, SINGLE) ; Color r/c+ AT(10, 10) "Please Standby While Network Resources are Established..." Sleep 1 ; Color n/c AT(13,18) "Reviewing User Account Information.........." Sleep 1 ; ; ; ;------------------------------ SET VARIBLES -------------------------------- ; ****** Notice: Always put quotes around all strings. ****** ; $AMN ="\\ADMIN" $ADO ="\\ADMIN-DO" $ADG ="\\ADM-GHT" $DC1 ="\\ADM-DC1" $AIN ="\\ADMININET" $PRT ="\\ADM-PRT" $ITS ="\\ADMIN-IT" $HSQ ="\\HMSQ" ; $Common = $AMN + "\Common" $Apps = $AMN + "\Apps" $Nurses = $HSQ + "\Nurses$" $Itshare = $ITS + "\It-Share$" $FOOD = $AMN + "\Food Services$" ; ;----------- SET GROUPSHARE VARIABLE (Based on group membership.) ----------- ; DEFAULT $GroupShare to NOGROUP$ to prevent script from crashing on assumed variable! ; (THE EFFECT OF MULTIPLE MEMBERSHIP IS THE LAST MAPPING TAKES PRECEDENCE.) ; $GroupShare = $AMN + "\NOGROUP$" ; ; IF INGROUP ("Business & Finance") $GroupShare= $AMN + "\Business & Finance$" ENDIF ; IF INGROUP ("Career Ladder") $GroupShare= $AMN + "\Career Ladder$" ENDIF ; IF INGROUP ("Curriculum") $GroupShare= $AMN + "\Curriculum & Instruction$" ENDIF ; IF INGROUP ("Domain Admins") $GroupShare= $ITS + "\Infotech$" ENDIF ; IF INGROUP ("Educational Services") $GroupShare= $AMN + "\Educational Services$" ENDIF ; IF INGROUP ("Food Services") $GroupShare= $AMN + "\Food Services$" ENDIF ; IF INGROUP ("INFOTECH") $GroupShare= $ITS + "\InfoTech$" ENDIF ; IF INGROUP ("Language Aquisition") $GroupShare= $AMN + "\Language Aquisition$" ENDIF ; ;IF INGROUP ("Leadership Developement") $GroupShare= $AMN + "\Leadership Developement$" ENDIF ; IF INGROUP ("MAINTENANCE") $GroupShare= $AMN + "\Maintenance$" ENDIF ; IF INGROUP ("MultiMedia Services") $GroupShare= $AMN + "\MultiMedia Services$" ENDIF ; IF INGROUP ("Native American Edu") $GroupShare= $AMN + "\Native American Edu$" ENDIF ; IF INGROUP ("Operations") $GroupShare= $AMN + "\Curriculum & Instruction$" ENDIF ; IF INGROUP ("Personnel Services") $GroupShare= $AMN + "\Personnel Services$" ENDIF ; IF INGROUP ("Public Relations") $GroupShare= $AMN + "\Public Relations$" ENDIF ; IF INGROUP ("Purchasing Property Control") $GroupShare= $AMN + "\Purchasing Property Control$" ENDIF ; IF INGROUP ("Research Evaluation") $GroupShare= $AMN + "\Research Evaluation$" ENDIF ; IF INGROUP ("Special Services") $GroupShare= $AMN + "\Special Services$" ENDIF ; IF INGROUP ("Staff Development") $GroupShare= $AMN + "\Staff Development$" ENDIF ; IF INGROUP ("Student Services") $GroupShare= $AMN + "\Student Services$" ENDIF ; IF INGROUP ("Superintendent") $GroupShare= $AMN + "\Superintendent$" ENDIF ; IF INGROUP ("Title I") $GroupShare= $AMN + "\Title I$" ENDIF ; IF INGROUP ("TRANSPORTATION") $GroupShare= $AMN + "\TRANSPORTATION$" ENDIF ; ; ;------------------ CONTINUE PREVIOUS PROGRESS DIALOG BOX ------------------- ; AT(16,22) "Thank You, Login will continue....." Sleep 1 CLS ; ;---------------------------- MAP GLOBAL DRIVES ----------------------------- ; Color n/c AT (1,14) "Mapping District Standard Global Network Drives......" SLEEP 1 ; ;----------- MAP STANDARD DRIVES FOR ALL SITES (Global Mappings) ------------ ; USE F: $Apps ; USE G: $GroupShare ; USE I: $Common ; IF INGROUP ("Nurses") USE N: $Nurses ENDIF ; IF INGROUP ("Domain Admins") USE O: $Itshare ENDIF ; IF INGROUP ("Food Services") USE W: $Food ENDIF ; ; ; ;------- THE NEXT MAPPINGS PORTION OF THE SCRIPT IS UNIQUE TO THE SITE ------ ; ;----------------------------- MAP LOCAL DRIVES ----------------------------- ; Color n/c AT (3,14) "Mapping Site-Based Local Network Drives.............." SLEEP 1 ; ; ;------------------ MAP SITE OR APPLICATION SPECIFIC DRIVES ----------------- ; ;IF INGROUP ("Domain Users") USE M: ENDIF ; ; ;-------------------------- MAP CDROM TOWER DRIVES -------------------------- ;------------------------ (NOT IN USE AT THIS TIME) ------------------------- ; ; ;------------------ END UNIQUE MAPPINGS PORTION OF SCRIPT ------------------- ; ; ; ;------------------------------- CHECK UPDATES ------------------------------ ; Color n/c AT (5,14) "Checking for Updates and Configuration Changes......." SLEEP 1 ; ;----------------------- CREATE UPDATES IN THIS SECTION --------------------- ; ;----------------------- REGISTRY MODIFICATION SECTION ---------------------- ; ;---------------------------- UPDATES COMPLETED ----------------------------- ; Color n/c AT (7,14) "Updates and Configuration Changes Completed.........." SLEEP 1 ; ;-------------------------- DISPLAY USER SETTINGS --------------------------- ; SMALL Color g+/n BOX (10,14,18,66,FULL) Color w+/n AT ( 11,20)"Userid : " ; User Login Information Window Text Strings AT (12,20) "Full name : " AT (13,20) "Privilege : " AT (14,20) "Workstation : " AT (15,20) "Domain : " AT (16,20) "Logon Server : " AT (17,20) "Script Used : " Color y+/n AT ( 11,37) @userid ; Associated Macro's AT (12,37) @fullname AT (13,37) @priv AT (14,37) @wksta AT (15,37) @domain AT (16,37) @lserver AT (17,37) @scriptname sleep 3 ; ; ;--------------------- CONFIRM GLOBALLY MAPPED DRIVES ---------------------- ; Color n/c AT (21,14) "Verifying Globally Mapped Network Drive Connections..." SLEEP 1 ; ; ;---------------------- MAPPED DRIVE ERROR CHECKING ------------------------- ; ;USE L: /DELETE ;(FOR DEBUGGING) ; $DL="F:\" IF EXIST ("F:\") GOSUB "CHECKG" ELSE GOTO "ERROR" ENDIF ; :CHECKG $DL="G:\" IF EXIST ("G:\") GOSUB "CHECKG2" ELSE GOTO "ERROR" ENDIF ; :CHECKG2 ;fnMapped("\\ADMIN\NOGROUP$") ? ;(Uncomment to echo drive letter output to window.) IF fnMapped("\\ADMIN\NOGROUP$") <> "G:" GOSUB "CHECKH" ELSE GOTO "MISDIRECT" ENDIF ; :CHECKH $DL="H:\" IF EXIST ("H:\") GOSUB "CHECKI" ELSE GOTO "ERROR" ENDIF ; :CHECKI $DL="I:\" IF EXIST ("I:\") GOSUB "LOGON" ELSE GOTO "ERROR" ENDIF ; ; ;---------------------- MESSAGE BOX PROMPTED TO USER ------------------------ ; :MISDIRECT BEEP MESSAGEBOX ("Your login to the SUSD Network has reported an error." + CHR(10) + "Some network resources may not be available." + CHR(10) + "Your $DL network drive to security group association has failed." + CHR(10) + "Please report this to your I.T. Department." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!" + CHR(10) + "", "Sunnyside USD #12 - ERROR - $DL Drive Association Failed ", 48, 15) GOSUB "END" ; :ERROR BEEP MESSAGEBOX ("Your login to the SUSD Network has reported an error." + CHR(10) + "Some network resources may not be available." + CHR(10) + "Your $DL network drive did not acquire a connection." + CHR(10) + "Please report this to your I.T. Department." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!" + CHR(10) + "", "Sunnyside USD #12 - ERROR - $DL Drive Missing", 48, 15) GOSUB "END" ; ; ; ; :LOGON MESSAGEBOX ("Welcome to the Sunnyside USD Computer Network." + CHR(10) + "Your account has been validated by @LSERVER." + CHR(10) + "The time is @DAY, @TIME, @DATE." + CHR(10) + " Have a nice day ;o) !!!", "Sunnyside USD #12 - LOGIN SUCCESSFUL !!!", 64, 15) ; :END ;----------- TELLS THE SCRIPT INTERPRETER THAT THE SCRIPT IS DONE ----------- COOKIE1 EXIT ; ;--------------------------- UDF DEFINITIONS -------------------------------- ;------------------------------ fnMapped ------------------------------------ ; Function fnMapped($sUNC) Dim $oDrives,$oDrive $oDrives = CreateObject("Scripting.FileSystemObject").Drives If Not VarType($oDrives) & 9 Exit 1 EndIf For Each $oDrive in $oDrives If $oDrive.DriveType = 3 AND $sUNC = $oDrive.ShareName $fnMapped = $oDrive.DriveLetter + ":" EndIf Next EndFunction
Well, the first thing I would suggest is get rid of all those IF/ENDIF's and go with the SELECT/CASE/ENDSELECT ... much easier on the eyes and prolly lot faster too...
btw - this assumes that your user's can't be a member of more than one of these groups ... that they're mutually exclusive ...
#150270 - 2005-10-2106:09 AMRe: Script needs general review.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11628
Loc: CA
Michael,
Please use the UBB TAGS for posting code. It makes it soooooo much easier to read and understand when used. When you post you should see items there for editing your post. Those are called UBB TAGS.
Instant UBB Code URL Email Image List Start List Item List End Bold Italics Underline Quote Code
The board even has an FAQ on what they all mean and how to use all of them.
#150271 - 2005-10-2109:25 AMRe: Script needs general review.
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11628
Loc: CA
Okay, here is a little re-write of your code. You need to review it for any obvious errors or missing / invalid information as applies to your environment.
I tried not to stray too far off of what I think you're attempting to do here.
I would probably clean it up more and do some things a bit different, but you should get the general idea here.
This script does away with the GOTO and GOSUB routines by using User Defined Functions
I also set the SetOptions so that you are forced to write cleaner code.
Let us know how it goes. Notice that the use of the Select / EndSelect will ONLY check for membership in 1 group. Once that group is found it will quit checking the other statements. If you have users that are in more then one group and you need to map multiple drives based on multiple memberships then you will need to use some IF/ENDIF statements to handle those.
NOTE: I wrote this script for use with KiXtart 4.5 It may work fine with earlier versions but I can't say for sure.
WOW, Thanks tons for the rewrite.... really unexpected. This forum is awesome ( your efforts especially). This will give me something to really sink my teeth into. I'm getting in late tonight, but I'll be reviewing it this weekend do some trials at work next week. Thanks again for your support, this really blows me away.