koons Posted May 3, 2010 Share Posted May 3, 2010 (edited) I am hoping to get some assistance from the experts. I'm not very versed in scripting and what not. Our users do not have administrative rights on their computers and we want to allow them to be able to update a certain program that seems to need updating on a weekly basis. I am trying to make a GUI that lists the downloaded updates we keep on our server and lets them select the update they need and then it runs as the domain admin. I'm not sure how (or even if it's possible) to display the files on our server. And for them to then select one and hit the $UpdateButton and have it run as the admin. Any help would be greatly appreciated. Thanks in advance. Here is what I've managed thus far with the help of Koda. _______________________________________________________________ expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\documents and settings\andrew.mclean\my documents\scripts\idsupdater\idsupdater.kxf $Form1_1 = GUICreate("IDS Updater", 633, 447, 1584, 161) GUISetBkColor(0xA6CAF0) $IDSUpdaterTitle = GUICtrlCreateLabel("IDS Updater 1.0", 179, 24, 275, 49) GUICtrlSetFont(-1, 30, 800, 4, "Garamond") GUICtrlSetColor(-1, 0x000000) $Directions1 = GUICtrlCreateLabel("Please select the update you wish to install from the below list", 85, 104, 463, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Directions2 = GUICtrlCreateLabel(" and hit the Update button.", 217, 136, 203, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUISetState(@SW_SHOW) $AvailableUpdatesList = GUICtrlCreateListView("", 118, 192, 401, 113) GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman") GUICtrlSetCursor (-1, 0) $UpdateButton = GUICtrlCreateButton("Update", 120, 360, 153, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") $CancelButton = GUICtrlCreateButton("Cancel", 440, 360, 81, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CancelButton Exit Case $UpdateButton EndSwitch WEnd Edited May 3, 2010 by koons Link to comment Share on other sites More sharing options...
koons Posted May 3, 2010 Author Share Posted May 3, 2010 After scouring this forum for a couple hours, I've managed to get the file list from the network path to display. Now I just need to figure out how to let the user select one of the files and then click a button to run the selected file as the admin. Here is what I have: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> #include <GuiListView.au3> #Region ### START Koda GUI section ### Form=c:\documents and settings\andrew.mclean\my documents\scripts\idsupdater\idsupdater.kxf $IDSUpdaterForm = GUICreate("IDS Updater", 633, 447, 1584, 161) GUISetBkColor(0xA6CAF0) $IDSUpdaterTitle = GUICtrlCreateLabel("IDS Updater 1.0", 179, 24, 275, 49) GUICtrlSetFont(-1, 30, 800, 4, "Garamond") GUICtrlSetColor(-1, 0x000000) $Directions1 = GUICtrlCreateLabel("Please select the update you wish to install from the below list", 85, 104, 463, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Directions2 = GUICtrlCreateLabel(" and hit the Update button.", 217, 136, 203, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUISetState(@SW_SHOW) $AvailableUpdatesList = GUICtrlCreateListView("", 118, 165, 401, 160) GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman") GUICtrlSetCursor (-1, 0) _GUICtrlListView_AddColumn($AvailableUpdatesList,"Available updates",397) $FileList=_FileListToArray("\\koons.com\share\Applications\IDS","*.exe") If @error=1 Then MsgBox(0,"","No folders found.") Exit EndIf If @error=4 Then MsgBox(0,"","No files found.") Exit EndIf Dim $a_lv_array[$FileList[0]][1] For $i = 1 To $FileList[0] $a_lv_array[$i - 1][0] = $FileList[$i] Next _GUICtrlListView_AddArray($AvailableUpdatesList,$a_lv_array) $UpdateButton = GUICtrlCreateButton("Update", 120, 360, 153, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") $CancelButton = GUICtrlCreateButton("Cancel", 440, 360, 81, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") GUISetState() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CancelButton Exit Case $UpdateButton EndSwitch WEnd Link to comment Share on other sites More sharing options...
koons Posted May 5, 2010 Author Share Posted May 5, 2010 OK. I'm pretty sure I have the syntax to do this, but I'm still looking into how I run the user selected file. In the below script, I am able to open cmd, but I want it to run the selected file from the listview. Would I use GetSelected? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> #include <GuiListView.au3> #Region ### START Koda GUI section ### Form=c:\documents and settings\andrew.mclean\my documents\scripts\idsupdater\idsupdater.kxf $IDSUpdaterForm = GUICreate("IDS Updater", 633, 447, 1584, 161) GUISetBkColor(0xA6CAF0) $IDSUpdaterTitle = GUICtrlCreateLabel("IDS Updater 1.0", 179, 24, 275, 49) GUICtrlSetFont(-1, 30, 800, 4, "Garamond") GUICtrlSetColor(-1, 0x000000) $Directions1 = GUICtrlCreateLabel("Please select the update you wish to install from the below list", 85, 104, 463, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Directions2 = GUICtrlCreateLabel(" and hit the Update button.", 217, 136, 203, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUISetState(@SW_SHOW) $AvailableUpdatesList = GUICtrlCreateListView("", 118, 165, 401, 160) GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman") GUICtrlSetCursor (-1, 0) _GUICtrlListView_AddColumn($AvailableUpdatesList,"Available updates",397) $FileList=_FileListToArray("\\koons.com\share\Applications\IDS","*.exe") If @error=1 Then MsgBox(0,"","No folders found.") Exit EndIf If @error=4 Then MsgBox(0,"","No files found.") Exit EndIf Dim $a_lv_array[$FileList[0]][1] For $i = 1 To $FileList[0] $a_lv_array[$i - 1][0] = $FileList[$i] Next _GUICtrlListView_AddArray($AvailableUpdatesList,$a_lv_array) $UpdateButton = GUICtrlCreateButton("Update", 120, 360, 153, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") $CancelButton = GUICtrlCreateButton("Cancel", 440, 360, 81, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") GUISetState() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CancelButton Exit Case $UpdateButton Local $sUserName = "Administrator" Local $sDomainName = "domain.com" Local $sPassword = "secret" If Not IsAdmin() Then RunAs($sUserName,$sDomainName,$sPassword,0,"c:\windows\system32\cmd.exe") Else MsgBox(0,"Silly goose.","You're an admin. You don't need to run this.") EndIf EndSwitch WEnd Link to comment Share on other sites More sharing options...
evilertoaster Posted May 5, 2010 Share Posted May 5, 2010 _GUICtrlListView_GetItemText($AvailableUpdatesList,number(_GUICtrlListView_GetSelectedIndices($AvailableUpdatesList))) will get you the selected text. You'll have to append that to the directory path to get the full file path. Link to comment Share on other sites More sharing options...
koons Posted May 6, 2010 Author Share Posted May 6, 2010 Thanks toaster, that helped a lot. I got it working perfectly. The user runs the script and it opens a GUI that lists all the available updates we have on our server. They then choose the update they need and it runs it off the server as the administrator. I also set a delay for my GUI window so it doesn't close immediately, as it takes a few seconds for the file on the server to copy over the network before it begins the install. Below is my final script. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> #include <GuiListView.au3> #Region ### START Koda GUI section ### $IDSUpdaterForm = GUICreate("IDS Updater", 633, 447, 1584, 161) GUISetBkColor(0xA6CAF0) $IDSUpdaterTitle = GUICtrlCreateLabel("IDS Updater 1.0", 179, 24, 275, 49) GUICtrlSetFont(-1, 30, 800, 4, "Garamond") GUICtrlSetColor(-1, 0x000000) $Directions1 = GUICtrlCreateLabel("Please select the update you wish to install from the below list", 85, 104, 463, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Directions2 = GUICtrlCreateLabel(" and hit the Update button.", 217, 136, 203, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") GUISetState(@SW_SHOW) $AvailableUpdatesList = GUICtrlCreateListView("", 118, 165, 401, 160) GUICtrlSetFont(-1, 10, 400, 0, "Times New Roman") GUICtrlSetCursor (-1, 0) _GUICtrlListView_AddColumn($AvailableUpdatesList,"Available updates",397) $FileList=_FileListToArray("\\domain.com\share\Applications\IDS","*.exe") If @error=1 Then MsgBox(0,"","No folders found.") Exit EndIf If @error=4 Then MsgBox(0,"","No files found.") Exit EndIf Dim $a_lv_array[$FileList[0]][1] For $i = 1 To $FileList[0] $a_lv_array[$i - 1][0] = $FileList[$i] Next _GUICtrlListView_AddArray($AvailableUpdatesList,$a_lv_array) $UpdateButton = GUICtrlCreateButton("Update", 120, 360, 153, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") $CancelButton = GUICtrlCreateButton("Cancel", 440, 360, 81, 41, $WS_GROUP) GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman") GUISetState() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() WinMove("IDS Updater","",100,100) Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $CancelButton Exit Case $UpdateButton Local $sUserName = "Administrator" Local $sDomainName = "domain.com" Local $sPassword = "secret" Local $sSelected = _GUICtrlListView_GetItemText($AvailableUpdatesList,number(_GUICtrlListView_GetSelectedIndices($AvailableUpdatesList))) If Not IsAdmin() Then RunAs($sUserName,$sDomainName,$sPassword,0,"\\domain.com\share\Applications\IDS\" & $sSelected) Else MsgBox(0,"Silly goose.","You're an admin. You don't need to run this.") EndIf Sleep(20000) Exit EndSwitch WEnd 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