I am building a vb.net application which monitors external process and kills the process based on certain conditions. The application works great with monitoring .exe process but i m unable to use it with control pannel items.
Suppose a user launches programs and features , I want my vb.net app to detect it and kill it. Under task manager the process is shown as explorer.exe.
I can successfully launch programs and features using Process.Start(System.Environment.SystemDirectory + "\appwiz.cpl")
but i cannot kill it this way, can anyone tell me how i could kill this process??
Thanks!
You can use the following:
Process.Start("taskkill.exe /im explorer.exe")
Just replace explorer.exe with the process you wanna stop/kill...
Also works with the PID (Process ID):
Process.Start("taskkill.exe /pid /*yourPID*/")
Do not kill applications until there is other way to exit them.
It is like finishing your day by instantly turning off your computer.
First, at least ask applications to close themselves:
Please see Microsoft article How to use Visual Basic .NET or Visual Basic 2005 to close another application how to implement closing request.
Also please have a look at this Q&A how to prevent application to be uninstalled by a user (w/o admin rights)?.
Related
I'm developing a program in mono/C# which will run on a Linux embedded platform with a touch-screen.
I've installed OpenBox in top of Raspbian, because this will run in "kiosk mode" and I'm trying to keep it as simple as possible.
I was planning to have two options in the program:
option to shutdown the computer
option to close the windows manager (openbox) and return to the terminal
For the first option I've tried using:
shutdown
poweroff
systcl poweroff
commands but all require special privileges, so I'm not sure on what would be the best approach. Should I create a bash script with root privileges and run this script from the program?
For the second option, I don't even know how to start. I've configured openbox to be able to close it from the keyboard through Ctrl + Alt + Backspace, but I know how to close it from the program.
I've tried using SendKeys with that key combination but does not work.
I've also tried the solution here using DBUS for C# but I've issues compiling it.
Could you please give any advice?
You can set your sudo program up to let a user run a program without any password.
Add to your visudo file:
<username-or-ALL> ALL=(ALL) NOPASSWD:/sbin/poweroff
See this maybe
If I were you, I would reboot after setting up and before testing.
I want to create a program that won't close when you click the close button but, only when a exit function is run from within the form.I was thinking i could have it run in the background without the window needing to be open (Like the steam client and dropbox, mediafire, google drive, google chrome extension notification), and was wondering how to do that.
I was thinking of some ways to do it but i wasn't sure how to do them:
A starter program that keeps it open in the background
Running a background process that keeps information stored
I am running c# 2010 so i will need answers relating to that. I would also prefer to not use 3rd party extensions/tools except a basic text editor(Notepad++).Thank you in advance!
There are a number of possible options:
Hide the main form
Create a Tray application
Write a Windows Service
I have 2 programs. I want to build an external tool, which prevents one of the programs from starting, when the other program is already running, and vice versa.
I can't touch the code of either of the two programs.
I want to do it preferably with C#, but a scripting language will also be ok.
Can anyone help me with the concept how to implement it?
Thanks in advance.
Write your tool as a windows service that keeps running in background and kills the second program if it starts. It can find out when a new process starts by listening to WMI events see .NET Events for Process executable start
There are couple of ways to do that. If you are using C# you should be getting the process name using the GetProcessesByName(). It would look something like this
Process[] processes = Process.GetProcessesByName(processName);
If you know the process name you can just kill the process
Or else use the [Semaphore Class] (http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx).
I'm starting a external application with System.Diagnostics.Process, this external process at one moment opens up a dialog where user has type something and then click OK. What i need is to wait with my application(the one where i started the external process) until the user has inserted something and clicked OK. After that OK i have to do some more task on that external process and then close it.
Yes, it's possible. There are a number of ways to get window information starting with a process handle and/or ID. See this question and responses for getting started. You will most likely end up using P/Invoke to the Win32 API to get this accomplished but there are dozens of good examples for getting this done.
Once you have the window handle you can use a timer polling scheme to test for the presence, or in your case, presence and then the disappearance of a window.
This is possible but there are some work behind it. First you need to run your code as unmanaged code as you will need to hook on Windows OS events with the Win32 API.
So an option would be to have a loop looking for the dialog to open, pause what ever your code are doing and continue when the dialog are gone.
If the application you are starting exists after the user interacts with the dialog, then you can just call Process.WaitFroExit() and your code will not continue until the process you started has quit.
There are quite a few helpful functions for interacting with processes in the System.Diagnostics.Process class (that I assume you are using to start this external application)
Okay I've spent the afternoon researching and haven't had much luck finding the answer to this. I am trying to prevent an application from launching via some sort of dll or background application. It is to be used in monitoring application usage and licenses at my institution. I have found leads here regarding WqlEventQuery and also FileSystemWatcher. Neither of these solutions appear to work for me because:
With WqlEventQuery I was only able to handle an event after the process was created. Using notepad as a test, notepad was visible and accessible to me before my logic closed it. I attempted to Suspend/Resume the thread (I know this is unsafe but I was testing/playing) but this just hung the window until my logic finished.
With FileSystemWatcher I was not able to get any events from launching a .exe, only creating, renaming and deleting files.
The goal here is to not let the application launch at all unless my logic allows it to launch. Is this possible? The next best solution I came up with was forcing some type of modal dialog which does not allow the user to interact with anything, once the dialog is closed the application is killed. My concern here is killing the application nicely and handling applications with high overhead when they load such as Photoshop or something. This would also interfere with a feature I was hoping to have where the user could enter a queue until a license is available. Is this my best route? Any other suggestions?
Thanks
edit: To clarify this is not a virus or anything malicious. It's not about preventing access to a blacklist or allowing access through a whitelist. The idea is to check a database on a case by case basis for certain applications and see if there is a license available for use. If there is, let the app launch, if not display a dialog letting the user know. We also will use this for monitoring and keeping track if we have enough licenses to meet demand, etc. An example of one of these apps is SPSS which have very expensive licenses but a very limited pool of people using it.
Could you use
System.Diagnostics.Process.GetProcessesByName
in a loop to look for the process?
It might work if you don't use too aggressive a polling rate.
You are indeed close, take a look at the WMI Management Events. http://msdn.microsoft.com/en-us/library/ms186151%28VS.80%29.aspx
Sample code from Microsoft: http://msdn.microsoft.com/en-us/library/ms257355(VS.80).aspx
Subscribing to the appropriate event will provide your application with the appropriate information to perform what you described.
Not sure if this is a GOOD solution but you could do something like pass a key into main so that if the key is not present or valid the application shuts down. Then when you open the application in your code, just pass the key in. Someone would then have to know the key in order to start the application.
This is assuming you have access to the application in question's source code, which upon reading your question again, I'm not so sure of.
I assume you don't have source for the application you want to prevent from loading...
Have you considered using a system policy? That would be the best-supported way to prevent a user from launching a program.
You could have a service running that force-kills any app that isn't "whitelisted", but I can't say how well that would work.
I wonder if you are taking the wrong approach. Back in the day there was a Mac app that would prevent access to the desktop and had buttons to launch a set list of applications.
IDEA
What if you had a wrapper for the approved apps then only allow your wrapper to run on the computer?
I would expect there is some way of hooking an application launch, but can't help directly on that front.
You may be able to improve your current approach by detecting the application's window opening and hiding it (move it offscreen) so that the user can't attempt to interact with it while you are trying to shut it down.
However, another approach that may be possible (depending on your circumstances) would be to write an application launcher. This simply is a replacement for the shortcut to the application that checks your licencing conditions, and then does a Process.Start to launch the real .exe at that point. This would work well for any application. (I used a system like this for starting up applications with specialised environment settings and it works beautifully)
You could combine this with your current approach as a fall-back for "clever" users who manage to circumvent your launcher.
If my understanding is right you want to create an application what will prevent the computer user to start any other process except ones for a white-list.
If this is the case, monitor the process list of processes (in a while loop) using System.Diagnostics.Process (the GetProcesses method gives the list of all running ones)
Just kill the process when it starts.
Or if your machines have Windows 7 (Windows 2008??) you can use AppLocker. http://www.microsoft.com/windows/enterprise/products/windows-7/features.aspx#applocker Just let Windows prevent the startup.
You might want to look at this product: http://www.sassafras.com/licensing.html Personally I can't stand it, but that's because it does what you describe. Might save you some coding.
You could actually edit the registry so when you click a psd, your launcher gets called instead of photoshop. Your launcher then checks for licenses and if there is one starts photoshop with the path of the file.
This is a long shot but you may find it helpful.
Perceived Types and Application Registration
http://msdn.microsoft.com/en-us/library/cc144150(VS.85).aspx