#include #include #include #include #include #include #include #include #include #include Opt("MustDeclareVars", 0) #Region ### START Koda GUI section ### Form=C:\DACHSER\Juliano\Form1.kxf $GUI_Main = GUICreate("Form1", 620, 479, -1200, 400) $btn_OK = GUICtrlCreateButton("OK", 217, 300, 185, 50, ($BS_DEFPUSHBUTTON)) $btn_Cancel = GUICtrlCreateButton("Cancel", 500, 420, 100, 40) $Combo1 = GUICtrlCreateCombo("DriveLetter", 80, 55, 85, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_TABSTOP)) $input_NetPath = GUICtrlCreateInput("Path", 210, 55, 360, 20) $cb_Persistent = GUICtrlCreateCheckbox("Verbindung bei Anmeldung wiederherstellen", 80, 180, 249, 17) $cb_ExtraCredentials = GUICtrlCreateCheckbox("Verbindung mit anderen Anmeldeinformationen", 80, 210, 256, 17) $Label1 = GUICtrlCreateLabel("Netzlaufwerk verbinden!", 20, 5, 250, 20) GUICtrlSetFont($Label1, 12, 400, 0, "MS Sans Serif") # Secondary GUI for Extracredentials $GUI_Secondary = GUICreate("Form2", 417, 319, -1800, 490) $btn_OK_Secondary = GUICtrlCreateButton("OK", 177, 270, 145, 30, ($BS_DEFPUSHBUTTON)) $btn_Cancel_Secondary = GUICtrlCreateButton("Cancel", 147, 230, 150, 30) $Label2 = GUICtrlCreateLabel("Anmeldeinformationen eingeben!", 20, 5, 250, 20) $Label3 = GUICtrlCreateLabel("Anmeldenamen eingeben!", 17, 105, 250, 20) $input_Username = GUICtrlCreateInput("", 17, 120, 360, 20) $input_Password = GUICtrlCreateInput("", 17, 200, 360, 20, $ES_PASSWORD) $Label4 = GUICtrlCreateLabel("Passwort eingeben!", 17, 180, 250, 20) GUICtrlSetFont($Label2, 12, 400, 0, "MS Sans Serif") #EndRegion ### END Koda GUI section ### $aFreeDriveList = _GetFreeDriveLetters() _ArrayDelete($aFreeDriveList, 0) GUICtrlSetData($Combo1, _ArrayToString($aFreeDriveList), "H:") GUISetState(@SW_SHOW, $GUI_Main) $iReturnExtraCredentials = GUICtrlRead($cb_ExtraCredentials) While 1 $MsgBox = GUIGetMsg() Switch $MsgBox Case $GUI_EVENT_CLOSE Exit Case $btn_Cancel_Secondary Exit Case $btn_Cancel Exit Case $btn_OK $iReturnExtraCredentials = GUICtrlRead($cb_ExtraCredentials) If $iReturnExtraCredentials == 1 Then GUISetState(@SW_SHOW, $GUI_Secondary) Else $input_Username = "" $input_Password = "" _Networkdrive() EndIf Case $btn_OK_Secondary _Networkdrive() EndSwitch WEnd $User = GUICtrlRead($input_Username) $Password = GUICtrlRead($input_Password) Func _Networkdrive() $iPersistent = 0 $iReturnPersistent = GUICtrlRead($cb_Persistent) If $iReturnPersistent == 1 Then $iPersistent = 1 EndIf $sNetpath = GUICtrlRead($input_NetPath) If $iReturnExtraCredentials And $btn_OK_Secondary == 1 Then $sDrive = DriveMapAdd(GUICtrlRead($Combo1), $sNetpath, $iPersistent, $User, $Password) Else $sDrive = DriveMapAdd(GUICtrlRead($Combo1), $sNetpath, $iPersistent) EndIf If $sDrive == 0 Then If @error == 1 Then $Errordefinition = "Unknown Error!" ElseIf @error == 2 Then $Errordefinition = "Access to the remote share was denied!" ElseIf @error == 3 Then $Errordefinition = "The device is already assigned!" ElseIf @error == 4 Then $Errordefinition = "Invalid device name!" ElseIf @error == 5 Then $Errordefinition = "Invalid remote share!" Else $Errordefinition = "Invalid password!" EndIf MsgBox($MB_TOPMOST + $MB_ICONERROR + $MB_OK, "Connect Network Drive", "The network drive could not connect successfully!" & @CRLF & "The Error is: " & $Errordefinition) GUISetState(@SW_ENABLE, $GUI_Main) ;~ ElseIf FileExists($sNetpath) Then ;~ $Errordefinition = "The device is already assigned!" ;~ MsgBox($MB_TOPMOST + $MB_ICONERROR + $MB_OK, "1Connect Network Drive", "The network drive could not connect successfully!" & @CRLF & "The Error is: " & $Errordefinition) ;~ GUISetState(@SW_ENABLE, $GUI_Main) ;~ DriveMapDel( GUICtrlRead($Combo1)) ElseIf $sDrive == 1 Then MsgBox($MB_TOPMOST + $MB_ICONINFORMATION + $MB_OK, "Connect Network Drive", "The Network drive has sucessfully connected!") GUISetState(@SW_ENABLE, $GUI_Main) Exit Else MsgBox($MB_TOPMOST + $MB_ICONERROR + $MB_OK, "Connect Network Drive", "An Unexpected error occured!" & @CRLF & "Please contact the administrator!") GUISetState(@SW_ENABLE, $GUI_Main) Exit EndIf EndFunc ;==>_Networkdrive Func _GetFreeDriveLetters() Dim $aArray[1] For $x = 67 To 90 If DriveStatus(Chr($x) & ':\') = 'INVALID' Then ReDim $aArray[UBound($aArray) + 1] $aArray[UBound($aArray) - 1] = Chr($x) & ':' EndIf Next $aArray[0] = UBound($aArray) - 1 Return ($aArray) EndFunc ;==>_GetFreeDriveLetters