Jump to content

Wingethandle doesn't work when unattended


Recommended Posts

I am trying to automate a process which opens an exe, opens a window in that exe and runs.  I can get the script to work when I am running it from the editor.   I can get the script to work when I run it from the task scheduler as long as I have the window open to remote desktop.  But, as soon as I close the window to remote desktop (note: just closing the window NOT logging off as the service user), the script fails.  I have set up logging on my script so I know that one line "$handle1=WinGetHandle("VISUAL MRP(tm) - Material Requirements Planning - 615")"

is not getting the handle. 

The fist part of the script runs fine.  And the logging is working so I know that it is running some of the script.  But I cannot get this handle to reliably be found.  I have run this script several times in the editor and it is reliably finding the handle that way.  Just not when I run it with the task scheduler and the RDP window closed.  This has been ongoing for a few weeks now and I am not sure where to try next.  Can anyone help?

Link to comment
Share on other sites

Please post your script, or a reproducer script that demonstrates what it is you're doing.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include <Date.au3>
#include <array.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
$sFileName = "C:\Test.txt"

; Open file - deleting any existing content
$hFilehandle = FileOpen($sFileName, $FO_OVERWRITE)
FileWrite($hFilehandle,"Start"& @CRLF)

AutoItSetOption ("TrayIconDebug", 1)
ShellExecute("G:\Infor\Visual\Visual MFG\VMPLNWIN.EXE","-u <username> -p <password> -d <database>")
FileWrite($hFilehandle, getcurrenttime() & "Execute Window"& @CRLF)
sleep(3000)
$handle=WinGetHandle("Material Planning Window - Infor VISUAL [Material Planning Window]")
WinActive($handle)
FileWrite($hFilehandle, getcurrenttime() & $handle & @CRLF)
Send("!F")
FileWrite($hFilehandle,getcurrenttime() & "send !f" & @CRLF)
Sleep(1000)
Send("{Down}")
sleep(1000)
Send("{Down}")
sleep(1000)
Send("{Down}")
sleep(1000)
Send("{Down}")
sleep(1000)
Send("{Down}")

sleep(1000)
Send("{Down}")
sleep(1000)
Send("{ENTER}")
sleep(10000)
FileWrite($hFilehandle, getcurrenttime() & "send enter line 36" & @CRLF)
;window is now open
$handle1=WinGetHandle("VISUAL MRP(tm) - Material Requirements Planning - 615")
;AutoItSetOption("WinTitleMatchMode",4)
;$handle1=WinGetHandle("[CLASS:Gupta:Dialog; INSTANCE:1]")
WinActivate($handle1)
sleep(3000)

WinActive($handle1)
FileWrite($hFilehandle,getcurrenttime() & $handle1 & @CRLF)

 

 

The line in blue is the line which is not working when unattended.  This works FINE when I am watching the screen.  Just not when the RDP window is not open.  The script gets the handle of the first window just fine when the RDP window is not open.

Link to comment
Share on other sites

You can't use Send, or WinActive or Activate on an unattended PC.

https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The same way you do with Send, just need the window handle or title and the control handle. The help file explains how it works.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers

I would think it is pretty clear...no?:

Quote

Remarks

ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok.  I tried to use ControlSend($handle,"","","{Down}") and it doesn't work.  So, yes, that statement you posted is clear but this doesn't work.  So I must be missing something.

I

Link to comment
Share on other sites

14 minutes ago, LCote said:

Ok.  I tried to use ControlSend($handle,"","","{Down}") and it doesn't work.  So, yes, that statement you posted is clear but this doesn't work.  So I must be missing something.

I

When you use control send, you need to specify the control to which you're sending. Also it's a good idea to check for success on WinGetHandle etc, and you can often use the wait functions (WinWaitActive, winWaitNotActive, etc) to avoid guessing at sleep durations.

Link to comment
Share on other sites

Example...this will not work for notepad.exe

Winmenuselectitem ($h,"","File","Open...")

 

This will:

Winmenuselectitem ($h,"","&File","&Open...")

 

Wherever you see the underscores, you need to include a &

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

#include <Date.au3>
#include <array.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
$sFileName = "C:\Users\svc_erpvisual\Documents\Test.txt"

; Open file - deleting any existing content
$hFilehandle = FileOpen($sFileName, $FO_OVERWRITE)
FileWrite($hFilehandle,"Start"& @CRLF)

AutoItSetOption ("TrayIconDebug", 1)
ShellExecute("G:\Infor\Visual\Visual MFG\VMPLNWIN.EXE","-u <username> -p <password> -d <database>")
FileWrite($hFilehandle, getcurrenttime() & "Execute Window"& @CRLF)
sleep(3000)
$handle=WinGetHandle("Material Planning Window - Infor VISUAL - [Material Planning Window]")
FileWrite($hFilehandle, getcurrenttime() & $handle & @CRLF)
sleep(1500)
ControlSend($handle,default,$handle,"!F",0)

Up to here, this works.

I either need to send down several times.  Or send "Q" or winmenuselect to get to the command and NONE of it is working.

I am already aware of the ampersand in winmenuselect.  That still isn't working for me. 

I have been all over Google about this.  The only thing I haven't read about is the accelerators.  Can you explain?

 

 

Link to comment
Share on other sites

When you send alt at a window, you will see some letters are underlined in the menu.  those are accelerators, letters you can send at the window to open the menu item.  generally sub items in those menus also have accelerators.   you must include a & in front of that underlined letter.  read the full helpfile page for this (it's  a link, click it):

Winmenuselectitem

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Yes, I know that.  But it isn't working.  I am trying to send alt F then Q.  It doesn't work. 

I have tried sending

ControlSend($handle,default,$handle,"!F",0)

ControlSend($handle,default,$handle,"Q",0)

 

I also tried

ControlSend($handle,default,$handle,"!FQ",0)

None of these are working for me.  It could easily be a problem with the software I am trying to automate.

 

I also tried

ControlSend($handle,default,$handle,"{down}") and that didn't work either.

Edited by LCote
Link to comment
Share on other sites

Those methods won't work on a locked desktop.   i gave you the proper function to use that works in all situations

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...