Limiting program instances or processes, Unrealted to FOG, but still imaging Related
-
[url]https://bitsum.com/processlasso/[/url]
This looks interesting… it does have the ability to limit processes! Unfortunately it doesn’t exactly work lol. Anything else someone has up their sleeve
-
tried autoit? different ways u cud do it… execute chrome within autoit.exe or have autoit watch in the background if process number over set limit, close last process and could do message prompt… all sorts, limit is endless.
simple approach would be:
#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>If _Singleton(“chrome”, 1) = 0 Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Else
ShellExecute(@ProgramFilesDir & “\Google\Chrome\Application\chrome.exe”)
EndIfcompile that to .exe (even give it a relevant icon if u want even call it chrome etc)
only downside is, u would need to remove all chrome shortcuts and make sure they run this instead. the other option as i say wud to have an .exe run at startup doing the same thing but on trigger events or loop so:
While 1
Do
sleep (500)
Until ProcessExist(“chrome.exe”) = 1Do stuff, close, msg prompt etc etc etc
-
[quote=“Lee Rowlett, post: 41495, member: 28”]tried autoit? different ways u cud do it… execute chrome within autoit.exe or have autoit watch in the background if process number over set limit, close last process and could do message prompt… all sorts, limit is endless.
simple approach would be:
#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>If _Singleton(“chrome”, 1) = 0 Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Else
ShellExecute(@ProgramFilesDir & “\Google\Chrome\Application\chrome.exe”)
EndIfcompile that to .exe (even give it a relevant icon if u want even call it chrome etc)
only downside is, u would need to remove all chrome shortcuts and make sure they run this instead. the other option as i say wud to have an .exe run at startup doing the same thing but on trigger events or loop so:
While 1
Do
sleep (500)
Until ProcessExist(“chrome.exe”) = 1Do stuff, close, msg prompt etc etc etc[/quote]
Thanks I will play with this today!
Hmm It still opens multiple windows of chrome. I can open a crap load of windows still. The script opened chrome though. I’m new to AutoIT but I’m going to be playing with this a bit and hopefully coerce it to my needs
-
Inline with what Lee said, AutoIT is a fantastic scripting language. I would actually recommend checking out singleinstance, its a free application (built on AutoHotKey), that does exactly what you want. The source code is available for viewing so you can customize it as needed.
This site includes a download link and the usage of the program
[url]http://www.freewaregenius.com/singleinstance-allow-only-one-running-instance-of-a-program/[/url] -
i’m also a big fan of AutoHotKey and AutoIT, but i’m not sure if “single instance” will work for chrome, since it launches multiple processes for a single window. if you try it, let us know if it works.
-
[quote=“Jbob, post: 41522, member: 21733”]Inline with what Lee said, AutoIT is a fantastic scripting language. I would actually recommend checking out singleinstance, its a free application (built on AutoHotKey), that does exactly what you want. The source code is available for viewing so you can customize it as needed.
This site includes a download link and the usage of the program
[url]http://www.freewaregenius.com/singleinstance-allow-only-one-running-instance-of-a-program/[/url][/quote]I tried that SingleInstance program already
I am fond of that onehourcode site, I already use some of the applications on there, but they seem mostly tailored towards Windows 95 and such.
SingleInstance had no affect, I was able to open 20 windows
-
Not sure if this is proper or not, hopefully you guys will help me find my holes if I left any
Of course I still need to rename my “chrome.exe” and replace it with what I am going to call it, but this works with chrome.exe, I could just hide the shortcuts but I know my students will look for the chrome.exe in the folders, I need to obfuscate it a bit… maybe I will move it someplace like windows or system32…
AutoIT code
[code]
#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>Opt(“RunErrorsFatal”, 0)
While 1
If Not ProcessExists(“chrome.exe”) Then
ShellExecuteWait(@ProgramFilesDir & “\Google\Chrome\Application\chrome.exe”)
If Not @error Then Exit
EndIf
If ProcessExists(“chrome.exe”) Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Exit
EndIf
Sleep (30)
WEnd
[/code] -
RunErrorsFatal is obselete and has been for sometime - might aswell remove it but part from that, first glance, all looks good to me…
[SIZE=5][B][FONT=Segoe UI][COLOR=#db7100]16th May, 2008 - v3.2.12.0[/COLOR][/FONT][/B][/SIZE]
[SIZE=13px][FONT=Segoe UI][COLOR=#000000][B]AutoIt:[/B][/COLOR][/FONT][/SIZE]
[LIST]
[*]The option [URL=‘https://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htm’][COLOR=#03697a]RunErrorsFatal[/COLOR][/URL] has been removed. [URL=‘https://www.autoitscript.com/autoit3/docs/functions/Run.htm’][COLOR=#03697a]Run()[/COLOR][/URL], [URL=‘https://www.autoitscript.com/autoit3/docs/functions/RunWait.htm’][COLOR=#03697a]RunWait()[/COLOR][/URL], [URL=‘https://www.autoitscript.com/autoit3/docs/functions/ShellExecute.htm’][COLOR=#03697a]ShellExecute()[/COLOR][/URL] and [URL=‘https://www.autoitscript.com/autoit3/docs/functions/ShellExecuteWait.htm’][COLOR=#03697a]ShellExecuteWait()[/COLOR][/URL] now all set @error when they fail to run the application. AutoIt will no longer throw a fatal error when an application fails to run.
[/LIST] -
Sorry if it sounds like i’m preaching/patronising, dont mean to - just want to give a lil’ help where i can
You could remove the Sleep(30) as every scenario your exiting so sleep not needed, also While 1 WEnd basic overview means to loop the code in between.
i.e.
[SIZE=13px][COLOR=#000000][FONT=Courier New][URL=‘https://www.autoitscript.com/autoit3/docs/keywords/While.htm’][COLOR=#03697a][COLOR=blue]While[/COLOR][/COLOR][/URL][COLOR=#2a2a2a]$i[/COLOR][URL='https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm’][COLOR=#03697a][COLOR=#ff8000]<=[/COLOR][/COLOR][/URL][COLOR=blue]10[/COLOR][/FONT][/COLOR][/SIZE]
[COLOR=#000000][SIZE=13px][FONT=Courier New][URL=‘https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm’][COLOR=#03697a][COLOR=#000090]MsgBox[/COLOR][/COLOR][/URL][COLOR=#ff8000]([/COLOR][COLOR=#2a2a2a]$MB_SYSTEMMODAL[/COLOR][COLOR=#ff8000],[/COLOR][COLOR=red]“”[/COLOR][COLOR=#ff8000],[/COLOR][COLOR=red]"Value of $i is: "[/COLOR][COLOR=#ff8000]&[/COLOR][COLOR=#2a2a2a]$i[/COLOR][COLOR=#ff8000])[/COLOR][/FONT][/SIZE][/COLOR]
[COLOR=#000000][SIZE=13px][FONT=Courier New][COLOR=#2a2a2a]$i[/COLOR][URL=‘https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm’][COLOR=#03697a][COLOR=#ff8000]=[/COLOR][/COLOR][/URL][COLOR=#2a2a2a]$i[/COLOR][URL='https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm’][COLOR=#03697a][COLOR=#ff8000]+[/COLOR][/COLOR][/URL][COLOR=blue]1[/COLOR][/FONT][/SIZE][/COLOR]
[COLOR=#000000][SIZE=13px][FONT=Courier New][COLOR=blue][URL=‘https://www.autoitscript.com/autoit3/docs/keywords/While.htm’][COLOR=#03697a]WEnd[/COLOR][/URL][/COLOR][/FONT][/SIZE][/COLOR]so increase $i until it reaches 10. your code only runs through once so remove While 1 WEnd.
you don’t really need if not @error then exit statement as it will exit anyway.
other thing you don’t need to tell autoit to exit, only time you really need to tell it to exit is when there’s further code or what you want to achieve is “complete” so you’re telling it “stop here” autoit just “executes” code from top to bottom regardless so if there’s no further code or the statements below will not be matched then exit not needed.
also i prefer to use positive (if) rather than false positive (if not) as sometimes can give mixed results so i’d change your code to:[CODE]#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>If ProcessExists(“chrome.exe”) Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Else
ShellExecuteWait(@ProgramFilesDir & “\Google\Chrome\Application\chrome.exe”)
EndIf[/CODE]should get same results.
p.s. i hadn’t actually ever tried the _Singleton funcion… glad to know it DOESNT work lol! -
…But like junkhacker said - this probably won’t work or you might run into trouble for chrome as there is more than one process for a single instance and if chrome doesn’t close successfully you’d have to physically kill it for you to be able to run this code again? you could get it ask user if they want to close previous instance if it exists to give you complete control?
if so, look at InputBox function
one last thing - if you’re just starting out with autoit install [SIZE=13px][FONT=Open Sans][COLOR=#1c1c1c]SciTE … Syntaxcheck prod and tidy autoit source will help a bundle (Tools->SyntaxCheckProd or Tools->Tidy Autoit Source)[/COLOR][/FONT][/SIZE]
[url]https://www.autoitscript.com/site/autoit-script-editor/downloads/[/url]
-
Thank for your input, you’re right I can slim it down to
[quote=“Lee Rowlett, post: 41539, member: 28”]
[CODE]#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>If ProcessExists(“chrome.exe”) Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Else
ShellExecuteWait(@ProgramFilesDir & “\Google\Chrome\Application\chrome.exe”)
EndIf[/CODE]should get same results.
p.s. i hadn’t actually ever tried the _Singleton funcion… glad to know it DOESNT work lol![/quote]Without much of an issue. I had a recommendation to use a while loop to help accommodate that singleton function, then I moved awya from singelton to the ProcessExists. This week I have some more time to play around with it a bit.
I plan to actually change chrome.exe to something garbled such as qweljklewr and drop off the extension, I’m going to see if I can’t get the script to copy the file and rename it to something.exe an run it from there. Chrome only likes to work if it’s in the correct directory, but if I leave it a .exe the students will find it, this could help deter them from finding my file.
I’ll keep playing with it. Right now it doesn’t seem like many are interested in limiting chrome, this could be beneficial to someone in the future!
-
This seems to work nicely.
[code]
#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>
$str = “.exe”If ProcessExists(“chrome.exe”) Then
MsgBox(64, “Warning”, “Only one instance is allowed”)
Else
FileMove(@ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl”, @ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl” & $str)
ShellExecuteWait(@ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl.exe”)
FileMove(@ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl.exe”, @ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl”)
EndIf
[/code]Still tweaking, I am thinking about hosting my main chrome.exe file outside of the google folders to help prevent users from stumbling upon the file!
-
do your students have admin rights on these devices?
[url]http://www.askvg.com/the-best-method-to-hide-files-folders-in-windows-without-using-3rd-party-utilities/[/url]warning you will have issues with regedit until you renable it in your gpo. If you wish to edit the registry after imaging.
-
[quote=“Wolfbane8653, post: 41566, member: 3362”]do your students have admin rights on these devices?
[url]http://www.askvg.com/the-best-method-to-hide-files-folders-in-windows-without-using-3rd-party-utilities/[/url]warning you will have issues with regedit until you renable it in your gpo. If you wish to edit the registry after imaging.[/quote]
Yes all basic users that are logged in are admins.
I almost had a variant working that launched files without extensions, I still need to tweak it a bit.
-
don’t forget that those students can always right click and “open file location” for shortcuts
[url]http://www.sevenforums.com/tutorials/236988-open-file-location-add-remove-context-menu.html[/url]
-
even more robust use FileInstall… that way you don’t have to have it anywhere on the machine, won’t be there unless executed so will give less chance of users finding it ;-)… also means they cannot delete it ;-).
it will embed into the .exe and will extract when executed and once you’re done just delete so… it also means you don’t rely on the file being in a certain location (so if deleted, don’t matter just put it back next time it runs :-D). only few limitations - is you have to make sure you’re .exe source is in the location you specify when compiling and the source cannot contain variables and if it’s a “large” file you’re embedding it’s slugish/freezes part from that all good!
change First Filemove to:
FileInstall([FONT=Consolas]“C:\Temp\MyScript\asdfghjkl.exe”, @ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl.exe”, 1)[/FONT]
2nd Filemove to:
FileDelete([FONT=Consolas]@ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl.exe”)[/FONT]
-
[quote=“Wolfbane8653, post: 41570, member: 3362”]don’t forget that those students can always right click and “open file location” for shortcuts
don’t do it as a shortcut… have it as an .exe within an .exe so .exe on desktop extract the .exe into chrome folder and executes it, waits for it to finish and then deletes.
-
[quote=“Lee Rowlett, post: 41572, member: 28”]don’t do it as a shortcut… have it as an .exe within an .exe so .exe on desktop extract the .exe into chrome folder and executes it, waits for it to finish and then deletes.[/quote]
I won’t use a shortcut, I can’t trust these kids, I almost ran chrome in kiosk mode but decided it wasn’t worth my effort, at least with AutoIT they think it is chrome.exe and they aren’t any wiser.
I was not able to use your FileInstall recommendation, for some reason after I compile it and run the .exe, it claims the program is already running, when it is not. It only, renames the file or moves it when I run the .a3u and not the .exe.
-
I think this is the code I am going to use.
[code]
#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>Opt(“RunErrorsFatal”, 0)
While 1
If ProcessExists(“asdfghjkl”) Then
MsgBox(64, “Warning”, “Please close the current window before opening another!”)
Exit
Else
Run(@ProgramFilesDir & “\Google\Chrome\Application\asdfghjkl”, “”, @SW_HIDE)
If Not @error Then Exit
EndIf
WEnd
[/code]This seems to work well, I have renamed chrome.exe to asdfghjkl and with the script I am able to execute the file. I compile my script as chrome.exe with the chrome Icon.
-
Wanted to add that my chrome script is working flawlessly.
Something I forgot to take into consideration was the hotkeys chrome uses.
Users can still launch an incognitio window with Ctrl+Shift+N and they can launch a new window with Ctrl+N.
I wrote another script for Auto IT that will block these key commands.
Does anyone know how to limit the blocking to the Chrome sessions only?
Until then I am going to leave the Alt+F4 key alone, it is still useful in other cases.
[code]
#NoTrayIcon
HotKeySet(“^n”, “_SarlaccPit”)
HotKeySet(“^N”, “_SarlaccPit”)
HotKeySet(“^t”, “_SarlaccPit”)
;HotKeySet(“!{F4}”, “_SarlaccPit”)While 1
Sleep(500)
WEndFunc _SarlaccPit()
EndFunc[/code]
Right now I compiled this as an exe and it runs at startup