Jump to content

need to find suitable trigger to run script


aleph01
 Share

Recommended Posts

I have a situation in a library setting where PCReservation (PCR) creates sessions for patrons.  Launch Command is the software that creates the menus that the patrons can use.  If a patron uses PCR correctly, they start their session and they end their PCR session and the computer is ready for the next patron.  As in all public computer use, some patrons don’t  use the software as expected.  In this case, instead of logging off of PCR, they log off of or shut down Windows.  These are Windows 8 machines, so they get the “Logging Off” screen with the circling dots.  They think all is well and they walk away.  In the meantime, Windows 8 ( I thought) was closing all of the open programs (including PCR), but when it came to Launch Command (LC), it ran into the fact that we require a password to close LC so that patrons can’t just close it at any time during their session. When the window times out, windows offers a choice:  Close the Program or Cancel.  The patron doesn’t see this, having walked away thinking all is fine.  After about 40 seconds Windows defaults to Cancel.  Then the screen returns to Launch Command, the menu screen, and everything seems fine.  Fine, except PCR isn’t running.  I thought that this will be easy to script – use ProcessExists on the PCR process, and if it doesn’t exist, run the executable to start it.  I wrote such a script and it didn’t work.  Then I looked at the processes running after the failed log off.  The PCR process was still running, only in some background way – it wasn’t requiring a log in, the status bar was missing – in short, there was no indication that PCR was running at all, except that the process was still in the process list.

Thank you if you’ve had the patience to get to this point after my long background paragraph.  My question is:  how can I get a script to recognize the state the computer is in and start PCR?  Alternately, is there a way to have Windows “log off” or “shut down” to start a script, rather than go directly to logging off or shutting down?  Perhaps a better alternate is: does anyone have a better solution to this?

_aleph_

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

I would use local policy to block shutdown and restart options (fix the issue at its core w/o scripts)

If that does not work, instead of looking for a process, see if you can look for a window (If WinExists) that popup should be a good window to look for, and I assume that your program may have a GUI/Window of its own so if its closed that means it was exited so you could check for If Not WinExists() for that program window.

We use a kiosk software here too, and I do not care for it much.

I think the best way to go is a group policy that enforces a kiosk like state, and you can even do a lot of stuff with Autoit that helps enforce a kiosk environment.

No Shutdown.PNG

Edited by ViciousXUSMC
Link to comment
Share on other sites

Here is another function to consider:

Quote

_WinAPI_ShutdownBlockReasonCreate ( $hWnd, $sText )

This function can only be called from the thread that created the window specified by the $hWnd parameter,
otherwise, the function fails and the last error code is ERROR_ACCESS_DENIED (5).

You should be able to create your own GUI that exists while your app exists and block the shutdown with a message back to the user.

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Juvigy ,  what you suggest won't work because the opac user remains logged into Windows.  PCReservation runs under the opac profile and allows patrons to log into a session based on their library card number and PIN.  Use of a startup folder would require logging off Windows and back on.  Patrons should only be logging on and off of PCRes sessions and Windows stays logged on as the opac user.

232showtime , if you like...

While 1
    $i = ProcessExists("PCReservationClientService.exe")
    If $i = 0 Then Run("C:\Program Files (x86)\Envisionware\PC Reservation\Clientmodule\PC Reservation Client Module.exe")
    Sleep (10001)
WEnd

but it's not the script that's at fault, it's the fact that checking for the process is not a viable approach.

ViciousXUSMC, local policy would make the computers too hard to administer, but I like the idea of If NOT WinExists because the PCRes program basically covers the whole screen, blocking access until barcode and PIN are input, at which point a status bar with time left, etc. is created and lasts for the duration of the session.  So I'm thinking something like If NOT WinExists (main screen) AND NOT WinExists (status bar) Then...  since one or the other would always be present.

Jfish, _WinAPI_ShutdownBlockReasonCreate ( $hWnd, $sText )  wouldn't help when the patron tries to logs off of Windows.


Thanks all for the ideas.  It's comforting to know the Forum is here.

_aleph_

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

@aleph01 - How does it make the computer hard to administer?
That is kind of the joy is that it makes it hard for users, and not harder for administrators :)

Remote Restart/Shutdown, Scheduled Restart/Shutdown, Restart/Shutdown from the CMD Prompt Etc.

You can even hide an autoit script for shutdown and just double click it if you wanted.

Link to comment
Share on other sites

3 hours ago, aleph01 said:

Jfish, _WinAPI_ShutdownBlockReasonCreate ( $hWnd, $sText )  wouldn't help when the patron tries to logs off of Windows.

Well it can't stop them from choosing to do it anyway, but it can stop the logoff process and ask them if they really want to do it.  Run the below and try to logoff to test.  Stipulated not a perfect solution because they can still choose to logout but at least you can intervene,

#include <MsgBoxConstants.au3>
#include <WinAPISys.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("PLEASE DON'T LOGOFF THIS MACHINE", 615, 437, 192, 124)
GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Set the highest shutdown priority for the current process to prevent closure the other processes.
_WinAPI_SetProcessShutdownParameters(0x03FF)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_QUERYENDSESSION($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam

    Switch $hWnd
        Case $Form1
            _WinAPI_ShutdownBlockReasonCreate ($Form1, "PLEASE CANCEL YOUR LOGOFF" )
            If _WinAPI_ShutdownBlockReasonQuery($Form1) Then
                Return 0
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_QUERYENDSESSION

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

@aleph01,

if i read you correctly, your problem is that you must not allow logoff without closing the application.

if this is the only application being used (i.e. a dedicated workstation), then you can replace the Windows shell with your application. when user chooses to close the application and enter their application password for that, Windows displays the standard shutdown/restart/logoff dialog, which will occur after the application was closed. the concept of shell replacement consolidates the closing of the application with the end of the session, i.e. binds them together as a single operation.

i never tried it on Windows 8 - and i'm not going to - but you can google "replace windows shell with application" you'll find plenty of info on how it's done, and it's quite simple. also Windows 10 has a feature titled Shell Launcher which does just that, formally.

if this is NOT the only application in use, you can write a simple menu application, that allows running shortcuts, command prompt, etc. - whatever you are using. the wrapper can also monitor the application, and close itself when the application closes.

another (completely different) option would be to set-up a special, admin-level password for closing the application, and set-up a scheduled task to be triggered at logoff, that will send the "Close" signal to the application and use that password to close it gracefully. not sure it's going to work - most likely it's not, but you can check.

 

@ViciousXUSMC,

3 hours ago, ViciousXUSMC said:

How does it make the computer hard to administer

i think his workstations are not in a domain, so using LGPO rather than GPO makes it somewhat tedious of a task. of course, i hope he has some kind of remote management ability, because he's going to need it... eventually.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

You said the problem is :

Quote

In this case, instead of logging off of PCR, they log off of or shut down Windows. 

So if you put your script to kill PCR process and start it again after the kill, then put the script in the startup/logon folder , it should solve that problem, because the svript will be executed every time a user logs on to windows.

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