Sign in to follow this  
Followers 0
Merrik

Runas Help

7 posts in this topic

#1 ·  Posted (edited)

Hi,

I could use some help with this script using runas

#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 by Merrik

Share this post


Link to post
Share on other sites



This should work better:

#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>

Share this post


Link to post
Share on other sites

Thanks sleepydvdr :)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

UPDATE 2:

http://support.microsoft.com/kb/942091

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0