No Window Name available

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

No Window Name available

Post by obfusc88 » Sat Aug 27, 2011 1:55 am

I am running a script that calls a program whose window name I cannot capture. I was trying to use WaitWindowOpen, but that did not work. So I tried using GetActiveWindow, and FindWindowWithText, but they all failed.

So, I turned on Tools/System Windows Monitor and found that the "window" is really something called a "ConsoleWindowClass" ?

I have tried running the program with the command in the path.
I have tried running the program using the full path.
I have tried running the program using cmd /c
All end up with the same result, I had to change the window name slightly for each one, since xxcopy.exe* did not work, I needed the full path showing in the Window Title

The command line program running in the window pauses with a message that I need to press "any key" to continue. So I am trying to SetFocus to the window so I can Send>AnyKey, else the program shuts down in two minutes if no key is pressed.

Here a sample test script that runs OK:

Code: Select all

Let>vOne=1
Let>vTwo=2
GoSub>TestOne
MessageModal>Sub is done
Goto>End

SRT>TestOne
Let>RP_WINDOWMODE=1
Run Program>C:\Program Files\XXcopy\xxcopy.exe Q:\*\* T:\Snap\ /CR8 /BU /PB /FF /CK0 /OAQ:\Data\Backups\Logs\20110824Msg.log /FoQ:\Data\Backups\Logs\20110824Files.log /FMSDTZAL /EXQ:\Data\Backups\Xxcopy\ExcludeList.txt
Wait>10
WaitWindowOpen>C:\Program Files\XXcopy\xxcopy.exe
Wait>2
Send>%SPACE%
WaitWindowClosed>Progress - XXCOPY
Let>RP_WINDOWMODE=0
MessageModal>Done
End>TestOne

Label>End
I made the test script and it runs OK every time. But if I run it in the middle of my script, it hangs on WaitWindowOpen. So, I wondered, what was different? Well, in the real script, it is actually part of a SubRoutine, so I modified the test script to run in a sub routine as shown above. And it still runs OK.

So, what else is different? Some variables at the beginning of the main script. I tried removing them and it looked like RP-WAIT was causing the problem. It was originally set = 1. I removed it, and it seemed to run OK, but only once. So I set RP_WAIT=2 and =0, and it also ran OK once only. Here is the code for the variables at the top of the real script:

Code: Select all

CAPSOFF
Let>SK_DELAY=10
Let>CF_OVERWRITE=1
Let>MSG_STAYONTOP=0
Let>RP_WAIT=2
Let>RP_WINDOWMODE=0
Let>Count=0
This is the only RP_WAIT line in the script, and is not in the loop that runs the subroutine process from 1-14 times. Hmm, No, I have not run the test script yet with a loop to see if it continues to run more than one time. I will try to get to that soon.

Again, it always hangs when WindowName=NOT FOUND with any of the Wait style windows using the Window Name. I am sure it is because this is a ConsoleWindowClass vs. a "normal window". Since I can't get the name, I can't get the handle either. The "window" is open, but no name.

All I want to do is SEND>AnyKey to the window so it will continue.

All good suggestions will be gratefully accepted.
The program I am running is XXCOPY, version 2.92.2
I am using Macro Scheduler 11.1.20 on Windows7 32bit Pro.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Aug 27, 2011 6:44 am

Please try:
WaitWindowOpen>xxcopy*

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Sun Aug 28, 2011 5:46 pm

Nope.

I have tried all variations of the command line, with and without the path segments, with and without the "*".

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sun Aug 28, 2011 9:03 pm

Make sure no trailing space.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Aug 29, 2011 3:00 am

Does any recognizable text show up within the list if you run GetWindowList>? If yes you could run that in a loop checking the list for the recognizable text. Continue when the text is found.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Mon Aug 29, 2011 4:05 am

1. No trailing spaces, but thanks.
2. Never thought of GetWindowsList. I just tried that, and the name that appears is C:\Windows\system32\cmd.exe. But not available to MS tools.
But this does not work: WaitWindowOpen>C:\Windows\system32\cmd.exe*
It does not work with WaitWindowOpen>cmd.exe* either.
It does not work if the "*" is dropped.
It does not recognize any text string in the window.

Here is a screenshot of the open "window":
Image

Pressing "anykey" does allow the program to run properly in this OS (Windows7). Works OK if run from a DOS prompt window, this window opens up, I press a key, and off it goes. But will not allow me to press a key when run from inside Macro Scheduler.
I

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Aug 29, 2011 4:36 am

If the window is found using GetWindowList> then the following might work as a substitute for WaitWindowOpen.

If the following works and you can detect when the window is open the next question is, can you set focus to it? If you can set focus using "C:\Windows\system32\cmd.exe" as the window name then can you use Send> to send a key stroke? If not try a "Press" key function like Press Enter or Press tab.

Code: Select all

GoSub>WaitWindowOpen,C:\Windows\system32\cmd.exe

SRT>WaitWindowOpen
  Label>WWO_WaitForWindow
  GetWindowList>ListOfOpenTopLevelWindows
  Separate>ListOfOpenTopLevelWindows,WaitWindowOpen_var_1,WindowListTest
  If>WindowListTest_count>1
  Else
    Wait>0.01
    Goto>WWO_WaitForWindow
  EndIf
END>WaitWindowOpen

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Aug 29, 2011 5:49 am

JRL's algorithm should work fine.
There are 2 more alternatives as your last resorts:

Method 1
Label>PE
ProcessExists>cmd.exe,Result
Wait>.1
If>Result=Fales,PE

Methold 2
1. Save a tiny portion of the window title as an image, say, c:\temp\cmd.bmp.
2. WaitScreenImage>c:\Temp\cmd.bmp
WaitReady>0

BTW, please check if your version of Macro Scheduler supports the commands mentioned in either Method 1 or 2.

Hope it helps.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Tue Aug 30, 2011 11:20 am

My version does not support ProcessEnd.
My version does support WaitScreenImage. That sounds like a good idea to replace WaitWindowOpen

It's not the wait/delay that is the problem, it is setting the focus to do the Send/Press.

But both suggestions above will only provide the delay so I know the window is open. But I still need to follow that with a SetFocus. The problem is SetFocus needs a window name. One of the things that is confusing is why GetWindowList would show the window name, but that name is NOT FOUND when using in SetFocus/FindWindowWithText type of commands. These are the only commands I know in Macro Scheduler to set focus before Send> is used.

I still think is has to do with being a "ConsoleWindowClass" object. Is it possible to write some type of WindowsScript that can be called by Macro Scheduler that would do the Send>AnyKey to that object? I don't know the WindowsScript tools, so I would need the specific code. But then I could Run Program>XXCOPY/Get a Delay/Run the WindowsScriptCommand/ and let XXCOPY continue to run after it receives the AnyKey from that script. (When XXcopy does continue to run, another window opens that Macro Scheduler does recognize OK and I can use with WaitWindowClosed).

Thanks for the ideas, keep them coming.

obfusc88
Pro Scripter
Posts: 89
Joined: Wed Mar 14, 2007 6:22 pm

Post by obfusc88 » Tue Aug 30, 2011 11:43 am

I googled for ConsoleWindowClass and found a question similar to mine, how to send text to this type object. On this site: http://www.vbforums.com/archive/index.php/t-380589.html I found the following code that fixed the problem for that person.

Code: Select all

[DllImport("user32", EntryPoint = "FindWindowA")]
private static extern IntPtr FindWindow(
[MarshalAs(UnmanagedType.LPStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPStr)] string lpWindowName
);

[DllImport("user32", EntryPoint = "PostMessageA")]
private static extern int PostMessage(
IntPtr hWnd,
int uMsg,
int wParam,
int lParam
);

private const int WM_CHAR = 0x102;

private void Command1_Click()
{
// you will need to change this line to find the telnet window
IntPtr hWndCMD = FindWindow("ConsoleWindowClass", String.Empty);

byte[] chars = (new System.Text.ASCIIEncoding()).GetBytes(Text1.Text);

for (int i = 0; i < chars.Length; i++)
{
PostMessage(hWndCMD, WM_CHAR, (int)chars[i], 0);
}

PostMessage(hWndCMD, WM_CHAR, 10, 0);
PostMessage(hWndCMD, WM_CHAR, 13, 0);
}
---------------------------
I also found this VB6 code here: http://answers.yahoo.com/question/index ... 926AA97pPG

Code: Select all

Dim WinHandle as Long
WinHandle = Shell("calc.exe", 1) ' Run Calculator
AppActivate WinHandle ' Activate the Calculator

...assuming you are shelling the required app through code, or if it is already running using its "window title", as so:

On Error GoTo Fail
AppActivate "Microsoft Excel"
'Activation Successful
'Rest of code goes here
End Sub

Fail:
'Activation Failed

Once you have an active app then you can send 'keystrokes' to it like so:

SendKeys "Hello" 'Will send this text string to the app active input

You can also send special control characters with symbols like "^" for 'Control', "%" for 'Alt', "+" for 'Shift'. 
So for ex. using SendKeys "%FO" will effectively send the sequence 'Alt-F' then 'O' (like for File-Menu - Open)
-------------------------------

Could a modification of one of these work for me? What is the language(VB6?)? What file name would it be saved as? How would it be compiled and/or called by Macro Scheduler? Can this be done in the VB included with Macro Scheduler?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Aug 30, 2011 12:20 pm

Referring to your code, instead of Send>%SPACE%,
Try: Press ENTER

Referring to Method 2, the script may look like:
WaitScreenImage>c:\Temp\cmd.bmp
WaitReady>0
Wait>1
Press ENTER

Referring http://www.xxcopy.com/xxcopy01.htm, it offers several parameters to suppress the dialog.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Aug 30, 2011 12:45 pm

I have been using XXCOPY for many years. I think armsys is correct. I can't check now, but I believe the correct switch is "/YY" to kill window prompts.

If this does not work, I will check to see if I have an older version that I can use to try to duplicate the problem. Even if this does work, I am curious about not being able to see the window.

(I would bet that no other program has more switches on a command line than XXCOPY, but it is a great program). :roll:
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Aug 30, 2011 1:11 pm

I was wrong, "/YY" is not correct.

But "/WV0" is supposed to suppress warning about wrong OS. That is a number zero at the end, not the letter O.

Sorry about that, hope this helps.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Aug 30, 2011 1:29 pm

You may also right-click xxcopy.exe in Windows Explorer and set its Compatiblity to Windows XP.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Aug 30, 2011 4:01 pm

In case you still have the problem. It looks like the /WV0 switch in the help sections was deprecated, but not removed from the Help.

But I think I have a small java script that can be run before XXCOPY to send the key into the XXCOPY program. I found it in my old XXCOPY notes folder. I had used it in some batch files for XXCOPY without Macro Scheduler.

I won't be able to get to it for a few hours. But maybe Marcus will be able to write a small VB script here that will send the key for you.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts