473,466 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can you do system wide hooks in .Net?

I don't think you can hook system events outside your application in .Net
without using an unmanaged DLL, but I thought I'd ask.

Jim Hubbard
Jul 21 '05 #1
5 1902
That's right. You have to use Win32 API (through P/Invoke).

"Jim Hubbard" <re***@groups.please> wrote in message
news:7s*******************@bignews4.bellsouth.net. ..
I don't think you can hook system events outside your application in .Net
without using an unmanaged DLL, but I thought I'd ask.

Jim Hubbard

Jul 21 '05 #2
Thanks for the confirmation.

BTW, it seems to me that Windows can never be fully .NEt....that some
unmanaged code will always be required to do things that managed code just
can't.

Isn't that a step backwards?

Jim Hubbard
"Shiva" <sh******@online.excite.com> wrote in message
news:OF****************@TK2MSFTNGP14.phx.gbl...
That's right. You have to use Win32 API (through P/Invoke).

"Jim Hubbard" <re***@groups.please> wrote in message
news:7s*******************@bignews4.bellsouth.net. ..
I don't think you can hook system events outside your application in .Net
without using an unmanaged DLL, but I thought I'd ask.

Jim Hubbard

Jul 21 '05 #3

"Jim Hubbard" <1@2.com> wrote in message
news:0Y*******************@bignews4.bellsouth.net. ..
Thanks for the confirmation.

BTW, it seems to me that Windows can never be fully .NEt....that some
unmanaged code will always be required to do things that managed code just
can't.


To an extent, thats true, however the number of things that are actually
only possible in unmanaged code are *extremely* small. Many things, like
hooks, etc, require pinvoke simply because windows hasn't exposed managed
interfaces to the functionality. It will be a while.
Most of what can't be done with managed code is stuff that any normal user
will never do. I don't think I will be writing a driver for anything in the
near future, nor do I need kernel mode access to anything(and though it may
be possible for .NET to operate at kernel mode, I wouldn't be surprised if
it never does). As it is I never write down to that level in C++, so why
should I be upset if C# doesn't let me?

And more to the point of your question, system hooks are pretty limited from
a managed language like C#. You can implement a certain subset, but I think
all you can do *globally* is keyboard and mouse hooks. Everything else
requires a dll that can be loaded by the OS seperatly, so you have to be
able to write atleast those entry points in unmanaged code. You can probably
do it with mixed C++, but I do not think it is possible from C# or VB.NET.
Jul 21 '05 #4
I agree with Daniel. Unmanaged code is still required for functionality that
have not been yet exposed to the managed world through the framework.

"Jim Hubbard" <1@2.com> wrote in message
news:0Y*******************@bignews4.bellsouth.net. ..
Thanks for the confirmation.

BTW, it seems to me that Windows can never be fully .NEt....that some
unmanaged code will always be required to do things that managed code just
can't.

Isn't that a step backwards?

Jim Hubbard
"Shiva" <sh******@online.excite.com> wrote in message
news:OF****************@TK2MSFTNGP14.phx.gbl...
That's right. You have to use Win32 API (through P/Invoke).

"Jim Hubbard" <re***@groups.please> wrote in message
news:7s*******************@bignews4.bellsouth.net. ..
I don't think you can hook system events outside your application in .Net
without using an unmanaged DLL, but I thought I'd ask.

Jim Hubbard


Jul 21 '05 #5

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:OL**************@TK2MSFTNGP09.phx.gbl...

"Jim Hubbard" <1@2.com> wrote in message
news:0Y*******************@bignews4.bellsouth.net. ..
Thanks for the confirmation.

BTW, it seems to me that Windows can never be fully .NEt....that some
unmanaged code will always be required to do things that managed code just can't.
To an extent, thats true, however the number of things that are actually
only possible in unmanaged code are *extremely* small.


Small in number, but big in the OS......like Remote Desktop and Remote
Assistance. These cannot be done purely in .Net.
Many things, like
hooks, etc, require pinvoke simply because windows hasn't exposed managed
interfaces to the functionality. It will be a while.
So you think it can be done in .Net? Exposing the OS to hooking and across
the whole system would violate the memory management features in .Net.

It just looks to me like .Net is a giant step backwards in capability. Sure
it's faster to write code.....but it's less capable and less secure than
what we had.
Most of what can't be done with managed code is stuff that any normal user
will never do. I don't think I will be writing a driver for anything in the near future, nor do I need kernel mode access to anything(and though it may be possible for .NET to operate at kernel mode, I wouldn't be surprised if
it never does). As it is I never write down to that level in C++, so why
should I be upset if C# doesn't let me?
You shouldn't. But those of us that do that sort of thing are.

And more to the point of your question, system hooks are pretty limited from a managed language like C#. You can implement a certain subset, but I think all you can do *globally* is keyboard and mouse hooks. Everything else
requires a dll that can be loaded by the OS seperatly, so you have to be
able to write atleast those entry points in unmanaged code. You can probably do it with mixed C++, but I do not think it is possible from C# or VB.NET.


Just thought I'd ask to amke sure I wasn't missing anything.

Thanks for your help.

Jim Hubbard

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
I am trying to determine if C# has the capabilities to listen for system events when the application does not have the window's focus. I am writing a windows application that I would like to run...
3
by: Patrick | last post by:
I have been developing in VB6 for years. I am converting to VB.net. I was wondering if it is possible to create a System hook in VB.net. I know that I VB6, I could not, so I created one in C++. ...
5
by: Jim Hubbard | last post by:
I don't think you can hook system events outside your application in .Net without using an unmanaged DLL, but I thought I'd ask. Jim Hubbard
0
by: leslie_tighe | last post by:
Hello, I need to build the following functionality into my application and wanted to see if the System journal hooks were the right way to approach this problem? If not, I would appreciate any...
3
by: cichy83 | last post by:
Hi! I have a problem with global hooks under these two OS. I'm using three following types of hooks: CBT Hokk, Keyboard Hook, Mouse Hooks. I'm using BCB 6, under Win XP everything works fine...
0
by: Nickneem | last post by:
I' m trying to disable all right mouse clicks by using the vbAccelerator Windows Hooks Library The small (systray / console) app. must catch all (right) mouseclicks before they are received by...
0
Mague
by: Mague | last post by:
Hey, I've looked up system hooks but i cannot find how to use key hooks on Visual Studio 2005. I want to use system hook to detect if Ctrl R to start a pitucalar part of the program and Ctrl S to...
0
by: Jared Goralnick | last post by:
Hi, I'm in the process of developing some high-level specs for an application. Some of the functionality of this application involves intercepting Windows access to certain applications or...
22
by: schneider | last post by:
I need to hook the system mouse down event. I'm trying to replicate how a context menu hides when the mouse clicks outside of the control. Thanks, Schneider
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.