Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: disconnect drives
Word of warning, don't open the dialog with the Dialog Editor unless you save a backup copy first, as this will cause some of the dialog code to be lost.
;********* ;********* Network Drive disconnect script for Win32 and Novell 3.x Networks ;********* ;********* All disclaimers and legal mumbojumbo that are always applied to shareware/freeware ;********* apply to this chunk of code too. Every effort was made to throughly debug this script ;********* before sending it out. However, I make ABSOLUTELY NO WARRANTEE, EXPRESS OR IMPLIED, ;********* as to the operation of this script. ;********* ;********* This script allows network drives to be disconnected without opening an Explorer ;********* window. A single drive, multiple drives or all drives can be disconnected from ;********* selections made in a single dialog. The script will not attempt to disconnect local ;********* removable, CD-Rom or hard drives. ;********* ;********* This script was written to test for Microsoft Win32 and Novell Netware 3.X network ;********* resources, since these are the networks that I work with. You will need to change ;********* the path in the AddExtender commands to point to your Winbatch\System directory. ;********* If you use different networks, you will need to substitute the correct WIL Network ;********* Extender for your network(s) and change all commands which are specific to the ;********* corresponding WIL Network Extender(s). ;********* ;********* This script tests all drive letters (A: - Z:), to determine which type of drives are ;********* mapped. The mapping information passed to a dialog, Ask_drv.WDL, which is called ;********* by this script. Ask_drv.WDL was created with the Dialog Editor and then edited ;********* with Notepad, as needed. The dialog uses 26 checkbox controls to allow selection ;********* of drives to be disconnected. A string variable is used in the text field of these ;********* controls. The strings are passed to the dialog through 26 variables, UNC0 - UNC25, ;********* created during the first loop of this script. If a drive is mapped to a network ;********* resource, the UNC name will be stored in the corresponding UNCx variable. If not a ;********* network resource, the variable will contain the appropriate drive type, depending on the ;********* mapping test result. The dialog returns 26 variables (A - Z), which contain the values ;********* returned by the checkbox controls. The returned values are used by this script to ;********* determine if a given drive has been selected for disconnect. ;********* ;********* ********!!! WARNING !!!******** ;********* ;********* If you want to edit the Ask_drv.WDL script, use Notepad. If you want to use Dialog Editor ;********* to open the dialog, SAVE A BACKUP COPY OF THE DIALOG FIRST ! If the script is opened ;********* and then saved with Dialog Editor, the references to variables UNC0 - UNC25 will be lost. ;********* The dialog will still execute if this happens, but the checkboxes will no longer display ;********* any information about drive mapping. This makes the dialog pretty useless, unless you ;********* have committed all of your drive mapping to memory. ;********* ;********* A list named Type is also created during the first loop of this script. Type contains ;********* 26 items, each an ASCII value for an integer, which indicates the type of resource ;********* mapped to each drive. Later in the script, these values are converted to integers and ;********* used to determine whether to skip or disconnect selected drives. ;********* The following are values which may be found in Type, and their meanings: ;********* 1 = unmapped/unidentified, 2 = Removable Media drive, 3 = Hard Drive, 4 = CDRom Drive, ;********* 5 = RamDisk, 6 = Win32 Network resource, 7 = Netware resource. ;********* ;********* Note that drive disconnects are forced, ignoring the state of any open files on drives ;********* that are selected for disconnect. ;********* ;********* Attention 16 bit WIL users ;********* This script was produced with the 32 bit version of WIL. It uses the 32 bit network extenders ;********* and some (or all ?) of the commands may not work with 16 bit WIL. Sorry I can't give any more ;********* help than this, but I have never worked with the 16 bit version. ;********* ;********* AddExtender("E:\winbatch\system\WWN3Z34I.DLL") ; WIL extender for Netware 3.x AddExtender("E:\winbatch\system\WWW9534I.DLL") ; WIL extender for Win32 network ;Stick these DLLs in the windows directory for Netware 3.X support - nwcalls.dll, wwn3z16i.dll Display (6,"Network Disconnect","All windows will minimize during this execution.%@CRLF%They will be maximized at completion.") ;************ Minimize open windows reopen = "" windows = WinItemize() ;get list of windows cnt = ItemCount(windows, @TAB) for c = 1 to cnt current = ItemExtract(c, windows, @TAB) ;get windows name if WinState(current) == @HIDDEN || WinState(current) == @ICON then continue ;if window is hidden or icon, skip reopen = ItemInsert(current, -1, reopen, @TAB) ;store name in list to reopen later WinIconize(current) ;minimize window next ;************ remv = DiskScan (1) ;check for removable drives hard = DiskScan (2) ;check for hard drives netw = DiskScan (4) ;check for network drives cdrom = DiskScan (8) ;check for CDRom drives ramdk = DiskScan (16) ;check for RamDisks rem = ItemCount (remv, @TAB) hrd = ItemCount (hard, @TAB) cdr = ItemCount (cdrom, @TAB) ram = ItemCount (ramdk, @TAB) Type = "" ;************ Determine drive mapping and assign "drive type" values BoxOpen ("Disconnect Drives","Checking drive mapping") for d = 0 to 25 ;loop to check for existing drives drive = StrCat( num2char( char2num("A") + d ), ":" ) BoxText("Drive %drive%") if DiskExist("%drive%") == @TRUE then goto locltst ;jump if drive exists UNC%d% = "UNMAPPED DRIVE" Type = ItemInsert(Num2Char(1), -1, Type, @TAB) ;log as unmapped drive continue :locltst if rem==0 && hrd==0 && cdr==0 && ram==0 then goto nettst ;jump if all local drives accounted for if rem == 0 then goto hrdtst ;jump if no removable drives left if ItemExtract(1, remv, @TAB) != drive then goto hrdtst ;check if drive is in removable list UNC%d%= "REMOVABLE MEDIA DRIVE" Type = ItemInsert(Num2Char(2), -1, Type, @TAB) ;log drive as "Type 2" remv = ItemRemove(1, remv, @TAB) ;delete item rem = rem - 1 ;update count continue :hrdtst if hrd == 0 then goto cdrtst ;jump if no Hard drives left if ItemExtract(1, hard, @TAB) != drive then goto cdrtst ;check if drive is in Hard drive list UNC%d%= "HARD DRIVE" Type = ItemInsert(Num2Char(3), -1, Type, @TAB) ;log drive as "Type 3" hard = ItemRemove(1, hard, @TAB) ;delete item hrd = hrd - 1 ;update count continue :cdrtst if cdr == 0 then goto ramtst ;jump if no CD-Rom drives left if ItemExtract(1, cdrom, @TAB) != drive then goto ramtst ;check if drive is in CD-Rom list UNC%d%= "CD-ROM DRIVE" Type = ItemInsert(Num2Char(4), -1, Type, @TAB) ;log drive as "Type 4" cdrom = ItemRemove(1, cdrom, @TAB) ;delete item cdr = cdr - 1 ;update count continue :ramtst if ram == 0 then goto nettst ;jump if no RamDisks left if ItemExtract(1, ramdk, @TAB) != drive then goto nettst ;check if drive is in RamDisk list UNC%d%= "RAMDISK" Type = ItemInsert(Num2Char(5), -1, Type, @TAB) ;log drive as "Type 5" ramdk = ItemRemove(1, ramdk, @TAB) ;delete item ram = ram - 1 ;update count continue :nettst if ItemExtract(1, netw, @TAB) == drive then goto getnet ;if drive is in network drive list, test gosub error continue :getnet netw = ItemRemove(1, netw, @TAB) ;delete item if n3DriveStatus("%drive%") == 23 then goto Nvl ;test if drive is Novell resource :MS UNC%d% = w95GetCon("%drive%") ;store UNC name Type = ItemInsert(Num2Char(6), -1, Type, @TAB) ;log drive as "Type 6" continue :Nvl UNC%d% = n3DrivePath("%drive%") ;store UNC name Type = ItemInsert(Num2Char(7), -1, Type, @TAB) ;log drive as "Type 7" Next BoxShut () ;************ Call dialog and disconnect selected drives Call ("Ask_drv.WDL","") ;call disconnect dialog BoxOpen ("Disconnect Drives","Working, Please Wait") for d = 0 to 25 BoxText ("Working, Please Wait ---") chkbox = Num2Char( Char2Num("A") + d) ;returned dialog checkbox variable name if ButtonPushed == 2 then goto all ;test for disconnect or disconnect all if %chkbox% != 1 then continue ;if dialog checkbox not selected, next loop :all drive = StrCat(chkbox, ":" ) TypeI = Char2Num( ItemExtract( d+1, Type, @TAB)) ;get "drive type" integer BoxText ("Working, Please Wait |") Switch TypeI Case 1 ;Unmapped drive, skip Break Case 2 ;local Removable media drive, skip Break Case 3 ;local hard drive, skip Break Case 4 ;local CD-Rom drive, skip Break Case 5 ;RamDisk, skip Break Case 6 ;Win32 Network resource Discon = w95CancelCon("%drive%",@false,@true) ;attempt disconnect if Discon == @FALSE then gosub Fail ;call sub if disconnect failed Break Case 7 ;Novell Netware resource Discon = n3MapDelete("%drive%") ;attempt disconnect if Discon == @FALSE then gosub Fail ;call sub if disconnect failed Break EndSwitch next BoxShut () ;************ Maximize windows which were minimized at start cnt=ItemCount(reopen, @tab) for c = cnt to 1 by -1 current = ItemExtract(c, reopen, @TAB) WinShow ("%current%") next exit ;************ ;*************** SUBROUTINES ;************ :error ;Unidentfied drive logging and message BoxShut () UNC%d% = "UNIDENTIFIED DRIVE" Type = ItemInsert(Num2Char(1), -1, Type, @TAB) ;log unidentified drive Message ("Disconnect Drives","FAILURE - Could not identify Drive %drive%") BoxOpen ("Disconnect Drives","Working, Please Wait ---") return :Fail ;Disconnect failure message BoxShut () Message ("Disconnect Drives","FAILURE - Could not disconnect Drive %drive%") BoxOpen ("Disconnect Drives","Working, Please Wait ---") return
DisconFormat=`WWWDLGED,5.0` DisconCaption=`Disconnect Drives` DisconX=106 DisconY=32 DisconWidth=340 DisconHeight=264 DisconNumControls=31 Discon01=`184,244,64,DEFAULT,PUSHBUTTON,DEFAULT,"DISCONNECT ALL",2` Discon02=`92,244,64,DEFAULT,PUSHBUTTON,DEFAULT,"DISCONNECT",1` Discon03=`6,56,150,DEFAULT,CHECKBOX,A,"A: = %UNC0%",1` Discon04=`6,70,150,DEFAULT,CHECKBOX,B,"B: = %UNC1%",1` Discon05=`6,84,150,DEFAULT,CHECKBOX,C,"C: = %UNC2%",1` Discon06=`6,98,150,DEFAULT,CHECKBOX,D,"D: = %UNC3%",1` Discon07=`6,112,150,DEFAULT,CHECKBOX,E,"E: = %UNC4%",1` Discon08=`6,126,150,DEFAULT,CHECKBOX,F,"F: = %UNC5%",1` Discon09=`6,140,150,DEFAULT,CHECKBOX,G,"G: = %UNC6%",1` Discon10=`6,154,150,DEFAULT,CHECKBOX,H,"H: = %UNC7%",1` Discon11=`6,168,150,DEFAULT,CHECKBOX,I,"I: = %UNC8%",1` Discon12=`6,182,150,DEFAULT,CHECKBOX,J,"J: = %UNC9%",1` Discon13=`6,196,150,DEFAULT,CHECKBOX,K,"K: = %UNC10%",1` Discon14=`6,210,150,DEFAULT,CHECKBOX,L,"L: = %UNC11%",1` Discon15=`6,224,150,DEFAULT,CHECKBOX,M,"M: = %UNC12%",1` Discon16=`184,56,150,DEFAULT,CHECKBOX,N,"N: = %UNC13%",1` Discon17=`184,70,150,DEFAULT,CHECKBOX,O,"O: = %UNC14%",1` Discon18=`184,84,150,DEFAULT,CHECKBOX,P,"P: = %UNC15%",1` Discon19=`184,98,150,DEFAULT,CHECKBOX,Q,"Q: = %UNC16%",1` Discon20=`184,112,150,DEFAULT,CHECKBOX,R,"R: = %UNC17%",1` Discon21=`184,126,150,DEFAULT,CHECKBOX,S,"S: = %UNC18%",1` Discon22=`184,140,150,DEFAULT,CHECKBOX,T,"T: = %UNC19%",1` Discon23=`184,154,150,DEFAULT,CHECKBOX,U,"U: = %UNC20%",1` Discon24=`184,168,150,DEFAULT,CHECKBOX,V,"V: = %UNC21%",1` Discon25=`184,182,150,DEFAULT,CHECKBOX,W,"W: = %UNC22%",1` Discon26=`184,196,150,DEFAULT,CHECKBOX,X,"X: = %UNC23%",1` Discon27=`184,210,150,DEFAULT,CHECKBOX,Y,"Y: = %UNC24%",1` Discon28=`184,224,150,DEFAULT,CHECKBOX,Z,"Z: = %UNC25%",1` Discon29=`104,2,124,DEFAULT,STATICTEXT,DEFAULT,"Select one or more drives then click DISCONNECT."` Discon30=`104,18,124,DEFAULT,STATICTEXT,DEFAULT,"DISCONNECT ALL will delete all network mapping."` Discon31=`104,34,118,DEFAULT,STATICTEXT,DEFAULT,"Note - Only network resources will be unmapped"` ButtonPushed=Dialog("Discon")
Article ID: W13478
Filename: Disconnect Mapped Drives Ex Dialog.txt
File Created: 2001:03:01:13:25:34
Last Updated: 2001:03:01:13:25:34