nw000 Posted July 10, 2013 Posted July 10, 2013 Hi, I am trying to use an AutoIt application run from PSEXEC.EXE on a Windows 2008 R2 server but have come across a problem with ControlSetText(). The Windows 2008 R2 server has User Account Control (UAC) disabled. The problem can be demonstrated with the following AutoIt code. Compile the following AutoIT to an executable, say "test.exe". WinActivate("[CLASS:Notepad]") WinWaitActive("[CLASS:Notepad]") ControlSetText("[CLASS:Notepad]", "", "Edit1", "This is some test text") On the 2008 R2 server start two cmd.exe A and B. On cmd.exe A, type the following psexec.exe 127.0.0.1 -u <username> -p <password> -i 1 cmd.exe using the same username and password as used to login. Another cmd.exe window C appears. Now start notepad on cmd.exe B. notepad.exe Run the AutoIt script from cmd.exe C test.exe and no text appears in the the notepad window. Run the same AutoIt script from cmd.exe B test.exe and the text "This is some test text" is written to notepad. Quit notepad and now start it again but this time from cmd.exe C. This time the application test.exe only works if run from cmd.exe C. It seems to be a permissions problem but I can find no difference in permissions between cmd.exe B and C. Does anyone have any ideas what the problem might be?
Tripredacus Posted July 10, 2013 Posted July 10, 2013 Can you confirm that your EXE is actually running under the context of the user account you specified? Most people end up using PSEXEC and it runs under a system account which only has permission for Session 0, while a logged in user exists in a different session. Twitter | MSFN | VGCollect
nw000 Posted July 10, 2013 Author Posted July 10, 2013 Hi, I typed whoami /all in both cmd.exe B and C (the one spawned from PSEXEC). The only difference I could see was that cmd.exe B had the additional group of LOCAL S-1-2-0. Other than that, the two printouts were identical. Since the original post, I have found a workaround to use ControlSend() with the string "{HOME}+{END}{DEL}" & "This is some test text" but I am still intrigued to know why ControlSetText() does not. Also ControlCommand() with "EditPaste" seems to be able to append text to what is already there. But since I need to delete the original text, I went with the ControlSend() solution.
nw000 Posted July 11, 2013 Author Posted July 11, 2013 Hi, I found the ControlSend() solution in the above post a bit unrealiable and have come up with a better solution which I include here in case anyone else comes across the same problem. #include <GuiEdit.au3> ; Function to write text to an edit box on Windows 2008 Func ControlSetText2008($title, $text, $controlID, $newText) Local $hWnd = ControlGetHandle($title, $text, $controlID) _GUICtrlEdit_SetSel($hWnd, 0, -1) _GUICtrlEdit_ReplaceSel($hWnd, $newText) EndFunc ;==>ControlSetText2008 I found _GUICtrlEdit_SetText() suffers from the same problem as ControlSetText(). Also I am compiling the AutoIt on Server 2003 32-bit and running the compiled AutoIt on Server 2008 R2 64-bit. I don't know if that has any influence on this problem.
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