I have a good working experience with C# but now I want to develop a simple(may be a console app) software which just detects the name and time of the process started or ended on my computer.
For example (I am assuming that my small app is already running) if a user opens Firefox then it should just insert firefox.exe into a database with time and if a user close it then it also do the same.
And same as above if a user open notepad then it should insert notepad.exe with time and so on.
I know how to insert values in database but I just need your help in identifying when the process/program starts or ends on my system.
Honestly saying I never developed this kind of application before so i have no idea that it can be possible using console app or i need to make a windows service app etc.
So please provide your answer just considering me as a beginner.
In the part of C# I am able to understand it so need to worry about that.
I am using visual studio 2010 with .net 4.0.
To do this without polling requires WMI. This is well supported in .net and you can use the ManagementEventWatcher class to subscribe to WMI notifications.
This Code Project article illustrates how it is done. Here's an extract showing how straightforward it is.
notePad = new ProcessInfo("notepad.exe");
notePad.Started +=
new Win32Process.ProcessInfo.StartedEventHandler(this.NotepadStarted);
notePad.Terminated +=
new Win32Process.ProcessInfo.TerminatedEventHandler(this.NotepadTerminated);
Note that ProcessInfo is a class implemented in the code attached to that article.
Related
I need to develop a project using Visual Studio. The project will run constantly in the background, checking a file path. When the image is uploaded to the file path, the application will display the uploaded image as a pop-up on the computer screen. The application will not be triggered by a user. It will constantly run in the Background, checking the file path. Which project template should I use for this? I hope I was able to explain.
I thought of writing windows service. Because it can run in the background. But I couldn't open a picture with it
I see you're a new contributor, so it would be better if you posted a bit more context of what you have already tried. For instance, providing a minimal reproducible example. I ask you this because the way to write Windows Services or Console Applications in .Net Framework and .Net Core (and subsequent) are different. How to ask a question?
That being said, a windows service, by concept, does not have UI and is not allowed to have one. They're designed precisely to only run on the background, without user interaction (at least since Windows Vista).
These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface.
From Microsoft Docs
So it seems that you need to either write your application as a different kind (for example), or create a secondary application that somehow communicates with your windows service. The decision would be up to you based on your requirements and/or possible limitations.
There are some possible alternatives in this possibly related question as well.
I've built a small windows form app that opens a crm of choice to that customer account by running a command with the incoming phone number to the pbx that is connected to the app. It hangs out in the task bar and runs in the background.
This app runs beautifully in the IDE visual studio, and then once built and ran from the .exe it runs great too. However, when submitting it to the Microsoft store and then downloading it, the app doesn't even open. The window doesn't pop up and close immediately even. There is no action at all.
I'm confused because it has passed the tests from the store itself but still doesn't work. I've even tried submitting a practically empty app (removing much functionality) so that I could just see if the window would pop up when I run the app, but still nothing.
I'm fairly new at playing around with these things, but I've spent so much time online in the past two weeks trying to figure out the problem I thought it would be worth asking the great group here.
If you think you need some code, please ask. At this point, I don't even know what would be helpful to share.
Thanks!
if you use .net framework you should insert the framework into the installation file.
or if you use database you should check connection string and insert the database into the installation file and insert the local database( by database version )on the Customer system.
I have a C# console application program running on windows server anytime.
On the same machine I have zend server and apache running.
It is possible to send a command to the running C# program directly from the PHP without having an endless loop on the C# program that taking the info from outsourced files?
For example, the command "/init" would initialize all the variables on the C# program.
Can I write a init.php file to send the "/init" command to the running C# windows application?
This will be in order to initialize all the variables on the running "Program.exe" by opening the URL "http://example.com/init.php".
Thanks in advance.
There is a number of approache for IPC.
As I understand it, you want to do that without a loop. The thing is: You have to have a loop anyway to keep the console application alive. The programm is staretd. Executes all code. And then ends. You could block it via stuff like ReadKey(), but then it would not be able to process anything.
Unfortunately all approaches to IPC I know either require a loop. Or a GUI that already has a loop - the EventQueue. You will not get around some multitasking, and for that alone I always advise a GUI application.
It is also pretty unclear what data you actually want to send and what that application doe with that data. Depending on those requirements, it might be possible to just do this via commandline parameters.
However the biggest issue might be rights. Web Servers are notoriously vulnerable to hacking, being online 24/7/365. As a result, they are usually run under the most restrictive user rights imaginable. Read access to it's content and programm folder is the only thing you can asume. Reading anywhere else, writing or even Execution is not usually on the list of things it can do. And will raise some eyebrows from the admin too.
I have a problem in my VB code so I am now stuck. I am trying to open a certain application by my VB application code, this is done successfully by Process.Start().
However I don't only need to start application, I also need to manipulate its User Interface, like button presses or loading configuration.
So how can I do that, given all what I know from the tool that I launch, is its destination in my machine?
I tried to google it, but I couldn't find good answer!
I'd like to know with a .net language(C# or VB) if I can detect when a new app is launched.
e.g: an user opens Firefox.exe from desktop (not from my app!), is it possible to detect this event from my app? Also is it possible to "pause" it before running it?
So for example when an user double-clicks an application, my app comes first and then it displays a message if he is sure to open that file with Yes and No buttons.
I don't need all code, I just need to know how to catch that event that can happen anywhere in system.
There are some Windows API functions in user32.dll that you can use in your .NET application through System.Runtime.InteropServices.DllImport to get the information you're looking for. Take a look at GetWindowThreadProcessId. For sample code, see http://www.c-sharpcorner.com/UploadFile/satisharveti/ActiveApplicationWatcher01252007024921AM/ActiveApplicationWatcher.aspx. Because applications tend to become active when they are launched, you'll find that the techniques used in that example will cause it to detect new app launches.
That doesn't answer the question about letting the user confirm whether they want to run an app, but it will get you part of the way towards what you are trying to do.