|
Update: Well, I started the process suspended and I hooked it soon enough, I'm just going to have to find a way to suspend the process as soon as it is created.... I'll have to look into that...
I'm not familiar with flags... It comes in with a desired access of 3221225472. I assume it is the result of the flags hex values being translated into a single int. Anyway, I just return 1 for both desired access and share mode. Well, 0x00000001, but same diff really.
Question: Does anyone have any idea how the heck to automatically cause all instances of a specific process to start suspended? I don't want to try to figure out drivers and such.... But I already covered DLL injection so why the heck not, right? I would just really prefer to not....
modified 8-Nov-11 21:39pm.
|
|
|
|
|
In order to make the program open the file in shared mode, you need to modify the "dwShareMode" parameter, it's the third parameter.
For instance:
PresentValue |= (FILE_SHARE_READ | FILE_SHARE_WRITE);
This tells the program to add the values of the SHARE flags to the existing flag value.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You replied just before I edited. I had forgot to mention that I just requested read access and allowed read access. Both are 0x00000001 or 1, so it wasn't difficult.
Now I only have two issues. One being suspending the process as soon as it starts (Edit: The process will not be started from within any of my own code. I want to be able to suspend it when opened through any user initiated method), and the second is how to make the injected DLL call ReOpenFile if the original file isn't in share read mode.... I haven't been able to call a method from within the Run() code with EasyHook yet...
|
|
|
|
|
Without getting into drivers and things, the best way to have the program start suspended is to create your own launcher process.
Write a small program that calls CreateProcess with the CREATE_SUSPENDED flag.
Then, after you inject the DLL, call ResumeThread on the process's main thread.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Which means that I need to create a driver.... Bah!
A launcher process isn't really an option.... While it would be easily possible, it defeats the purpose of the entire program, unfortunately....
/sigh I suppose it's time to learn how to make a driver?
Will Anti-Virus detect this as a threat? It's going to have DLL injection and a driver that I assume will be loaded when the process starts and unloaded when the process ends..... And no real way to sign it apart from self signing....
Edit: I'll work on this more tomorrow. Maybe someone will have an idea for running something when I first hook the process?
Basically I need to find a handle within the process pointing at gw.dat, test it's file shared options, and if they are not read only shared, I will need to call ReOpenFile... Anyone have any ideas on that one?
modified 8-Nov-11 22:56pm.
|
|
|
|
|
I do have one more idea for you. Go to MSDN, and look up ShellExecuteHook.
EDIT-------------
This has been deprecated as of Vista. Sorry.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Would hooking ShellExecute(), ShellExecuteEx() and IsUserAnAdmin() work? I found it while looking for an alternative.
|
|
|
|
|
Well, yes, you could hook those functions in explorer.exe. Then, when the shell launches the specified program, you have your chance to modify the call so that it gets launched suspended.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hah, this is getting so frustrating.... It's too bad IShellExecuteHook was depreciated...
It's even more annoying that Microsoft didn't bother with an alternative...
Would hooking those functions globally work? Or.... I could attempt a driver, but I don't think kernel level drivers are possible in C#, and I would have to wing it in C or C++.....
And to make it worse, the only tutorial on making a driver doesn't work on my system. Something about not allowing unsigned drivers into kernel level....
|
|
|
|
|
Wait, don't be mistaken. It's true that IShellExecuteHook was deprecated, but the functions you mentioned before are still in use: ShellExecute, ShellExecuteEx
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Oh, I know that. The only issue I see is that to effectively make sure that I catch every single possible execution of the client, I would need to hook every single process, right? Just in case they open the client?
Or would hooking just explorer.exe work for every file run from any program?
|
|
|
|
|
Yes, I agree. You would have to hook every process.
Have you considered a system-wide hook to get your hooking dll into every process?
Global System Hooks in .NET[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Wow, very nice article there. I'm surprised I missed it..... Thanks!
I'll definitely check that out! This way I can either hook the process creation, or even just hook CreateFile(). Though at this point I have another question I'm going to move down the thread line...
Edit: Looks like I could muddle my way into making that work... Might just hook CreateFile globally and look specifically for gw.dat openings.
I can see advantages for both. If I globally hook CreateFile and look for gw.dat, no matter what the process is named it would open read only. Which would be fine except when the user needs to update... If I globaly hook process creation I would be able to avoid issues with updating.... Maybe I'll implement both as options.
modified 9-Nov-11 21:56pm.
|
|
|
|
|
Ok, one last issue...
I may have figured out a way to call code from the Run() command, but I wont be able to tell until I actually try to run ReOpenFile.
I need help getting ReOpenFile to apply to a pre-existing handle, that I have no idea what the variable is. I don't know how to do something like this.... From Run() I need to find the existing gw.dat handle, run ReOpenFile to gw.dat to change user permissions, and have that handle still be callable from the rest of the program.
Ideas?
|
|
|
|
|
Okay, so I thought I had figured how to draw my own title bar, by painting the non-client area. For the most part I have it working. Currently I catch WM_NCCALCSIZE and I resize the frame. Then I paint the custom title bar and handle mouse events and such on my own. Now, when I add something such as a ToolStrip it overlays the title bar. Because the title bar is not painted outside of the client area. Do I need to adjust the client area of the form somehow?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
I am using this code from Microsoft website to simple way to read from Serial Port. I am not getting any error which means it's correct BUT I am not getting any data from the SerialPort but data are being read if I use a third party software so there is no doubt Serial is sending the data?
what can I do? Thanks..
SerialPort serialPort1;
string RxString;
public frmMain()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
serialPort1 = new SerialPort() { PortName = txtPortName.Text, BaudRate = Convert.ToInt32(txtBaudRate.Text), DataBits = 8, Parity = Parity.None, StopBits = StopBits.One, Handshake = Handshake.None };
if (!serialPort1.IsOpen)
{
serialPort1.Open();
serialPort1.Write("SI\r\n");
btnStart.Enabled = false;
btnStop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.Text = "OK";
textBox1.AppendText(RxString);
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!serialPort1.IsOpen) return;
char[] buff = new char[1];
buff[0] = e.KeyChar;
serialPort1.Write(buff, 0, 1);
e.Handled = true;
}
private void btnStop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
btnStart.Enabled = true;
btnStop.Enabled = false;
textBox1.ReadOnly = true;
}
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
|
|
|
|
|
From a quick browse I see that you are not subscribing to the serial port Data_Received event.
Unless there is a piece of code that You haven't posted here.
Something like
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
I would also modify the DisplayText() method to take a string argument/reference
instead of using a lets say "global" variable.
Plus the code is most likely to throw an exception.
You should use InvokeRequired on the textbox since it was created on a different thread.
There too many objections that I have with your code.
Why use a event for displaying the text? Use the event to catch the serial data and then display it
using the InvokeRequired routine.
All the best,
Dan
modified 8-Nov-11 12:40pm.
|
|
|
|
|
Yes I think I missed it..
I will also take your comments when doing it because I am just starting with serial port communication..
Thanks alot
|
|
|
|
|
You're welcome
All the best,
Dan
|
|
|
|
|
jrahma wrote: I am not getting any error which means it's correct
jrahma wrote: data are being read if I use a third party software so there is no doubt Serial is sending the data
That is two logical errors in your opening paragraph.
for(;;) {} is not generating any compile-time or run-time errors, yet is probably not what your app would need.
And a peripheral sending data under some circumstances isn't necessarily sending data under different circumstances, e.g. when the control lines are set differently.
|
|
|
|
|
Hi,
I would like to check if a particular window with a particular name is open. How do I Do it in C#?
Basically in C++, i use IsWindowVisible(handle), how do I do it in C#?
|
|
|
|
|
|
Thank you but I do not want to use pinvoke. Is there any other way?
To get a particular process and kill it, I use:
foreach (Process procName in
Process.GetProcesses().Where
(procName => procName.ProcessName.StartsWith("Test")))
{
procName.Kill();
}
I am looking for something along the same lines.
|
|
|
|
|
In general, no, there is no other way.
Depending on what you're trying to do, you may be able to use Process.MainWindowTitle[^]. This will tell you the title of the main window of each process, and you can iterate through those looking for the one you want without P/Invoke. But (as far as I'm aware at least) there is no way to get a window by name that looks at all open windows without using FindWindowByName.
|
|
|
|
|
This tips[^] might help you.
|
|
|
|