Jump to content

Autoitv3 Function "RunAs" Problem


Recommended Posts

Hi all! Please take a look at my problems. Thanks!

Situation:

Well, I sometimes need to use other accounts to manage their own files. Vista doesn't have the RunAs context menu like XP does, so I'd like to use Autoit to assit me.

Script:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

HotKeySet("{ENTER}","LOGIN")

Global $f_GUI = GUICreate("Local DOS System", 261, 166, 446, 437)

GUISetFont(10, 400, 0, "Tahoma")

Global $l_username = GUICtrlCreateLabel("Local Username:", 8, 16, 100, 20)

Global $l_password = GUICtrlCreateLabel("Local Password:", 8, 48, 97, 20)

Global $i_username = GUICtrlCreateInput("", 112, 16, 121, 24)

Global $i_password = GUICtrlCreateInput("", 112, 48, 121, 24, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))

Global $b_launch = GUICtrlCreateButton("Launch Local DOS System", 8, 112, 243, 25, $WS_GROUP)

Global $i_status = GUICtrlCreateInput("Please Login", 112, 80, 121, 24, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

Global $l_status = GUICtrlCreateLabel("Login Status:", 8, 80, 79, 20)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $b_launch

LOGIN()

EndSwitch

WEnd

Func LOGIN()

$sUserName = GUICtrlRead($i_username)

$sPassword = GUICtrlRead($i_password)

$runas = RunAs($sUserName, @ComputerName, $sPassword, 1, @ComSpec, @SystemDir)

;RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir)

If $runas = 0 Then

GUICtrlSetData($i_status,"Login Failed!")

Else

GUICtrlSetData($i_status,"Login Success!")

EndIf

EndFunc

Problem:

However, after successful launching the CMD window(Or Dos Window), I CAN'T EVEN ENTER ONE COMMAND. When I entered one command, a new CMD window pops up.

What's the problem within my script?

Regards,

PlatinumHex

Link to comment
Share on other sites

@Danny35d,

It make sense now, thanks. By the way, I notice that hot keys in AutoIT will always work even if your script is not active, any way to bypass that? It's kinda annoying though.

@AdmiralAlkex,

Hmm...It didn't show up. Only the "Open Command Prompt" Context.

Thank you both for replying my post.

Link to comment
Share on other sites

I notice that hot keys in AutoIT will always work even if your script is not active, any way to bypass that? It's kinda annoying though.

You can use GUISetAccelerators as RobSaunders suggested or at your Switch statement add the following lines of code:

Case $GUI_EVENT_MINIMIZE
   HotKeySet("{ENTER}","")
Case $GUI_EVENT_MAXIMIZE
   HotKeySet("{ENTER}","LOGIN")
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

You can use GUISetAccelerators as RobSaunders suggested or at your Switch statement add the following lines of code:

Case $GUI_EVENT_MINIMIZE
   HotKeySet("{ENTER}","")
Case $GUI_EVENT_MAXIMIZE
   HotKeySet("{ENTER}","LOGIN")

But what happens if he minimizes the window and then just restores it? You need $GUI_EVENT_RESTORE in there as well.

Although either way, what if he's just in another window without minimizing it?

I would stick with GUISetAccelerators but an alternative is to GUICtrlSetState($b_launch, $GUI_DEFBUTTON), that should cause the Enter key to activate that button.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...