mechpro Posted March 17, 2016 Posted March 17, 2016 (edited) Hello, We have a script we use for kiosk machines that simply displays a GUI box that warns the user that it will close and re open firefox unless a button is pressed. If the button (cancel) is pressed, the script is canceled. It used to work perfectly fine for our Windows 7 machines but the script doesn't work for Win 10 machines. The gui box comes up without a problem but it fails to close and reopen firefox. Currently, this script uses mouse coordinates and we pin firefox in the taskbar - to the right of both, the search box and the desktop switcher icons. Does AutoIT allow to open a program such as firefox without having to use the mouse coordinate feature? Perhaps by specifying to the path of the firefox shortcut location? Or does Autoit not work for Win 10? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $i = 30 Global $e = 0 Global $Label2 $Form1 = GUICreate("Session Timeout", 306, 133, -1, -1) $Button2 = GUICtrlCreateButton("Cancel", 104, 96, 89, 33) $Label2 = GUICtrlCreateLabel("", 128, 72, 49, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Due to inactivity this computer will reset soon.", 42, 16, 224, 17) $Label3 = GUICtrlCreateLabel("Press cancel before time runs out to abort the reset.", 28, 48, 252, 17) GUISetState(@SW_SHOW) AdlibRegister("_Update", 1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Exit EndSwitch WEnd Func _Update() GUICtrlSetData($Label2, StringFormat("%02d:%02d", $e, $i)) $i -= 1 If $i < 0 Then $i = 0 $e -= 1 If $e < 0 Then Call("closefirefox") Call("openfirefox") Call("delete") Exit EndIf EndIf EndFunc ;==>_Update Func delete() $sPath = "C:\Users\user1\Downloads" FileDelete($sPath & "\*.*") $folderlist = _FileListToArray($sPath, "*", 2) If Not @error Then For $j = $folderlist[0] To $folderlist[1] Step -1 DirRemove($sPath & "\" & $folderlist[$j], 1) Next EndIf EndFunc ;==>delete Func closefirefox() While ProcessExists("Firefox.exe") ProcessClose("Firefox.exe") WEnd EndFunc ;==>closefirefox Func openfirefox() Sleep(250) MouseClick("left", 73, 1024, 1, 0) Sleep(100) MouseMove(@DesktopWidth / 2, @DesktopHeight / 2, 0) EndFunc ;==>openfirefox Edited March 17, 2016 by Melba23 Added code tags
Moderators Melba23 Posted March 17, 2016 Moderators Posted March 17, 2016 mechpro, Welcome to the AutoIt forums. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BrewManNH Posted March 17, 2016 Posted March 17, 2016 Run or ShellExecute is the function you're looking for. 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 GudeHow 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
InunoTaishou Posted March 17, 2016 Posted March 17, 2016 (edited) ; Get the path to firefox.exe Global Const $sFireFox = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe","") ; Close firefox closefirefox() ; Re-open firefox ShellExecute($sFireFox, "") ; Delete delete() ; Exit script with 0 errors Exit 0 I'd also look into using a timer instead of a counter ; Timeout, in seconds Global const $TIMEOUT = 30 Global $iTimerInit = TimerInit() Func _Update() Local $iDiff = TimerDiff($iTimerInit) Local $iMilis = (($TIMEOUT * 1000) - $iDiff) / 1000 Local $iSecsRemain = Mod($iMilis, 60) Local $iMinsRemain = Mod($iMilis / 60, 60) Local $iHoursRemain = Floor($iMilis / 60 ^ 2) If (Int($iSecsRemain) <= 0) Then closefirefox() ShellExecute($sFireFox, "") delete() Exit 0 Else GUICtrlSetData($lblTime, StringFormat("%02i:%02i", $iMinsRemain, $iSecsRemain)) EndIf EndFunc ;==>_Update A little more accurate and add support for always being able to keep the program open. Once you close firefox and restart it you can reinitialize the $iTimerInit with a new timer returned from TimerInit() Edited March 17, 2016 by InunoTaishou
mechpro Posted March 18, 2016 Author Posted March 18, 2016 Hello All, I wanted to give an update -- I included the suggestions and modified the script. The script startsa GUI with a count down timer, and launches/closes Firefox. However, after launching firefox the background stays black (if you close firefox and move the mouse the black screen disappears. It appears to be the black screen that comes on during a screen saver) I included a mouse click and mouse move to see if perhaps I could get that black screen to go away before launching but it remained. The script works perfectly fine if launched as an exe but not as a screen saver. I wasn't sure how to incorporate the suggestions from InunoTaishou. Any chance anyone could give this a try on Windows 10? Or see how to get rid of the black screen that obscures the desktop automatically instead of having to manually move the mouse? expandcollapse popup;============================================ ;Thomas Vu ;10/20/13 ;Purpose: Kiosk Mode for Library Desktops ;============================================ #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> Global $i = 30 Global $e = 0 Global $Label2 $Form1 = GUICreate("Session Timeout", 306, 133, -1, -1) $Button2 = GUICtrlCreateButton("Cancel", 104, 96, 89, 33) $Label2 = GUICtrlCreateLabel("", 128, 72, 49, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Due to inactivity this computer will reset soon.", 42, 16, 224, 17) $Label3 = GUICtrlCreateLabel("Press cancel before time runs out to abort the reset.", 28, 48, 252, 17) GUISetState(@SW_SHOW) AdlibRegister("_Update", 1000) ; Get the path to firefox.exe Global Const $sFireFox = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe","") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button2 Exit EndSwitch WEnd Func _Update() GUICtrlSetData($Label2, StringFormat("%02d:%02d", $e, $i)) $i -= 1 If $i < 0 Then $i = 0 $e -= 1 If $e < 0 Then call ("closefirefox") call ("openfirefox") Exit EndIf EndIf EndFunc func closefirefox () While Processexists( "Firefox.exe" ) processclose ( "Firefox.exe" ) WEnd EndFunc func openfirefox () sleep (250) mouseclick ("left", 462, 1022, 1, 0) MouseMove(@DesktopWidth/2, @DesktopHeight/2, 0) sleep (100) ShellExecute($sFireFox, "") EndFunc Exit 0
InunoTaishou Posted March 18, 2016 Posted March 18, 2016 I don't know how to toggle the screen saver but this is what I meant. (And works on Windows 10, because that's what I'm on) expandcollapse popup#include <GUIConstants.au3> Global $Label2 ; Timeout in seconds Global Const $TIMEOUT = 30 Global $iTimerInit = TimerInit() $Form1 = GUICreate("Session Timeout", 306, 133, -1, -1) $Button2 = GUICtrlCreateButton("Cancel", 104, 96, 89, 33) $Label2 = GUICtrlCreateLabel("", 128, 72, 49, 24) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $Label1 = GUICtrlCreateLabel("Due to inactivity this computer will reset soon.", 42, 16, 224, 17) $Label3 = GUICtrlCreateLabel("Press cancel before time runs out to abort the reset.", 28, 48, 252, 17) GUISetState(@SW_SHOW) AdlibRegister("_Update", 200) ; Get the path to firefox.exe Global Const $sFireFox = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe", "") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Exit EndSwitch WEnd Func _Update() Local $iDiff = TimerDiff($iTimerInit) ; Timeout + 1 because there are still 1000miliseconds on the 0 second and we're converting the floating value to an int in the If statement below ; Dropping that extra second Local $iMilis = ((($TIMEOUT + 1) * 1000) - $iDiff) / 1000 Local $iSecsRemain = Mod($iMilis, 60) Local $iMinsRemain = Mod($iMilis / 60, 60) Local $iHoursRemain = Floor($iMilis / 60 ^ 2) If (Int($iSecsRemain) <= 0) Then closefirefox() ShellExecute($sFireFox, "") Exit 0 Else GUICtrlSetData($Label2, StringFormat("%02i:%02i", $iMinsRemain, $iSecsRemain)) EndIf EndFunc ;==>_Update Func closefirefox() While ProcessExists("Firefox.exe") ProcessClose("Firefox.exe") WEnd EndFunc ;==>closefirefox
mechpro Posted March 18, 2016 Author Posted March 18, 2016 Thank you - I'll continue playing with it, hopefully someone else also chimes in regarding toggling the screensaver black screen that comes on when you turn this script into screensaver.scr
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now