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.