gr1fter Posted November 20, 2009 Share Posted November 20, 2009 Hello I can't seem to figure out how to create a GUI loop with a button that will function as a Home Button (Return to Main Menu). All my buttons work fine but if I do a next button and then try to use a back/home type button my gui gets fubared. can one of you bright minds provide me an example of a simple gui with a next button and then a back button that returns to the previous screen that works in a loop? Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2009 Moderators Share Posted November 20, 2009 gr1fter, First, welcome to the AutoIt forums. I am unclear what exactly you are looking for - show us what you have so far. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
playlet Posted November 20, 2009 Share Posted November 20, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
gr1fter Posted November 20, 2009 Author Share Posted November 20, 2009 (edited) Is this what you meant: expandcollapse popup$gui1 = GUICreate ("Main Window", 400, 400, 100, 100) $button1 = GUICtrlCreateButton ("Go to Window1", 20, 20, 200, 30) $button1a = GUICtrlCreateButton ("Go to Window2", 20, 70, 200, 30) GUISetState (@SW_SHOW, $gui1) $gui2 = GUICreate ("Window1", 400, 400) $button2 = GUICtrlCreateButton ("Go to Main Window", 20, 20, 200, 30) $button2a = GUICtrlCreateButton ("Go to Window2", 20, 70, 200, 30) GUISetState (@SW_HIDE, $gui2) $gui3 = GUICreate ("Window2", 400, 400, 500, 500) $button3 = GUICtrlCreateButton ("Go to Main Window", 20, 20, 200, 30) $button3a = GUICtrlCreateButton ("Go to Window1", 20, 70, 200, 30) GUISetState (@SW_HIDE, $gui3) While 1 $msg = GUIGetMsg() Switch $msg Case -3; this is the same as: $GUI_EVENT_CLOSE Exit Case $button1 GUISetState (@SW_HIDE, $gui1) GUISetState (@SW_HIDE, $gui3) GUISetState (@SW_SHOW, $gui2) Case $button1a GUISetState (@SW_HIDE, $gui1) GUISetState (@SW_HIDE, $gui2) GUISetState (@SW_SHOW, $gui3) Case $button2 GUISetState (@SW_HIDE, $gui2) GUISetState (@SW_HIDE, $gui3) GUISetState (@SW_SHOW, $gui1) Case $button2a GUISetState (@SW_HIDE, $gui1) GUISetState (@SW_HIDE, $gui2) GUISetState (@SW_SHOW, $gui3) Case $button3 GUISetState (@SW_HIDE, $gui2) GUISetState (@SW_HIDE, $gui3) GUISetState (@SW_SHOW, $gui1) Case $button3a GUISetState (@SW_HIDE, $gui1) GUISetState (@SW_HIDE, $gui3) GUISetState (@SW_SHOW, $gui2) EndSwitch Sleep(50) WEnd? I think this is what i need, however i want to stay in the same gui. here is my code (be gentle, it is my first one) but when i click status it goes to status, but when i click map drive i want it to return to the state the gui was first opened but then everything gets messed up. expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: ; ; Script Function: ; Net Use GUI for Mapping Drives for WinPE #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <Array.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> ;Variables GLOBAL $example2 GLOBAL $password GLOBAL $username GLOBAL $View GLOBAL $progress ;GUI Interface GUICreate("Map Drive", 320, 240, -1, -1, -1) GUISetState(@SW_SHOW) GUISetIcon ("d:\network.ico") GUISetBkColor(0xFFFFFF) $Pic1 = GUICtrlCreatePic("d:\bg.bmp",-1,-1,"","") GUICtrlSetState ($Pic1,$GUI_DISABLE) $mapbutton = GUICtrlCreateButton("Map Drive", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $status = GUICtrlCreateButton("Status", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $exit = GUICtrlCreateButton("Exit", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $label1 = GUICtrlCreateLabel ("Folder:",165, 108, 125, 20) $example = GUICtrlCreateLabel ("Example: \\server\share",165, 152, 125, 20) $dir = GUICtrlCreateLabel ("Specify the folder that you want to connect to:",125, 68, 190, 40) $server = GUICtrlCreateInput ("",165, 125, 125, 20,$ES_AUTOHSCROLL) $connect = GUICtrlCreateButton("Ok", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $remdrive = GuiCtrlCreateButton ("Disconnect Drive", 210, 210, 95, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($exit,$GUI_HIDE) ; Maps Drive to Network FUNC mapdrive() $progress2 = GUICtrlCreateProgress(100, 185, 190, 6) $folder = GUICtrlRead ($server) DriveMapAdd("R:",$folder,0) If @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then passprompt() ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") GUICtrlSetState($progress2,$GUI_HIDE) Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else GuiCtrlSetData($progress2, 10) Sleep (250) GuiCtrlSetData($progress2, 20) Sleep (250) GuiCtrlSetData($progress2, 40) Sleep (250) GuiCtrlSetData($progress2, 60) Sleep (250) GuiCtrlSetData($progress2, 80) Sleep (250) GuiCtrlSetData($progress2, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $folder) GUICtrlSetState($progress2,$GUI_HIDE) EndIf EndFunc ;Prompts for Username and Password Authentication to share Func passprompt() GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($exit,$GUI_SHOW) GUICtrlSetState($connect,$GUI_SHOW) $dir2 = GUICtrlCreateLabel ("Please enter network username and password:",110, 56, 200, 40) $label2 = GUICtrlCreateLabel ("Username:",165, 82, 125, 20) $label3 = GUICtrlCreateLabel ("Password:",165, 132, 125, 20) $example2 = GUICtrlCreateLabel ("Example: ",165, 177, 140, 20) $password = GUICtrlCreateInput ("",165, 150, 125, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $username = GUICtrlCreateInput ("",165, 100, 125, 20,$ES_AUTOHSCROLL) EndFunc ; Maps Drive to Network With Username & Password FUNC mapdriveauth() GUICtrlSetState($example2,$GUI_HIDE) $progress = GUICtrlCreateProgress(100, 185, 190, 6) $user = GUICtrlRead ($username) $passwd = GUICtrlRead ($password) $serv = GUICtrlRead ($server) $map = DriveMapAdd("R:",$serv,0,$user,$passwd) If @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then MsgBox (16, "Error", "Access to the remote share was denied") ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else GuiCtrlSetData($progress, 10) Sleep (250) GuiCtrlSetData($progress, 20) Sleep (250) GuiCtrlSetData($progress, 40) Sleep (250) GuiCtrlSetData($progress, 60) Sleep (250) GuiCtrlSetData($progress, 80) Sleep (250) GuiCtrlSetData($progress, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $serv) GUICtrlSetState($progress,$GUI_HIDE) EndIf EndFunc ;Creates a List View of ALL currently mapped drives Func status() GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($Pic1,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_SHOW) $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $allDrives = DriveGetDrive( "network" ) For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndFunc $mapdrive = GuiCtrlCreateButton ("Map Drive", 125, 210, 75, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) GUICtrlSetState($mapdrive,$GUI_HIDE) ;Disconnects Mapped Drive Choosen From List View Func remdrive() $dropdrive = GUICtrlRead(GUICtrlRead($View, 1)) $splitDropLine = StringSplit ( $dropdrive, "|") $dropDriveLtr = StringTrimLeft($splitDropLine[1], 1) $dropDriveLtr = StringTrimright($dropDriveLtr, 1) DriveMapDel ($dropDriveLtr) if @error = "1" Then msgbox (16, "Error", "Disconnection of " & $dropDriveLtr & " unsuccessful") Else _GUICtrlListView_DeleteAllItems($View) $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $allDrives = DriveGetDrive( "network" ) For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndIf EndFunc ; Function Loop for Drive Map While 1 Local $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $exit Exit Case $msg = $mapbutton mapdrive() Case $msg = $connect mapdriveauth() Case $msg = $status status() GUICtrlSetState($mapdrive,$GUI_SHOW) Case $msg = $remdrive remdrive() Case $msg = $mapdrive GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($Pic1,$GUI_SHOW) GUICtrlSetState($mapbutton,$GUI_SHOW) GUICtrlSetState($status,$GUI_SHOW) GUICtrlSetState($label1,$GUI_SHOW) GUICtrlSetState($example,$GUI_SHOW) GUICtrlSetState($dir,$GUI_SHOW) GUICtrlSetState($server,$GUI_SHOW) EndSelect WEnd Edited November 20, 2009 by gr1fter Link to comment Share on other sites More sharing options...
playlet Posted November 21, 2009 Share Posted November 21, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
gr1fter Posted November 21, 2009 Author Share Posted November 21, 2009 A few suggestions: First of all, don't make all of those spaces between lines. This is very frustrating to look at. I removed them for youSecond, you had a button outside gui creation area (somewhere between functions)Third, put Guisetstate function at the end (when you created all the buttons, labels...; and before while loop)Fourth, put while loop directly after Guisetstate (just a suggestion for better understanding) and all the functions at the end (so you don't get confused where is what)And last, try this (I think the only problem was that button that got lost between functions): expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <Array.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> ;Variables GLOBAL $example2 GLOBAL $password GLOBAL $username GLOBAL $View GLOBAL $progress ;GUI Interface GUICreate("Map Drive", 320, 240, -1, -1, -1) GUISetIcon ("d:\network.ico") GUISetBkColor(0xFFFFFF) $Pic1 = GUICtrlCreatePic("d:\bg.bmp",-1,-1,"","") GUICtrlSetState ($Pic1,$GUI_DISABLE) $mapbutton = GUICtrlCreateButton("Map Drive", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $status = GUICtrlCreateButton("Status", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $exit = GUICtrlCreateButton("Exit", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $label1 = GUICtrlCreateLabel ("Folder:",165, 108, 125, 20) $example = GUICtrlCreateLabel ("Example: \\server\share",165, 152, 125, 20) $dir = GUICtrlCreateLabel ("Specify the folder that you want to connect to:",125, 68, 190, 40) $server = GUICtrlCreateInput ("",165, 125, 125, 20,$ES_AUTOHSCROLL) $connect = GUICtrlCreateButton("Ok", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $remdrive = GuiCtrlCreateButton ("Disconnect Drive", 210, 210, 95, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($exit,$GUI_HIDE) $mapdrive = GuiCtrlCreateButton ("Map Drive2", 125, 210, 75, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) GUICtrlSetState($mapdrive,$GUI_HIDE) GUISetState(@SW_SHOW) ; Function Loop for Drive Map While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $exit Exit Case $msg = $mapbutton mapdrive() Case $msg = $connect mapdriveauth() Case $msg = $status status() GUICtrlSetState($mapdrive,$GUI_SHOW) Case $msg = $remdrive remdrive() Case $msg = $mapdrive GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($Pic1,$GUI_SHOW) GUICtrlSetState($mapbutton,$GUI_SHOW) GUICtrlSetState($status,$GUI_SHOW) GUICtrlSetState($label1,$GUI_SHOW) GUICtrlSetState($example,$GUI_SHOW) GUICtrlSetState($dir,$GUI_SHOW) GUICtrlSetState($server,$GUI_SHOW) EndSelect WEnd ; Maps Drive to Network FUNC mapdrive() $progress2 = GUICtrlCreateProgress(100, 185, 190, 6) $folder = GUICtrlRead ($server) DriveMapAdd("R:",$folder,0) If @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then passprompt() ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") GUICtrlSetState($progress2,$GUI_HIDE) Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else GuiCtrlSetData($progress2, 10) Sleep (250) GuiCtrlSetData($progress2, 20) Sleep (250) GuiCtrlSetData($progress2, 40) Sleep (250) GuiCtrlSetData($progress2, 60) Sleep (250) GuiCtrlSetData($progress2, 80) Sleep (250) GuiCtrlSetData($progress2, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $folder) GUICtrlSetState($progress2,$GUI_HIDE) EndIf EndFunc ;Prompts for Username and Password Authentication to share Func passprompt() GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($exit,$GUI_SHOW) GUICtrlSetState($connect,$GUI_SHOW) $dir2 = GUICtrlCreateLabel ("Please enter network username and password:",110, 56, 200, 40) $label2 = GUICtrlCreateLabel ("Username:",165, 82, 125, 20) $label3 = GUICtrlCreateLabel ("Password:",165, 132, 125, 20) $example2 = GUICtrlCreateLabel ("Example: ",165, 177, 140, 20) $password = GUICtrlCreateInput ("",165, 150, 125, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $username = GUICtrlCreateInput ("",165, 100, 125, 20,$ES_AUTOHSCROLL) EndFunc ; Maps Drive to Network With Username & Password FUNC mapdriveauth() GUICtrlSetState($example2,$GUI_HIDE) $progress = GUICtrlCreateProgress(100, 185, 190, 6) $user = GUICtrlRead ($username) $passwd = GUICtrlRead ($password) $serv = GUICtrlRead ($server) $map = DriveMapAdd("R:",$serv,0,$user,$passwd) If @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then MsgBox (16, "Error", "Access to the remote share was denied") ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else GuiCtrlSetData($progress, 10) Sleep (250) GuiCtrlSetData($progress, 20) Sleep (250) GuiCtrlSetData($progress, 40) Sleep (250) GuiCtrlSetData($progress, 60) Sleep (250) GuiCtrlSetData($progress, 80) Sleep (250) GuiCtrlSetData($progress, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $serv) GUICtrlSetState($progress,$GUI_HIDE) EndIf EndFunc ;Creates a List View of ALL currently mapped drives Func status() GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($Pic1,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_SHOW) $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $allDrives = DriveGetDrive("all") For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndFunc ;Disconnects Mapped Drive Chosen From List View Func remdrive() $dropdrive = GUICtrlRead(GUICtrlRead($View, 1)) $splitDropLine = StringSplit ( $dropdrive, "|") $dropDriveLtr = StringTrimLeft($splitDropLine[1], 1) $dropDriveLtr = StringTrimright($dropDriveLtr, 1) DriveMapDel ($dropDriveLtr) If @error = "1" Then msgbox (16, "Error", "Disconnection of " & $dropDriveLtr & " unsuccessful") Else _GUICtrlListView_DeleteAllItems($View) $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $allDrives = DriveGetDrive( "network" ) For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndIf EndFunc Thanks for the response, I will check this out later and let you know. Sorry for the code, I didn't have spaces in my original code but i copied the code from a linux machine and when i pasted into firefox that is the format that went in. I'll do it from windows next time. Link to comment Share on other sites More sharing options...
gr1fter Posted November 25, 2009 Author Share Posted November 25, 2009 Thanks for the response, I will check this out later and let you know. Sorry for the code, I didn't have spaces in my original code but i copied the code from a linux machine and when i pasted into firefox that is the format that went in. I'll do it from windows next time.Thanks for the help guys, I took some of advice from everyone and was able to figure it. Really appreciate it. Link to comment Share on other sites More sharing options...
gr1fter Posted November 25, 2009 Author Share Posted November 25, 2009 (edited) My next task is to figure out how I can add a updownbutton? I think that is what i want. but basically with my little tool i can only map to R: drive because i hard coded it in. I would like to be able to choose the letter to map with updown or drop down menu. Think you guys can push me in the right direction? Here is my current code... expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: ; ; Script Function: ; Net Use GUI for Mapping Drives for WinPE #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <Array.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> ;main menu variables GLOBAL $Pic1 GLOBAL $mapbutton GLOBAL $status GLOBAL $label1 GLOBAL $example GLOBAL $dir GLOBAL $server ;username & password variables GLOBAL $exit GLOBAL $connect GLOBAL $example2 GLOBAL $password GLOBAL $username GLOBAL $dir2 GLOBAL $label2 GLOBAL $label3 ;status variables GLOBAL $View GLOBAL $remdrive GLOBAL $mapdrive ;progress variables GLOBAL $progress GLOBAL $progress2 ;GUI Interface GUICreate("Map Drive", 320, 240, -1, -1, -1) GUISetState(@SW_SHOW) GUISetIcon ("d:\network.ico") GUISetBkColor(0xFFFFFF) ;Main Menu $Pic1 = GUICtrlCreatePic("d:\bg.bmp",-1,-1,"","") $mapbutton = GUICtrlCreateButton("Map Drive", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $status = GUICtrlCreateButton("Status", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $label1 = GUICtrlCreateLabel ("Folder:",165, 108, 125, 20) $example = GUICtrlCreateLabel ("Example: \\server\share",165, 152, 125, 20) $dir = GUICtrlCreateLabel ("Specify the folder that you want to connect to:",125, 68, 190, 40) $server = GUICtrlCreateInput ("",165, 125, 125, 20,$ES_AUTOHSCROLL) ;Status View $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $remdrive = GuiCtrlCreateButton ("Disconnect Drive", 210, 210, 95, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $mapdrive = GuiCtrlCreateButton ("Map Drive", 125, 210, 75, 20,$BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) ;Username & Password View $dir2 = GUICtrlCreateLabel ("Please enter network username and password:",110, 56, 200, 40) $label2 = GUICtrlCreateLabel ("Username:",165, 82, 125, 20) $label3 = GUICtrlCreateLabel ("Password:",165, 132, 125, 20) $example2 = GUICtrlCreateLabel ("Example: jd123456",165, 177, 140, 20) $password = GUICtrlCreateInput ("",165, 150, 125, 20, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $username = GUICtrlCreateInput ("",165, 100, 125, 20,$ES_AUTOHSCROLL) $exit = GUICtrlCreateButton("Exit", 240, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) $connect = GUICtrlCreateButton("Ok", 155, 205, 70, 25, $BS_DEFPUSHBUTTON,$WS_EX_TOPMOST) GUICtrlSetState ($Pic1,$GUI_DISABLE) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($example2,$GUI_HIDE) GUICtrlSetState($password,$GUI_HIDE) GUICtrlSetState($username,$GUI_HIDE) GUICtrlSetState($dir2,$GUI_HIDE) GUICtrlSetState($label2,$GUI_HIDE) GUICtrlSetState($label3,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) ; Function Loop for Drive Map While 1 Global $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $mapbutton mapdrive() GUICtrlSetState($Pic1,$GUI_SHOW) GUICtrlSetState($mapbutton,$GUI_SHOW) GUICtrlSetState($status,$GUI_SHOW) GUICtrlSetState($label1,$GUI_SHOW) GUICtrlSetState($example,$GUI_SHOW) GUICtrlSetState($dir,$GUI_SHOW) GUICtrlSetState($server,$GUI_SHOW) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($example2,$GUI_HIDE) GUICtrlSetState($password,$GUI_HIDE) GUICtrlSetState($username,$GUI_HIDE) GUICtrlSetState($dir2,$GUI_HIDE) GUICtrlSetState($label2,$GUI_HIDE) GUICtrlSetState($label3,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) Case $status status() GUICtrlSetState($Pic1,$GUI_HIDE) GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($example2,$GUI_HIDE) GUICtrlSetState($password,$GUI_HIDE) GUICtrlSetState($username,$GUI_HIDE) GUICtrlSetState($dir2,$GUI_HIDE) GUICtrlSetState($label2,$GUI_HIDE) GUICtrlSetState($label3,$GUI_HIDE) GUICtrlSetState($View,$GUI_SHOW) GUICtrlSetState($remdrive,$GUI_SHOW) GUICtrlSetState($mapdrive,$GUI_SHOW) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) Case $remdrive remdrive() GUICtrlSetState($Pic1,$GUI_HIDE) GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($example2,$GUI_HIDE) GUICtrlSetState($password,$GUI_HIDE) GUICtrlSetState($username,$GUI_HIDE) GUICtrlSetState($dir2,$GUI_HIDE) GUICtrlSetState($label2,$GUI_HIDE) GUICtrlSetState($label3,$GUI_HIDE) GUICtrlSetState($View,$GUI_SHOW) GUICtrlSetState($remdrive,$GUI_SHOW) GUICtrlSetState($mapdrive,$GUI_SHOW) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) Case $mapdrive GUICtrlSetState($Pic1,$GUI_SHOW) GUICtrlSetState($mapbutton,$GUI_SHOW) GUICtrlSetState($status,$GUI_SHOW) GUICtrlSetState($label1,$GUI_SHOW) GUICtrlSetState($example,$GUI_SHOW) GUICtrlSetState($dir,$GUI_SHOW) GUICtrlSetState($server,$GUI_SHOW) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($connect,$GUI_HIDE) GUICtrlSetState($example2,$GUI_HIDE) GUICtrlSetState($password,$GUI_HIDE) GUICtrlSetState($username,$GUI_HIDE) GUICtrlSetState($dir2,$GUI_HIDE) GUICtrlSetState($label2,$GUI_HIDE) GUICtrlSetState($label3,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) EndSwitch WEnd ;Prompts for Username and Password Authentication to share Func passprompt() GUICtrlSetState($mapbutton,$GUI_HIDE) GUICtrlSetState($status,$GUI_HIDE) GUICtrlSetState($server,$GUI_HIDE) GUICtrlSetState($example,$GUI_HIDE) GUICtrlSetState($label1,$GUI_HIDE) GUICtrlSetState($dir,$GUI_HIDE) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($progress2,$GUI_HIDE) GUICtrlSetState($remdrive,$GUI_HIDE) GUICtrlSetState($mapdrive,$GUI_HIDE) GUICtrlSetState($View,$GUI_HIDE) GUICtrlSetState($exit,$GUI_SHOW) GUICtrlSetState($connect,$GUI_SHOW) GUICtrlSetState($dir2,$GUI_SHOW) GUICtrlSetState($label2,$GUI_SHOW) GUICtrlSetState($label3,$GUI_SHOW) GUICtrlSetState($example2,$GUI_SHOW) GUICtrlSetState($password,$GUI_SHOW) GUICtrlSetState($username,$GUI_SHOW) EndFunc ; Maps Drive to Network FUNC mapdrive() $folder = GUICtrlRead ($server) DriveMapAdd("R:",$folder,0) If @error = "1" Then passprompt() While 1 Switch GUIGetMsg () Case $GUI_EVENT_CLOSE Exit Case $exit Exit Case $connect mapdriveauth() ExitLoop EndSwitch WEnd ElseIf @error = "2" Then passprompt() While 1 Switch GUIGetMsg () Case $GUI_EVENT_CLOSE Exit Case $exit Exit Case $connect mapdriveauth() ExitLoop EndSwitch WEnd ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else $progress2 = GUICtrlCreateProgress(100, 185, 190, 6) GuiCtrlSetData($progress2, 10) Sleep (250) GuiCtrlSetData($progress2, 20) Sleep (250) GuiCtrlSetData($progress2, 40) Sleep (250) GuiCtrlSetData($progress2, 60) Sleep (250) GuiCtrlSetData($progress2, 80) Sleep (250) GuiCtrlSetData($progress2, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $folder) GUICtrlSetState($progress2,$GUI_HIDE) EndIf EndFunc ; Maps Drive to Network With Username & Password FUNC mapdriveauth() GUICtrlSetState($example2,$GUI_HIDE) $user = GUICtrlRead ($username) $passwd = GUICtrlRead ($password) $serv = GUICtrlRead ($server) $map = DriveMapAdd("R:",$serv,0,$user,$passwd) If @error = "1" Then MsgBox (16, "Error", "An unknown error occured") ElseIf @error = "2" Then MsgBox (16, "Error", "Access to the remote share was denied") ElseIf @error = "3" Then $disconnect = MsgBox (292, "Error", "The device is already assigned, Disconnect R: " & DriveMapGet("R:")) Select Case $disconnect = 6 DriveMapDel ("R:") MsgBox (64, "Map Drive", "Successfully Disconnected Drive R:") Case $disconnect = 7 EndSelect ElseIf @error = "4" Then MsgBox (16, "Error", "Invalid device name") ElseIf @error = "5" Then MsgBox (16, "Error", "Invalid remote share") ElseIf @error = "6" Then MsgBox (16, "Error", "Invalid password") Else $progress = GUICtrlCreateProgress(100, 185, 190, 6) GuiCtrlSetData($progress, 10) Sleep (250) GuiCtrlSetData($progress, 20) Sleep (250) GuiCtrlSetData($progress, 40) Sleep (250) GuiCtrlSetData($progress, 60) Sleep (250) GuiCtrlSetData($progress, 80) Sleep (250) GuiCtrlSetData($progress, 100) Sleep (500) MsgBox (64, "Map Drive", "R: Drive has been successfully mapped to: " & $serv) GUICtrlSetState($progress,$GUI_HIDE) GUICtrlSetState($exit,$GUI_HIDE) GUICtrlSetState($status,$GUI_SHOW) EndIf EndFunc ;Creates a List View of ALL currently mapped drives Func status() $View = GuiCtrlCreateListView("Drive | Source", "", "", 320, 200) $allDrives = DriveGetDrive( "network" ) If NOT @error Then $allDrives = DriveGetDrive( "network" ) For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndIf EndFunc ;Disconnects Mapped Drive Choosen From List View Func remdrive() $dropdrive = GUICtrlRead(GUICtrlRead($View, 1)) $splitDropLine = StringSplit ( $dropdrive, "|") $dropDriveLtr = StringTrimLeft($splitDropLine[1], 1) $dropDriveLtr = StringTrimright($dropDriveLtr, 1) DriveMapDel ($dropDriveLtr) If @error = "1" Then msgbox (16, "Error", "Disconnection of " & $dropDriveLtr & " unsuccessful") Else EndIf _GUICtrlListView_DeleteAllItems($View) $allDrives = DriveGetDrive( "network" ) If NOT @error Then For $i = 1 to $allDrives[0] $curDriveLtr = $allDrives[$i] $curDrivePath = DriveMapGet($curDriveLtr) GuiCtrlCreateListViewItem( " " & $curDriveLtr & " | " & $curDrivePath & "", $View) Next EndIf EndFunc Edited November 25, 2009 by gr1fter Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now