Visual C# Developer Center > Visual C# Forums > Visual C# General > how can set a program mode to kernel mode
Ask a questionAsk a question
 

Answerhow can set a program mode to kernel mode

  • Monday, November 02, 2009 6:19 AMiman62 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    i want write a program that it has some permission.
    this program muse run in kernel mode that i can close it
    i read in some site that i can do this work by API ... but i don't
    known how can i do this ...

Answers

  • Wednesday, November 04, 2009 12:47 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    You can't do this in C#.  Portions of your code's interaction with the WinAPI will be run in Kernel Mode (graphics, some portions of networking, etc), but all of those calls are made through the Windows User mode APIs.  The entire .NET Framework rests on the User-Mode Windows API, which in turn calls down to the kernel mode functions, but this means that .NET will always start out running in user mode.  If you need something to run in Kernel Mode, you'll be better off writing in C or C++ and creating a simple, non-intrusive device driver that will feed data back up to a User-Mode application which will interact with it. 

    This is not a topic that can be fully discussed within the bounds of a forum thread.  I'd suggest picking up a copy of Mark Russinovich's Windows Internals, and start reading.  Also, get yourself a good C++ book. You'll need it.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser

All Replies

  • Wednesday, November 04, 2009 12:47 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    You can't do this in C#.  Portions of your code's interaction with the WinAPI will be run in Kernel Mode (graphics, some portions of networking, etc), but all of those calls are made through the Windows User mode APIs.  The entire .NET Framework rests on the User-Mode Windows API, which in turn calls down to the kernel mode functions, but this means that .NET will always start out running in user mode.  If you need something to run in Kernel Mode, you'll be better off writing in C or C++ and creating a simple, non-intrusive device driver that will feed data back up to a User-Mode application which will interact with it. 

    This is not a topic that can be fully discussed within the bounds of a forum thread.  I'd suggest picking up a copy of Mark Russinovich's Windows Internals, and start reading.  Also, get yourself a good C++ book. You'll need it.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • Wednesday, November 04, 2009 1:28 PMStephen Cleary Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I just have one addition to David Morton's suggestion: get a good C book. C++ is not supported for kernel code.

    (C++ is actually a flamable topic on kernel developer lists. It is possible to use, but you have to know the details of language/stdlib implementation, and not use certain things like exceptions, RTTI, new/delete/malloc/free, and the majority of the standard library).

           -Steve
    Programming blog: http://nitoprograms.blogspot.com/
      Including my TCP/IP .NET Sockets FAQ

    Microsoft Certified Professional Developer
  • Wednesday, November 04, 2009 3:09 PMWyck Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Write a driver.  Put your kernel-mode code in the driver.  Install your driver.  Call your driver with an IoCtl call.