
SanCon
Members-
Posts
8 -
Joined
-
Last visited
Recent Profile Visitors
179 profile views
SanCon's Achievements

Seeker (1/7)
0
Reputation
-
RunAs, ProcessEx UDF and returned errorlevels - (Moved)
SanCon replied to SanCon's topic in AutoIt General Help and Support
Thanks, @Melba23 Sorry for posting it on the wrong forum. -
Greetings, I've found and used @TheDcoder's ProcessEX UDF, and have found it and invaluable tool in my scripting arsenal. Recently, I found myself needing to create a script which then attempts to run another program as a different user. I was able to heavily borrow from the _Process_RunCommand function to create _Process_RunAsCommand: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Process_RunAsCommand ; Description ...: Runs a command or an executable under a different user security privilege. ; Syntax ........: _Process_RunAsCommand($iMode, $sUserName, $sUserPass, $sUserDomain, $sExecutable [, $sWorkingDir = @TempDir [, $iRunOptFlag = $STDERR_MERGED]]) ; Parameters ....: $iMode - Mode in which this function should operate, See Remarks. ; $sUserName - User name under which you would like to run the command/executable. ; $sUserPass - Password for $sUserName. ; $sUserDomain - Domain name to which the $sUserName belongs. ; $sExecutable - The command to run/execute (along with any arguments). ; $sWorkingDir - [optional] The working directroy for the command. Default is @TempDir. $sUserName must have ; privileges to create/modify files on this directory. ; $iRunOptFlag - [optional] The Opt flag for the Run function. Default is $STDERR_MERGED. ; Return values .: Success: Mode $PROCESS_RUN : Will return the process handle & @extended will contain the PID of the command ; Mode $PROCESS_RUNWAIT : Will return the output & @extended will contain the exit code for the function ; Failure: Will return False & @error will contain: ; 1 - If the $iMode flag is invalid ; 2 - If the command is invalid ; Author ........: J. Sanchez, heavily borrowing from code by TheDcoder ; Modified ......: N/A ; Remarks .......: 1. The ONLY valid modes are: $PROCESS_RUN & $PROCESS_RUNWAIT ; $PROCESS_RUN : Will act similarly to Run function, See Return values ; $PROCESS_RUNWAIT : Will act similarly to RunWait function, See Return values ; If you use $PROCESS_RUN then use _Process_GetExitCode to get the exit code & use StdoutRead to get the output of the command ; 2. Use $PROCESS_COMMAND to run commands like this: $PROCESS_COMMAND & "ping 127.0.0.1" ; 3. Add $PROCESS_DEBUG to $iMode to automagically debug the command, $PROCESS_RUN is equivalent to $PROCESS_RUNWAIT in this case ; Related .......: RunAs, RunWait ; Link ..........: http://bit.ly/ProcessUdfForAutoIt ; Example .......: Yes, see example.au3 ; ===============================================================================================================================; Functions Func _Process_RunAsCommand($iMode, $sUserName, $sUserPass, $sUserDomain, $sExecutable, $sWorkingDir = @TempDir, $iRunOptFlag = $STDERR_MERGED) Local $iExitCode = 0 ; Declare the exit code variable before hand Local $sOutput = "" ; Declare the output variable before hand Local $bDebug = False ; Declare the debug variable before hand If BitAND($iMode, $PROCESS_DEBUG) Then $bDebug = True If BitAND($iMode, $PROCESS_RUN) Then $iMode = $PROCESS_RUN ElseIf BitAND($iMode, $PROCESS_RUNWAIT) Then $iMode = $PROCESS_RUNWAIT Else Return SetError(1, 0, False) EndIf ; If Not $iMode = $PROCESS_RUN Or Not $iMode = $PROCESS_RUNWAIT Then Return SetError(1, 0, False) ; If the mode is invalid... ;Local $iPID = Run($sExecutable, $sWorkingDir, @SW_HIDE, $iRunOptFlag) ; Run!!! :P Local $iPID = RunAs($sUserName,$sUserDomain,$sUserPass,BitAND(0,4),$PROCESS_COMMAND & " " & $sExecutable,$sWorkingDir,@SW_HIDE,$iRunOptFlag) If @error Then Return SetError(2, @error, False) ; If the command is invalid... Local $hProcessHandle = _Process_GetHandle($iPID) ; Get the handle of the process If $iMode = $PROCESS_RUN Then If Not $bDebug Then Return SetExtended($iPID, $hProcessHandle) ; If the function is in Run mode then return the PID & Process Handle $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code EndIf If Not $bDebug Then While ProcessExists($iPID) $sOutput &= StdoutRead($iPID) ; Capture the output Sleep(250) ; Don't kill the CPU WEnd $sOutput &= StdoutRead($iPID) ; Capture any remaining output $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the exit code & the output :D EndIf $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code EndFunc The issue that I currently have is that, regardless of what the errorlevel returned by the program being executed, the errorlevel returned by the _Process_RunAsCommand is 259, which, according to this page it means that there's no more data (I'm guessing from the STDIO and STDERR?) Any guidance would be greatly appreciated.
-
Windows 10 RunAs script problem
SanCon replied to Traskiz's topic in AutoIt General Help and Support
While I know this is an old topic, it came up during a search for me, and this might prove useful to someone else: I kept getting an error 1 whenever I tried to launch an elevated cmd.exe using AutoIt's RunAs. The culprit was the working directory. I was using the script directory, but once I switched to "@TempDir", I was able to launch my elevated command prompt and run my programs as needed. -
SanCon reacted to a post in a topic: Disabling a button in an Internet Explorer_Server instance using IUIAutomation
-
SanCon reacted to a post in a topic: Disabling a button in an Internet Explorer_Server instance using IUIAutomation
-
Thank you again, @LarsJ. With my limited understanding, I thought as much, but I know that some of the members in the AutoIt community are quite resourceful. I thought about monitoring mouse activity, but now that you mention that it may not be possible to do it within AutoIt, I may have to give up on this endeavor. Thank you again for your help!
-
SanCon reacted to a post in a topic: Disabling a button in an Internet Explorer_Server instance using IUIAutomation
-
@LarsJ, Thank you for the reply. Upon further examination of the output of simplespy, I see the following: UIA_IsValuePatternAvailable:= <False> UIA_IsWindowPatternAvailable:= <False> UIA_ValueIsReadOnly:= <True>Edited entry: could the Legacy IAccessiblePattern part be used for my purpose? UIA_IsLegacyIAccessiblePatternAvailable:= <True> UIA_LegacyIAccessibleChildId:= <0> UIA_LegacyIAccessibleName:= <Delete> UIA_LegacyIAccessibleRole:= <43> UIA_LegacyIAccessibleState:= <1048576> UIA_LegacyIAccessibleDefaultAction:= <Press>Your help is greatly appreciated!
-
Some views, but no replies. I'm guessing it's not possible to do this. Still... @junkew: Found an MSDN article about Registering Custom Properties, Events, and Control Patterns, but not sure how to implement this approach in AutoIt. I may not be understanding this correctly, but would this allow one to add a custom property to a button which UIAutomation is able to click/highlight/etc? In the snippet above, your libraries can highlight and click on the button. But I've found no way to disable it. So, could a custom property be added to disable any button seen by the Automation library? Thank you all for your time!
-
SanCon reacted to a post in a topic: IUIAutomation MS framework automate chrome, FF, IE, ....
-
exact same script doesnt run on other computer
SanCon replied to Arclite86's topic in AutoIt General Help and Support
I would also recommend declaring all variables by using: Opt("MustDeclareVars", 1) When I worked at Sony, we created a program using AutoIt! which automated some of our testing. Program worked fine in 99% of computers. Due to some bad practice, we were declaring variables on the fly. Once we switched to "Must Declare Variables" the issue we experienced (the program would complain at random that variables were being used before being declared) went away. Hope that helps. -
SanCon reacted to a post in a topic: Running AutoIT EXEs with Locked screens - FAQ
-
Hello everyone, I support an application which has an Internet Explorer_Server instance in a pane of the application. There are a few buttons we would like to disable in the application, as it causes many an issue whenever users click on the buttons. The buttons which are part of the application/program are easy to disable (there was a "Print" button which we have disabled this way, thus forcing the user to use the "File->Print" option as that is the preferred method) but those which are part of the Internet Explorer_Server pane were inaccessible. Enter Junkew's IUIAutomation UDF. I've been trying to follow the threads regarding IUIAutomation, and while I've been able to highlight the button (which in itself is a great accomplishment in my view) I can't find a way to disable said button. Is this even possible? If this were a regular button, I could get the handle of the control and manipulate it that way. I understand that the "automation" part doesn't include disabling items (who does that, right?) but I was wondering if someone savvier than myself knew of a method to do this. Below is the code provided by simple spy (which I commented out to use the shorter version of the program at the end) Some information has been removed, but it was mostly to protect innocent servers. :-) Any guidance/assistance would be greatly appreciated. #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) #cs Local $oP13=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=[Horizon Ambulatory Care];controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app4", $treescope_children) _UIA_Action($oP13,"setfocus") Local $oP12=_UIA_getObjectByFindAll($oP13, "Title:=Workspace;controltype:=UIA_PaneControlTypeId;class:=WindowsForms10.MDICLIENT.app4", $treescope_children) _UIA_Action($oP12,"setfocus") Local $oP11=_UIA_getObjectByFindAll($oP12, "Title:=Horizon Ambulatory Care;controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app4", $treescope_children) _UIA_Action($oP11,"setfocus") Local $oP10=_UIA_getObjectByFindAll($oP11, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell Embedding", $treescope_children) _UIA_Action($oP10,"setfocus") Local $oP9=_UIA_getObjectByFindAll($oP10, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell DocObject View", $treescope_children) _UIA_Action($oP9,"setfocus") Local $oP8=_UIA_getObjectByFindAll($oP9, "Title:=info.sys:12200/hac/clinical/frame/showMainFrame;controltype:=UIA_PaneControlTypeId;class:=Internet Explorer_Server", $treescope_children) _UIA_Action($oP8,"setfocus") Local $oP7=_UIA_getObjectByFindAll($oP8, "Title:=HAC;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children) Local $oP6=_UIA_getObjectByFindAll($oP7, "Title:=info.sys:12200/hac/clinical/frame/showRootFrame;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) Local $oP5=_UIA_getObjectByFindAll($oP6, "Title:=Root Frame Page;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children) Local $oP4=_UIA_getObjectByFindAll($oP5, "Title:=info.sys:12200/hac/clinical/workFlow/worklist/tabBarHandler/showFrameSet?activeTab=0;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children) Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=info.sys:12200/hac/clinical/workFlow/worklist/showWorklist;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Worklist;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children) Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children) ;~ First find the object in the parent before you can do something ;~$oUIElement=_UIA_getObjectByFindAll("Delete.mainwindow", "title:=Delete;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Delete;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) ConsoleWrite("Value: " & _UIA_action($oUIElement,"right") & @CRLF) #ce _UIA_SetVAR("HACWindow","Title:=[Horizon Ambulatory Care];controltype:=UIA_WindowControlTypeId;class:=WindowsForms10.Window.8.app4") _UIA_SetVAR("TaskListPane","Title:=Worklist;controltype:=UIA_PaneControlTypeId;class:=") _UIA_SetVAR("DeleteButton","title:=Delete;ControlType:=UIA_ButtonControlTypeId") ConsoleWrite("HAC? " & _UIA_Action("HACWindow","setfocus") & @CRLF) ConsoleWrite("Pane? " & _UIA_Action("TaskListPane","setfocus") & @CRLF) ConsoleWrite("Button? " & _UIA_Action("DeleteButton","highlight") & @CRLF)