Jump to content

Exit script after "While" loop


Recommended Posts

The loop will not even start with WinExists(). Instead use WinWaitActive().

Run(@ComSpec & " /c " & "C:BGInfoBginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
WinActivate($Title)
WinWaitActive("title", "", 10)
Send("{ESC}")

Autoit will do all the looping internally.

Hmm ok, I will try your script on Monday when I'm back at work. Thank you!

WinClose() ? Should be the same as hitting ESC or the window X

I will give that a try if John's version don't work! Thanks :D
Link to comment
Share on other sites

He doesn't even need the window activated before telling it to minimize. Correct me if I'm wrong, but you just want it so that when BGinfo starts automatically on logon, you want it minimized to the system tray? (with the way you're spawning BGinfo, minimizing to tray is done by pressing ESC... and should also give you the same result if you press the window X).

Try this out:

$title = "BGInfo"
WinWait($title)
WinClose($title)
Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

The loop will not even start with WinExists(). Instead use WinWaitActive().

Run(@ComSpec & " /c " & "C:BGInfoBginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
WinActivate($Title)
WinWaitActive("title", "", 10)
Send("{ESC}")

Autoit will do all the looping internally.

Thank you! It almost worked! As long as no other windows steal focus from BGInfo it closes as it should, but since a lot of other applications will launch at the same time this won't do it in the long run..

WinClose() ? Should be the same as hitting ESC or the window X

Thanks, nice suggestion. And I thought it worked for a little while, but then I noticed that the icon from the taskbar was gone as well as the window..

Geez this is frustrating :)

Edited by scanie
Link to comment
Share on other sites

It appears as though {ESC} likley just set the window attribute to hidden, rather than closes it. If this is the case you can use:

Run(@ComSpec & " /c " & "C:\BGInfo\Bginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
WinSetState ($Title, "", @SW_HIDE)

Best to check if this is so first though. Run the program normally and hit {ESC} to close it. Then run:

$state=WinGetState($Title)
If BitAnd($state, 2) Then
MsgBox(0,"Visible?","Visible: True")
Else
MsgBox(0,"Visible?","Visible: False")
EndIf

If the state comes back hidden the above code should work. Otherwise it'll require a retry loop to get the {ESC} key approach to work properly in the event focus is stolen.

Link to comment
Share on other sites

It appears as though {ESC} likley just set the window attribute to hidden, rather than closes it. If this is the case you can use:

Run(@ComSpec & " /c " & "C:BGInfoBginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
WinSetState ($Title, "", @SW_HIDE)

Best to check if this is so first though. Run the program normally and hit {ESC} to close it. Then run:

$state=WinGetState($Title)
If BitAnd($state, 2) Then
MsgBox(0,"Visible?","Visible: True")
Else
MsgBox(0,"Visible?","Visible: False")
EndIf

If the state comes back hidden the above code should work. Otherwise it'll require a retry loop to get the {ESC} key approach to work properly in the event focus is stolen.

You sir, are awesome! It worked, at least on my test rig. I will try it on some other clients during the day! But it seems to me that you have solved my problem.

Big thanks!

P.S, how would I insert a loop in this script?

Edited by scanie
Link to comment
Share on other sites

Note: Will not work if the window is intended to merely be hidden.

If the window is actually supposed to close, instead of just being hidden, this should work to retake focus every second until the ESC actually works:

Run(@ComSpec & " /c " & "C:BGInfoBginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
While WinExists($Title)
WinActivate($Title)
Send("{ESC}")
Sleep(1000)
WEnd

Problem with this is that if the window is only supposed to be hidden, instead of close, the loop will never end. Could create some issues.

Another loop alternative that takes into account either possibility is:

Run(@ComSpec & " /c " & "C:BGInfoBginfo.lnk", @TempDir, @SW_HIDE)
$Title = "BGInfo"
WinWait($Title, "", 60)
While BitAnd(WinGetState($Title), 2)
WinActivate($Title)
Send("{ESC}")
Sleep(1000)
WEnd

This uses the ESC loop, but only continues the loop if the window state remains visible.

If the test script I provided returns false, after hitting ESC to close the window, then the script you have is the best solution. If you want more complete information this script will give 2 MsgBox's. One that tells you whether the window exist or not and the other telling you whether it's visible or not. (Note: It doesn't run BGInfo first).

$Title = "BGInfo"
$state=WinGetState($Title)
If @error Then MsgBox(0,"BGInfo","BGInfo window not found.")
If BitAnd($state, 1) Then MsgBox(0,"BGInfo","BGInfo window exist.")

If BitAnd($state, 2) Then
MsgBox(0,"BGInfo","Visible: True")
Else
MsgBox(0,"BGInfo","Visible: False")
EndIf

Edit: Said 'true' when it should have been 'false'.

Edited by John
Link to comment
Share on other sites

The first script you provided closes the window as soon as the BGInfo window loses focus, but the script doesn't close afterwards.

The second script doesn't work at all, strangely enough.

The script that worked the best so far was the one you provided before your last post. But, it's not consistant, because it works fine on my machine even though other windows are open in front of it. But on some other machines that I have tried it on, it doesn't always hide the window..

Haha, this has given me more work than I thought it would :) I thought this was going to be an easy task, I have done several autoit scripts before that has been more complex..

Link to comment
Share on other sites

Does minimizing the screen minimize it to the tray? Or does the window stay?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Does minimizing the screen minimize it to the tray? Or does the window stay?

What do you mean with minimizing the "screen"? The BGInfo window only has one button and it's the X. If that's what you meant? :)
Link to comment
Share on other sites

Try this...

WinSetState($title, "", @SW_MINIMIZE)

:ermm:

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

In order for me to have an idea of why it doesn't work on some other machines I need the information from the test scripts I provided. In fact I'll add more information based on the other questions here.

1) Open BGInfo normally without script.

2) Manually hit ESC to close/hide/minimize BGInfo

3) Run the following script and post every msgbox it pops up.

$Title = "BGInfo"
$state=WinGetState($Title)
If @error Then MsgBox(0,"BGInfo","BGInfo window not found.")
If BitAnd($state, 1) Then MsgBox(0,"BGInfo","BGInfo window exist.")
If BitAnd($state, 16) Then MsgBox(0,"BGInfo","BGInfo is minimized.")
If BitAnd($state, 32) Then MsgBox(0,"BGInfo","BGInfo is maximized.")

If BitAnd($state, 2) Then
MsgBox(0,"BGInfo","Visible: True")
Else
MsgBox(0,"BGInfo","Visible: False")
EndIf

Do the same on the machine the other script doesn't seem to work on, but first I need to know how BGInfo is supposed operate normally from you main machine.

Link to comment
Share on other sites

  • 8 months later...

If I understand correctly then all you need to do is register BGInfo to start with the following CLI switches: /NOLICPROMPT /TIMER:0 /TASKBAR

*** /TIMER:0 *** Is the key here as it removes the need to send the ESC key once the application starts.... It applies the changes immediately and minimizes the applicaiton to the system tray. Also as mentioned above you can start the application hidden without interfering with system tray functionality.

Prepending the path to a saved config file(saved from within the GUI with quotes) to the above for non default configuration. ;)

Edited by Decipher
Spoiler

censored.jpg

 

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...