Merrik Posted June 29, 2011 Share Posted June 29, 2011 (edited) Hi, I could use some help with this script using runas expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <constants.au3> HotKeySet("{enter}", "Click_Func") $widthCell=270 $GUI = GUICreate("Open Remote Control Panel tool", 220,140, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, bitor($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST)); CtrlCreateLabel ("Name: ", 5, 30, $widthCell) Global $DOS, $Message = '' ;; $ES_PASSWORD = 0x0020 $Name = GUICtrlCreateInput ( "", 100, 30, 100, 20) $Pword = GUICtrlCreateInput ("", 100, 60, 100, 20, $ES_PASSWORD) GUICtrlCreateLabel ("User Name: ", 25, 30, $widthCell) GUICtrlCreateLabel ("Password: ", 25, 60, $widthCell) $btn = GUICtrlCreateButton ("Ok", 100, 85, 80, 20) $clickonce = False GUISetState (@SW_SHOW) While 1 $Data = GUIGetMsg() Select Case $Data = $Btn If $clickonce = False then Click_Func() EndIf Case $Data = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Click_Func() $UserName = GuiCtrlRead($Name) If NOT $UserName Then MsgBox(4096, "Error", "Please enter your name.",0,$GUI) $clickonce = False Else $Command = "rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl" $launch = RunWait(@ComSpec & " /C " & $Command, "", @SW_HIDE) $UserName = GuiCtrlRead($Name) $Password1 = GuiCtrlRead($Pword) RunAs($UserName, @ComputerName, $Password1, 0, $launch, @SystemDir) If @error Then MsgBox(0,"Failed", "Failed to open Add\Remove Programs") EndIf EndFunc Edited June 29, 2011 by Merrik Link to comment Share on other sites More sharing options...
Developers Jos Posted June 29, 2011 Developers Share Posted June 29, 2011 .. You are trying to Shell the returncode of RunWait() with RunAs() ? Why are you doing RunWait first? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
sleepydvdr Posted June 29, 2011 Share Posted June 29, 2011 This should work better: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <constants.au3> HotKeySet("{enter}", "Click_Func") $widthCell=270 $GUI = GUICreate("Open Remote Control Panel tool", 220,140, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, bitor($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST)); CtrlCreateLabel ("Name: ", 5, 30, $widthCell) Global $DOS, $Message = '' ;; $ES_PASSWORD = 0x0020 $Name = GUICtrlCreateInput ( "", 100, 30, 100, 20) $Pword = GUICtrlCreateInput ("", 100, 60, 100, 20, $ES_PASSWORD) GUICtrlCreateLabel ("User Name: ", 25, 30, $widthCell) GUICtrlCreateLabel ("Password: ", 25, 60, $widthCell) $btn = GUICtrlCreateButton ("Ok", 100, 85, 80, 20) $clickonce = False GUISetState (@SW_SHOW) While 1 $Data = GUIGetMsg() Select Case $Data = $Btn If $clickonce = False then Click_Func() EndIf Case $Data = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Click_Func() $ReadName = GuiCtrlRead($Name) If $ReadName = "" Then ; Fixed this line MsgBox(4096, "Error", "Please enter your name.",0,$GUI) $clickonce = False Else $Command = "control.exe Appwiz.cpl" $UserName = GuiCtrlRead($Name) $Password1 = GuiCtrlRead($Pword) RunAs($UserName, @ComputerName, $Password1, 0, $Command) If @error Then MsgBox(0,"Failed", "Failed to open Add\Remove Programs") EndIf EndFunc #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
Merrik Posted June 29, 2011 Author Share Posted June 29, 2011 Thanks sleepydvdr Link to comment Share on other sites More sharing options...
Merrik Posted June 30, 2011 Author Share Posted June 30, 2011 UPDATE: The script works great on Windows XP, but on Windows 7 I get the message "Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item." I even tried right-clicking the EXE and run as administrator. Still the same thing. Does anyone have some thoughts on this? Link to comment Share on other sites More sharing options...
Merrik Posted June 30, 2011 Author Share Posted June 30, 2011 UPDATE 2: http://support.microsoft.com/kb/942091 Link to comment Share on other sites More sharing options...
Merrik Posted June 30, 2011 Author Share Posted June 30, 2011 Sorry for all of the updates. I found if I changed this line, all problems went away - even on Windows 7. RunAs($UserName, @ComputerName, $Password1, 2, $Command) 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