Jump to content
Sign in to follow this  
StarsLikeDust

WinClose Not working

Recommended Posts

StarsLikeDust

Hi All,

I'm a bit of a noob to Autoit. What I am trying to do is write a script to close a program. The program in question runs as a service. Since it's a database for the bookstore I work at it when you tell it to close it pops up a dialogue box telling you it will take 10 mins. Here is the code I have so far.

While ProcessExists( "ACUMEN BOOK Server.exe" ) > 0

    if WinExists ( "4D Server" ) == 1 Then
        WaitClose()
    EndIf

        If WinExists ( "ACUMEN Book" ) == 1 Then
        Close3()
    EndIf


    If WinExists ( "ACUMEN Book" ) == 1 Then
        Close2()
    EndIf

    If WinExists ( "ACUMEN Book" ) == 1 Then
        Close1()

    EndIf

WEnd

;Reboot the computer
Shutdown ( 2, "Weekly Reboot" )
Exit

;Functions

;Looks for Acumen Book window and send Ctrl+Q to try and shut it down
Func Close1()
    WinActivate ( "ACUMEN Book" )
    WinWaitActive( "ACUMEN Book" )
    SendKeepActive ( "ACUMEN Book","{CTRLDOWN}q{CTRLUP}" )
    return 0
EndFunc
;Looks for Acumen Book window and sends the close signal
Func Close2()

    WinActivate ( "ACUMEN Book" )

    if WinActive ( "4D Server" ) Then
        WinClose ( "ACUMEN Book" )
    EndIf

    return 0
EndFunc
;Looks for Acumen Book window and send Ctrl+Q to try and shut it down
Func Close3()
    WinActivate ( "ACUMEN Book" )

    if WinActive ( "4D Server" ) Then
        SendKeepActive ( "ACUMEN Book","^q" )
    EndIf

    return 0
EndFunc
;looks for the dialogue associated with closing acumen book server and tells it to continue
Func WaitClose()

    WinActivate ( "4D Server" )

    if WinActive ( "4D Server" ) Then
        SendKeepActive ( "{Enter}" )
    EndIf

    return 0
EndFunc

Nothing terribly complicated but unfortunately I simply doesn't work. I did a bit of digging around and found that when I use WinGetState( "ACUMEN Book" ) it returns 15 the help files say it should be 16,8, 4, etc. so I'm guessing that might be the issue? Anyone know how to get around that? Note: ProcessClose does shut it down but not properly. Since it is a database I'd rather shut it down the way it expects to be shutdown.

Share this post


Link to post
Share on other sites
PsaltyDS

Run this from a commandline:

NET START

Look for the service name in the list (i.e. "ACUMEN Book Server").

Then run this from AutoIt:

$sSvcName = 'ACUMEN Book Server'
$iRET = RunWait('NET.exe STOP "' & $sSvcName & '"')
MsgBox(64, 'Done', '$iRET = ' & $iRET)

There is also a WMI interface via the Win32_Service object, and DllCalls() you can use, but this is the basic method.

:mellow:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Fulano

Well, I don't really have time to examine it atm, but I can explain the 15 return value.

The values are actually binary flags. so

000001 = 1

000010 = 2

000100 = 4

001000 = 8

010000 = 16

100000 = 32

and added together they can indicate multiple states, in your case

001111 = 15

which, if you follow your eyes up to the table above, means that your window has traits 1, 2, 4 & 8 or in other words it exists, is visible, is enabled, and is active

Hope this helps with the debugging


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
StarsLikeDust

Hi Folks thanks for the idea and explination. Unfortuantly I don't think that is quite what I am looking for. NET Stop does indeed shut down the server however it seems to do so abruptly. Here is the command I was using for it:

Run ( @ComSpec & " /c" & 'NET Stop "4d: Server: ACUMEN_Struc_v7_6_66"', "", @SW_HIDE)

4d: Server: ACUMEN_Struc_v7_6_66 was found by following your suggestion Salty. Any other ideas? Or any idea why a simple WinClose on the window name of the program wouldn't work?

Share this post


Link to post
Share on other sites
PsaltyDS

I don't understand why a normal STOP is undesirable. Either by NET STOP, or WMI with $oSvc.StopService, it's the service's responsibility to respond correctly to that method.

What's the normal method of shutting this app down?

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
StarsLikeDust

I don't understand why a normal STOP is undesirable. Either by NET STOP, or WMI with $oSvc.StopService, it's the service's responsibility to respond correctly to that method.

What's the normal method of shutting this app down?

:(

Sigh, sorry about the time between posts I am working on this in my spare time. Basically the reason Net Stop is undesierable is that this software is rubbish. The reason I want it to shutdown is that the vendor told the folks here that the server this software runs on should be rebooted once a week. I didn't belive it at first and let the whole thing run for a couple weeks once. It does indeed start doing weird stuff. Since it's the method that the bookstore useses to keep track of sales and inventory I do want it to shutdown normally. The way we currently have to shut it down is this:

It runs as a service but we still have to login to the server and interact with the GUI for this thing. Ctrl + Q (or the file menu) brings up a dialogue box that also needs interacted with. (I know this place should get new software but i think it's unlikely they actually will...)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.