I'm writing an app in C# to prevent some executable file from opening. My app will detect opening selected executable file and show message box to let user choose to run it or not.
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="calc.exe"
I have use above method from This topic but it will block all executable file with that name from any path. Which I want is to block only executable file in flashdrive or specifed path.
Example. I selected that my program will show message box when "a.exe" in Drive F:/ is opening. If I use a method in reference topic, it will block all "a.exe" in any path like "C:/a.exe", "D:/a.exe" or "F:/a.exe" but I want it to block only a.exe in F:/ not in other path or drive.
Any idea for this?
Thanks a lot.
I have a similar point in a blog article where I try to detect the creation and destruction of a process instance. For this I use ManagementEventWatcher and this class uses queries like
internal ManagementEventWatcher WatchForProcessStart(string ProcessName)
{
string Query = "SELECT TargetInstance" +
" FROM __InstanceCreationEvent " + "WITHIN 2 " +
" WHERE TargetInstance ISA 'Win32_Process' " +
" AND TargetInstance.Name = '" + ProcessName + "'";
string Scope = "\\\\.\\root\\CIMV2";
ManagementEventWatcher Watcher = new ManagementEventWatcher(Scope, Query);
Watcher.Start();
return Watcher;
}
The scope is a ManagementScope instance which can be manipulated for your purposes as seen at MSDN
ManagementScope scope =
new ManagementScope(
"\\\\FullComputerName\\root\\cimv2");
scope.Connect();
I hope this helps you a bit. More information
http://msdn.microsoft.com/en-us/library/system.management.managementscope.aspx
http://www.idipous.net/how-to-monitor-proccess-creation-with-c/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With