#cs -------------------------------------------------------------------------------------------------------------------------------------------------------- Nas Connector Version: 2.0 / 03.06.2022 Author: Elias Jakob Icon Art: Peter Heim GUIScrollbars_Ex.au3: Melba23 from Autoit Forum Script Function: Connects NAS Drives to Users connected to the Network via VPN. Details: If Config.ini doesn't exist a Setup Window is launched If the Button "Festplatten auslesen" is pressed the output of net use is written to the "path" file Every Disk that exists gets written to the config.ini If Config.ini existes a Connection Window is launched If the Button "Verbinden" is pressed all available Drives get connected If the Button "Einstellungen" is pressed the Settings Window gets visible "Reset" deletes the config and saveddrives files and restarts the App In the Settings Window the desired Drives can be selected in the scrollable Window and with the press of "Verbinden" the saveddrives.ini gets rewritten #ce -------------------------------------------------------------------------------------------------------------------------------------------------------- #Region Requirements #include "GUIScrollbars_Ex.au3" #include #include #include #include #include #include #include #include #include #include #EndRegion Requirements #Region GUI If Not FileExists("config.ini") then $GUI_Outer_Window = GUICreate("Outer_Window", 470, 220, Default, Default, $WS_POPUP) GUISetBkColor(0x225588) $GUI_Inner_Window = GUICreate("Inner_Window", 450, 200, 12, 12, $WS_POPUP, $WS_EX_MDICHILD, $GUI_Outer_Window) GUISetBkColor(0xfffffff) Local $Label_1 = GUICtrlCreateLabel("NAS Connector", 10, 10, 250, 50) GUICtrlSetFont($Label_1, 30, 0, 0, "Calibri") GUICtrlSetColor($Label_1, 0x225588) GUICtrlSetBkColor($Label_1, 0xffffff) Local $Label_2 = GUICtrlCreateLabel("©Elias Jakob", 260, 35, 100, 20) GUICtrlSetFont($Label_2, 10, 0, 0, "Calibri") GUICtrlSetColor($Label_2, 0x225588) GUICtrlSetBkColor($Label_2, 0xffffff) Local $Button_1 = GUICtrlCreateButton("X", 390,10,50,50) GUICtrlSetFont($Button_1, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_1, 0x225588) GUICtrlSetBkColor($Button_1, 0xffffff) Local $Button_Focus = GUICtrlCreateButton("", -100,-100,1,1) GUICtrlSetState($Button_Focus, $GUI_FOCUS) GUICtrlSetFont($Button_Focus, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_Focus, 0x225588) GUICtrlSetBkColor($Button_Focus, 0xffffff) Local $Button_2 = GUICtrlCreateButton("Festplatten auslesen", 10,90,250,50) GUICtrlSetFont($Button_2, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_2, 0x225588) GUICtrlSetBkColor($Button_2, 0xffffff) Local $Button_3 = GUICtrlCreateButton("Neustart", 10,140,250,50) GUICtrlSetFont($Button_3, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_3, 0x225588) GUICtrlSetBkColor($Button_3, 0xffffff) Local $Icon = GUICtrlCreatePic("Icon.jpg", 320, 90, 100, 100) GUISetState(@SW_SHOW, $GUI_Outer_Window) GUISetState(@SW_SHOW, $GUI_Inner_Window) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 ExitLoop Case $Button_2 Detect_Drives() Case $Button_3 ShellExecute("Nas Connector 2.0.exe") Exit ShellExecute("Nas Connector 2.0.exe") EndSwitch WEnd ElseIf FileExists("config.ini") then ;--------------------------------------------------------------------------------------------------------------- $GUI_Outer_Window = GUICreate("Outer_Window", 470, 220, Default, Default, $WS_POPUP) GUISetBkColor(0x225588) ;--------------------------------------------------------------------------------------------------------------- $GUI_Inner_Window = GUICreate("Inner_Window", 450, 200, 12, 12, $WS_POPUP, $WS_EX_MDICHILD, $GUI_Outer_Window) GUISetBkColor(0xfffffff) Local $Label_1 = GUICtrlCreateLabel("NAS Connector", 10, 10, 250, 50) GUICtrlSetFont($Label_1, 30, 0, 0, "Calibri") GUICtrlSetColor($Label_1, 0x225588) GUICtrlSetBkColor($Label_1, 0xffffff) Local $Label_2 = GUICtrlCreateLabel("©Elias Jakob", 260, 35, 100, 20) GUICtrlSetFont($Label_2, 10, 0, 0, "Calibri") GUICtrlSetColor($Label_2, 0x225588) GUICtrlSetBkColor($Label_2, 0xffffff) Local $Button_1 = GUICtrlCreateButton("X", 390,10,50,50) GUICtrlSetFont($Button_1, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_1, 0x225588) GUICtrlSetBkColor($Button_1, 0xffffff) Local $Button_Focus = GUICtrlCreateButton("", -100,-100,1,1) GUICtrlSetState($Button_Focus, $GUI_FOCUS) GUICtrlSetFont($Button_Focus, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_Focus, 0x225588) GUICtrlSetBkColor($Button_Focus, 0xffffff) Local $Button_2 = GUICtrlCreateButton("Verbinden", 10,90,250,50) GUICtrlSetFont($Button_2, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_2, 0x225588) GUICtrlSetBkColor($Button_2, 0xffffff) Local $Button_3 = GUICtrlCreateButton("Einstellungen", 10,140,250,50) GUICtrlSetFont($Button_3, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_3, 0x225588) GUICtrlSetBkColor($Button_3, 0xffffff) Local $Icon = GUICtrlCreatePic("Icon.jpg", 320, 90, 100, 100) ;--------------------------------------------------------------------------------------------------------------- $GUI_Outer_Window_2 = GUICreate("Outer_Window_2", 920, 420, Default, Default, $WS_POPUP) GUISetBkColor(0x225588) ;--------------------------------------------------------------------------------------------------------------- $GUI_Settings = GUICreate("Settings", 900, 400, 12, 12 , $WS_POPUP, $WS_EX_MDICHILD, $GUI_Outer_Window_2) GUISetBkColor(0xfffffff) Local $Label_3 = GUICtrlCreateLabel("NAS Connector", 10, 10, 250, 50) GUICtrlSetFont($Label_3, 30, 0, 0, "Calibri") GUICtrlSetColor($Label_3, 0x225588) GUICtrlSetBkColor($Label_3, 0xffffff) Local $Label_4 = GUICtrlCreateLabel("©Elias Jakob", 260, 35, 100, 20) GUICtrlSetFont($Label_4, 10, 0, 0, "Calibri") GUICtrlSetColor($Label_4, 0x225588) GUICtrlSetBkColor($Label_4, 0xffffff) Local $Button_4 = GUICtrlCreateButton("X", 840,10,50,50) GUICtrlSetFont($Button_4, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_4, 0x225588) GUICtrlSetBkColor($Button_4, 0xffffff) Local $Button_Focus_2 = GUICtrlCreateButton("", -100,-100,1,1) GUICtrlSetState($Button_Focus_2, $GUI_FOCUS) GUICtrlSetFont($Button_Focus_2, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_Focus_2, 0x225588) GUICtrlSetBkColor($Button_Focus_2, 0xffffff) Local $Button_5 = GUICtrlCreateButton("Verbinden", 100,340,250,50) GUICtrlSetFont($Button_5, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_5, 0x225588) GUICtrlSetBkColor($Button_5, 0xffffff) Local $Button_6 = GUICtrlCreateButton("Reset", 550,340,250,50) GUICtrlSetFont($Button_6, 20, 0, 0, "Calibri") GUICtrlSetColor($Button_6, 0x225588) GUICtrlSetBkColor($Button_6, 0xffffff) ;--------------------------------------------------------------------------------------------------------------- $GUI_Settings_Scrollable = GUICreate("Settings_Scrollable", 300, 200, 350, 100, $WS_POPUP, $WS_EX_MDICHILD, $GUI_Settings) GUISetBkColor(0xfffffff) _GUIScrollbars_Generate($GUI_Settings_Scrollable, 0, 1000) Local $Drives_Array = IniReadSectionNames("config.ini") For $i = 1 to $Drives_Array[0] $Drive = $Drives_Array[$i] $Name = IniRead("config.ini", $Drives_Array[$i], "Name", "Default Value") $Drives_Array[$i] = GUICtrlCreateCheckbox($Name, 0, ($i * 35), 140, 30) GUICtrlSetFont($Drives_Array[$i], 20, 0, 0, "Calibri") GUICtrlSetColor($Drives_Array[$i], 0x225588) If IniRead("saveddrives.ini", "Drives", $Drive, "Default Value") == "Connect" Then GUICtrlSetState($Drives_Array[$i], $GUI_CHECKED) EndIf ConsoleWrite($Drives_Array[$i]) Next GUISetState(@SW_SHOW, $GUI_Outer_Window) GUISetState(@SW_SHOW, $GUI_Inner_Window) GUISetState(@SW_HIDE, $GUI_Outer_Window_2) GUISetState(@SW_HIDE, $GUI_Settings) GUISetState(@SW_HIDE, $GUI_Settings_Scrollable) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 ExitLoop Case $Button_2 Connect_Drives() $Splash = SplashTextOn("", "Netzlaufwerke werden verbunden...", 300, 40, Default, Default) Sleep(5000) SplashOff() ExitLoop Case $Button_3 GUISetState(@SW_HIDE, $GUI_Outer_Window) GUISetState(@SW_HIDE, $GUI_Inner_Window) GUISetState(@SW_SHOW, $GUI_Outer_Window_2) GUISetState(@SW_SHOW, $GUI_Settings) GUISetState(@SW_SHOW, $GUI_Settings_Scrollable) Case $Button_4 ExitLoop Case $Button_5 Save_Drives() Connect_Drives() $Splash = SplashTextOn("", "saveddrives.ini wird neu geschrieben und Netzlaufwerke werden verbunden...", 300, 40, Default, Default) Sleep(5000) SplashOff() ExitLoop Case $Button_6 FileDelete("config.ini") FileDelete("saveddrives.ini") ShellExecute("Nas Connector 2.0.exe") Exit ShellExecute("Nas Connector 2.0.exe") EndSwitch WEnd EndIf #EndRegion GUI #Region Detect_Drives Func Detect_Drives() _FileCreate("config.ini") _FileCreate("path.ini") FileWriteLine("path.ini", "[Path]") _FileCreate("saveddrives.ini") FileWriteLine("saveddrives.ini", "[Drives]") RunWait(@Comspec & " /c net use | find /i ""\\"" >" & "netuse.log","",@SW_HIDE) $file = FileOpen("netuse.log",0) $idx = 0 While 1 Local $drivearray[25][2] $line = FileReadLine($file) If @error = -1 Then ExitLoop $Driveletter = StringMid($line,StringInStr($line,":") - 1,2) $Drivepath_1 = StringMid($line,StringInStr($line,"\\")) $idx = $idx + 1 $drivearray[0][0] = $idx $drivearray[$idx][0] = $Driveletter $drivearray[$idx][1] = $Drivepath_1 $iPos = StringInStr($Drivepath_1, " ") $bar1 = Stringleft($Drivepath_1, $iPos-1) FileWriteLine("path.ini", $Driveletter & "=" & $bar1) Wend FileClose($file) $Alphabet = "A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" $Letters = StringSplit($Alphabet, ",") For $i = 1 to $Letters[0] $Path = IniRead("path.ini", "Path", $Letters[$i] & ":", "Default Value") If $Path <> "Default Value" then $Name_Array = StringSplit($Path, "\") $Name = $Name_Array[UBound($Name_Array)-1] FileWriteLine("config.ini", "[" & $Letters[$i] & ":" &"]") FileWriteLine("config.ini", "Letter=" & $Letters[$i] & ":") FileWriteLine("config.ini", "Path=" & $Path ) FileWriteLine("config.ini", "Name=" & $Name) FileWriteLine("config.ini", Chr(10)) FileWriteLine("saveddrives.ini", $Letters[$i] & ":=Connect") EndIf Next FileDelete("netuse.log") FileDelete("path.ini") EndFunc #EndRegion Detect_Drives #Region Connect_Drives Func Connect_Drives() $Alphabet = "A:,B:,D:,E:,F:,G:,H:,I:,J:,K:,L:,M:,N:,O:,P:,Q:,R:,S:,T:,U:,V:,W:,X:,Y:,Z:" $Letters = StringSplit($Alphabet, ",") For $i = 1 to $Letters[0] $Letter = IniRead("config.ini", $Letters[$i], "Letter", "Default Value") $Path = IniRead("config.ini", $Letters[$i], "Path", "Default Value") $Name = IniRead("config.ini", $Letters[$i], "Name", "Default Value") If IniRead("saveddrives.ini", "Drives", $Letter, "Default Value") == "Connect" Then DriveMapDel($Letter) DriveMapAdd($Letter, $Path) $Shell = ObjCreate("shell.application") $Shell.NameSpace($Letter).Self.Name = $Name EndIf Next EndFunc #EndRegion Connect_Drives #Region Save_Drives Func Save_Drives() FileDelete("saveddrives.ini") _FileCreate("saveddrives.ini") FileWriteLine("saveddrives.ini", "[Drives]") Local $Drives_Array_2 = IniReadSectionNames("config.ini") For $i = 1 to $Drives_Array_2[0] If GUICtrlRead($Drives_Array_2[$i]) = $GUI_CHECKED Then FileWriteLine("saveddrives.ini", $Drives_Array_2[$i] & "=Connect") Else FileWriteLine("saveddrives.ini", $Drives_Array_2[$i] & "=Disconnect") EndIf Next EndFunc #EndRegion Save_Drives