|
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.
|
|
|
|
|
Hello ::- ). I've recently upgraded to Windows 7 and, naturally, some of my apps have run into a black, merciless wall of changed behaviors.
One of the things which stopped working are my applications to bring stuff out of SysTray. Some applications don't have good methods to bring them out of SysTray via hotkey. Total Commander for example sometimes fails and you have to press Enter. So I made an application which worked fine on XP. But now, instead of bringing it back from SysTray and popping it in my face, it just blinks it on the Taskbar.
Before you say "ForegroundLockTimeout", know that I already set this to 0 across the registry.
What I'm trying to do is to make Total Commander come out from SysTray via a hotkey. The hotkey actually launches my C# application. In my C# application I do this:
int hwndTC = Win32API.FindWindow("TTOTAL_CMD", null);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.Show);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.ShowMaximized);
Win32API.ShowWindow((IntPtr)hwndTC, Win32API.ShowWindowCommand.Maximize);
Win32API.SetForegroundWindow(hwndTC);
But the result is that instead of TC showing itself in my face, I see it blinking on the TaskBar.
One very strange thing is that when Visual Studio is running (and thus, the .vshost.exe is running), everything works fine. As soon as I shut down VS, the blinking stuff happens again.
|
|
|
|
|
|
When two event handlers are registered for one event, they are executed in the order they were registered (yes, I know, I must not rely on that).
Now I want the event handler which was registered second to be executed first (reliably of course). How can that be achieved - or can it be achieved at all?
|
|
|
|
|
You can use the event's delegate array if you have control over the event source.
e.g. Helpfully in the standard order!
public EventHandler MyEvent;
private void OnMyEvent(EventArgs args) {
EventHandler temp = MyEvent;
if (temp != null) {
Delegate[] handlers = temp.GetInvocationList();
for(Int32 i = 0; i < handlers.Length; ++i) {
((EventHandler)handlers[i])(this, args);
}
}
}
Alan.
|
|
|
|
|
While this will work well at the moment, GetInvocationList is defined as returning things in the same order as they will be executed, and I'm not sure that order is defined anywhere.
|
|
|
|
|
Yes I see what you mean and it made me wonder if an explicit backing list combined with implementation of the event's add and remove accessors would help.
It wouldn't as the multicast nature of delegates means that the list would actually be a list of delegate chains and the only way to iterate through the chains would still be via GetInvocationList.
Alan.
|
|
|
|