I need to automate FileMon.exe to startup with filters, save out the log it generates, and then exit.
My solution has been to write an assist application that will do all of this. Which has worked on starting up with specified filters and killing the process, but I still need it to save the log. Do you think it would be silly to send the application keystrokes to save the log? For instance I would send an Alt+F, Alt+S, type filepath, Enter.
How can you send keystrokes like above to another process that is running in C#?
As I know, you have to invoke some of native APIs:
-FindWindow to find parent windows you want to work with
-FindWindowEx to find true windows you'll send message to
-SendMessage to send key strokes to those windows
Details of these APIs, refer at MSDN :)
You can use Windows.Forms.SendKeys to send keystrokes to the active application.
Thanks for all the answers and help guys... I'm actually going to write and invoke a perl script using Win32::GuiTest.
That's probably a deaad end. You should look and see if the application (or one of its dependent DLLs) exposes the proper API calls to do what you are trying to do. If you had to do it by keystrokes, you could look into some kind of macro program like MacorMaker.
You could use powershell and the windows automation cmdlets up on www.codeplex.com/wasp to do this.
-Oisin
Use something like AHK (Auto HotKey) it is a simple language that can be compiled to an EXE and is designed for automating the keyboard and mouse.
Also the IRC Channel and Forums always have people willing to help if need be.
Related
I would like to write a program that can intercept the windows message that is sent when I press the button on my apple headphones and remap that to send a message to my desktop pandora app to play/pause. Is there already a utility that accomplishes this? Does the .NET framework give me access to these messages? Would I be able to access the message before it is sent to it's default program?
Is there already a utility that accomplishes this?
No clue. Probably not. SO isn't for recommendation questions anyways.
Does the .NET framework give me access to these messages?
No. Not easily anyways.
Would I be able to access the message before it is sent to it's
default program?
I don't know about timing, but you should be able to access it. You'll need to set up a hook (MSDN). Unfortunately, this is in the Windows API and so you'll need to use PInvoke to actually call the native (C++) methods needed.
I have a systemtray application (C#, Windows Forms). Next to this executable I will have another x amount of executables (written in C#) that must somehow send a message (preferably in string format) to the system tray application.
I do NOT want to install an entire Windows service for this.
It is NOT client-server. It all happens on the same PC. Using a listener combined with sockets would be to troublesome and it might even be blocked by it's own firewall I think.
I'm looking for something similar to a console application that can handle parameters on it's main function. Only this time for an already running Windows Form application.
Is it possible to somehow make a global function/procedure in the system tray application that can be called by other executables? Like "global void PerformAction(params here){..}"? This would seem to be the best solution but I'm not sure if .NET 4 supports this.
Example: executable X1.exe sends message "perform action [A] param [B]" to the system tray application and then terminates itself. The system tray application will then read that string and then knows that it needs to call function A with parameter "B".
But how do I send/receive the message?
Thank you.
Without resorting to WCF - you can use a simple wrapper over Named Pipes - like this one I posted as an answer to another question.
Hope this helps!
For local communication you could try anonymous pipes.
Link: http://msdn.microsoft.com/en-us/library/bb546102.aspx
You can also check out the remote method invocation.
Here is an example:
http://www.codeproject.com/Articles/14791/NET-Remoting-with-an-easy-example
There is a very handy method available to native application, i.e. window messages. With some hack, you can also use it with your .net application.
I would suggest you to refer to
SendMessage and SendMessageA api functions. You might have to write some unsafe code though.
If you used self hosted Asp.Net Web API, then you could use simple http calls to that application to execute methods. This is nice because you can test it using fiddler or anything that can send an http request.
Here is a link for an example.
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api
The easiest solution to me seemed to use a WCF service (inside the tray application) as Steve B mentioned.
I used this tutorial: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication.
I haven't heard of piping before but I think that the above link uses a WCF Service with piping. It did solve my problem.
Thanks for the many solutions provided (and so fast).
Is it possible to inject the code into another sub process? Let's say we have Silverlight plugin in the browser.. We want to inject our code (something like Snoop) into that plugin's process. When I'm using Spy++, I can receive the event from the plugin.. SO, I'm assuming that it is possible to inject the code as well..
Thanks in advance.
Edit: I'm currently looking at the code of Snoop and this article http://www.codeproject.com/KB/threads/winspy.aspx.. I understand that we can inject our code into other process.. My question is how to hook to other "sub" process..
Please take a look at this screenshot.. I'm trying to hook into "Microsoft SIlverlight" (Red arrow) but it doesn't work.. It would be great if you guys can share me some code example for hooking sub-process.. Thanks..
It's not quite "injection", but SetWindowsHookEx is pretty useful.
If you really need injection, take a look at what Process Hacker does.
Yes, it is possible to hook to other process.
For more information read the chapter 22 from the book “Programming Applications for Microsoft
Windows” by Jeffrey Richter. It contains different ways of hooking. I think this may help you.
API’s like SetWindowsHookEx(),CreateRemoteThread() ect will help you to hook to other process.
Windows doesn't have 'sub-processes,' but processes can have child processes. If child processes couldn't be hooked, you wouldn't be able to hook most running applications as they're child processes of explorer. Spy++ is showing you child windows, not processes. If you want to hook only input on a particular window you'll need to filter based on the active control.
Note: You're in Spy++ windows view, you can switch to processes view with the gears button.
I am writing a windowed .NET app in C#, which runs a third party console application via the Process class, as hidden as possible (CreateNoWindow, RedirectStandardOutput, etc.).
I've redirected it's StandardInput, so I can write whatever string I want, but not function keys or other type of special keys, as they don't have a character representation. As for me, I have to send keys F1 to F4 to the console app. The solutions I've found are for windowed app (PostMessage, SendMessage).
How can I do this for my console application?
Is there anything to do with the Handle of the Process?
You can't. Function keys cannot work with stdin, an app has to call ReadConsoleInput() to be able to detect them. That no longer works when you start the process without a console window.
Sendkeys.SendWait may solve your problem.
Does SendKeys work ("{F1}")? (the console will have to be active, though).
This isn't directly an answer to your question, but have you considered using MSMQ?
If your windowed application can receive those key-presses, it could pass that fact on to your console application using MSMQ. You may not have to actually pass the key-press, just the the fact that they were pressed.
I have found this techrepublic article helpful in getting the basics of MSMQ working.
i want to do a application which works in background and read all keys pressed by user and save it in file.
i start to write it in Win forms and use keys Pressed event but it works when form is focused:/
It is another way to do it? i hear about Windows Service, but i never use it :/
You can do it with help of these:
DirectX look into MDX
KeyLogger Application for C#
Creating a simple keylogger in C#
I don't know your reasons, but I just hope they are "good".
After doing a lot of research looking for a good code to use to achieve this, I've decided to create my own C# Keylogger API. It's very simple and clean:
api.CreateKeyboardHook((character) => { Console.Write(character); });
You just need to pass a callback and the API will return the key pressed by the user, among other things like: the screen the user was in that moment. Obviously, it works in background.
More details here: https://github.com/fabriciorissetto/KeystrokeAPI
I'm assuming you want to intercept all key events to all windows:
I wouldn't recommend C# for this. You'll need to drop to the Win32/64 API, which can be done, but you'd be better off using Visual C++ / something without training wheels.
There are several ways to do this. The easiest, by far, is to register a hook for keyboard events. Implement a basic service and handle the key-press events in your main loop / event handler. You can also just brute-force the keyboard state in a tight polling loop, but this will make the CPU cry.
There's 1,000,001 ways to install your own keyboard driver without admin privileges, but you're going to need to find one yourself, assuming you go down that road.
I seriously doubt that anyone on stackoverflow will help you create a key logger. You're going to need to dive into the bowels of the Win32 API and, likely, figure it out yourself. It isn't difficult if you have a solid C background. Windows "security" is little more than smoke & mirrors.