PlatinumHex Posted April 19, 2010 Posted April 19, 2010 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() EndSwitchWEndFunc 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 ThenGUICtrlSetData($i_status,"Login Failed!")ElseGUICtrlSetData($i_status,"Login Success!")EndIfEndFuncProblem: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
Danny35d Posted April 19, 2010 Posted April 19, 2010 May be because to trigger your HotKey function is the ENTER key. HotKeySet("{ENTER}","LOGIN") so every time you type a command and hit enter it will open a new command prompt window. AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
AdmiralAlkex Posted April 19, 2010 Posted April 19, 2010 To get the "run as different user"-choice In Vista/7 you need to hold Shift when you right click! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
PlatinumHex Posted April 20, 2010 Author Posted April 20, 2010 @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.
therks Posted April 20, 2010 Posted April 20, 2010 HotKeySet is for setting global hotkeys. If you want to set hotkeys specifically for your GUI look into GUISetAccelerators. My AutoIt Stuff | My Github
Danny35d Posted April 20, 2010 Posted April 20, 2010 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
therks Posted April 21, 2010 Posted April 21, 2010 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. My AutoIt Stuff | My Github
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