Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Delete Driver with C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Uwe Porsch - 11 Mar 2008 10:13 GMT
Hello,
I want to write a smal application which deletes a driver installed on Vista.

Right now I delete a driver manually within the Hardware Manager. I want to
do this with an app.

Thanks and regards
Uwe
Michael Nemtsev [MVP] - 11 Mar 2008 12:04 GMT
Hello Uwe,

Start from this http://www.codeproject.com/KB/system/EnumDevices.aspx

and be very carefull with testing :)

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

UP> Hello,
UP> I want to write a smal application which deletes a driver installed
UP> on Vista.
UP> Right now I delete a driver manually within the Hardware Manager. I
UP> want to do this with an app.
UP>
UP> Thanks and regards
UP> Uwe
Ben Voigt [C++ MVP] - 11 Mar 2008 14:51 GMT
> Hello,
> I want to write a smal application which deletes a driver installed
> on Vista.
>
> Right now I delete a driver manually within the Hardware Manager. I
> want to do this with an app.

You don't want to use C# for that.

If you must use .NET, then use C++/CLI and take advantage of the header
files already being written for you.  The device manager data structures
aren't easily used through p/invoke, while C++/CLI is basically designed for
exactly this sort of task.

You need the SetupDi* family of functions.

> Thanks and regards
> Uwe
Willy Denoyette [MVP] - 11 Mar 2008 16:52 GMT
> Hello,
> I want to write a smal application which deletes a driver installed on
[quoted text clipped - 6 lines]
> Thanks and regards
> Uwe

Very easy to shoot yourself in the foot, by using System.Management.
Needs elevated privileges to succeed.
           ...
           ManagementBaseObject outParams = null;
           string objPath =
string.Format("Win32_SystemDriver.Name='{0}'","driverNameToDelete");
           using (ManagementObject device= new ManagementObject(objPath))
          {
               outParams = device.InvokeMethod("Delete", null, null);
               uint ret =
Convert.ToUInt32(outParams.Properties["ReturnValue"].Value);
               if(ret != 0)
                   Console.WriteLine("Failed : {0}", ret);
               else
                   Console.WriteLine("Success");
           }
....

Willy.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.