Recently I was tasked with ensuring certain users can only use Program A or Program B at one time. The question of "....but why though?" has already been asked and despite it really not making a security difference I was told to make it happen anyway just as a placebo.
I came up with a solution by replacing the .lnk files on the desktop / start menu with powershell scripts that will check to see if the "close" application is open and close it, then launch the other application. My script is as follows:
# should be executed like this:
# powershell.exe -executionpolicy bypass -windowstyle hidden -file "c:\path\to\script.ps1" -close "name_of_process_to_close.exe" -open "C:\path\to\application\to\open.exe"
param(
$close = $null,
$open = $null
)
$closeproc = get-process | where {$_.name -match $close}
if($closeproc -ne $null){
foreach($proc in $closeproc){
$closecount = 0
while(!($proc.HasExited)){
$proc | stop-process -force
if($closecount -gt 10){
Add-Type -AssemblyName PresentationCore,PresentationFramework
[System.Windows.MessageBox]::Show("Unable to close $close. Please close $close before launching $open")
exit
}
$closecount++
}
}
}
. $open
One of the issues with this is the user could just search for the application in the start menu and launch it that way. As an alternative to my above solution I was thinking about configuring a scheduled task that launches on startup and checks every so often to see if both of these applications are running and prompt the user to close one.
Question
satukoro
Recently I was tasked with ensuring certain users can only use Program A or Program B at one time. The question of "....but why though?" has already been asked and despite it really not making a security difference I was told to make it happen anyway just as a placebo.
I came up with a solution by replacing the .lnk files on the desktop / start menu with powershell scripts that will check to see if the "close" application is open and close it, then launch the other application. My script is as follows:
One of the issues with this is the user could just search for the application in the start menu and launch it that way. As an alternative to my above solution I was thinking about configuring a scheduled task that launches on startup and checks every so often to see if both of these applications are running and prompt the user to close one.
Link to comment
https://www.neowin.net/forum/topic/1435075-close-one-application-when-another-opens/Share on other sites
0 answers to this question
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