#include "stdafx.h"
#include // make all functions unicode safe.
#include // for the api updatedriverforplugandplaydevices().
#include // for setupdi*** functions.
#include "install.h"
int displayerror(tchar * errorname)
bool findexistingdevice(in lptstr hardwareid)
//_tprintf(text("search for device id: [%s]/n"),hardwareid);
//// enumerate through all devices.
//found = false;
deviceinfodata.cbsize = sizeof(sp_devinfo_data);
for (i=0;setupdienumdeviceinfo(deviceinfoset,i,&deviceinfodata);i++)
else if (getlasterror() == error_insufficient_buffer)
else
}if (getlasterror() == error_invalid_data)
continue;
//// compare each entry in the buffer multi-sz list with our hardwareid.
//for (p=buffer;*p&&(p<&buffer[buffersize]);p+=lstrlen(p)+sizeof(tchar))
}if (buffer) localfree(buffer);
if (found) break;
}if (getlasterror() != no_error)
//// cleanup.
//cleanup_deviceinfo:
err = getlasterror();
setupdidestroydeviceinfolist(deviceinfoset);
setlasterror(err);
return err == no_error; //???
}bool
installrootenumerateddriver(in lptstr hardwareid,
in lptstr inffile,
out pbool rebootrequired optional)//
// create the container for the to-be-created device information element.
//deviceinfoset = setupdicreatedeviceinfolist(&classguid,0);
if(deviceinfoset == invalid_handle_value)
//// now create the element.
// use the class guid and name from the inf file.
//deviceinfodata.cbsize = sizeof(sp_devinfo_data);
if (!setupdicreatedeviceinfo(deviceinfoset,
classname,
&classguid,
null,
0,dicd_generate_id,
&deviceinfodata))
//// add the hardwareid to the device's hardwareid property.
//if(!setupdisetdeviceregistryproperty(deviceinfoset,
&deviceinfodata,
spdrp_hardwareid,
(lpbyte)hardwareid,
(lstrlen(hardwareid)+1+1)*sizeof(tchar)))
//// transform the registry element into an actual devnode
// in the pnp hw tree.
//if (!setupdicallclassinstaller(dif_registerdevice,
deviceinfoset,
&deviceinfodata))
//// the element is now registered. we must explicitly remove the
// device using dif_remove, if we encounter any failure from now on.
////
// install the driver.
//if (!updatedriverforplugandplaydevices(0,
hardwareid,
inffile,
installflag_force,
rebootrequired))
setlasterror(err);}//
// cleanup.
//cleanup_deviceinfo:
err = getlasterror();
setupdidestroydeviceinfolist(deviceinfoset);
setlasterror(err);
return err == no_error;
}int installdriver(_tchar *infname, _tchar *hardwareid)
//// look to see if this device allready exists.
//if (findexistingdevice(hwid))
}else
//// driver does not exist, create and call the api.
// hardwareid must be a multi-sz string, which argv[2] is.
//if (!installrootenumerateddriver(hwid, // hardwareid
fname, // filename
&rebootrequired))
}//_tprintf(text("driver installed successfully./n"));
if (rebootrequired)
return 0; // install success, no reboot required.
}int removedriver(_tchar *hardwareid)
//// enumerate through all devices.
//deviceinfodata.cbsize = sizeof(sp_devinfo_data);
for (i=0;setupdienumdeviceinfo(deviceinfoset,i,&deviceinfodata);i++)
else if (getlasterror() == error_insufficient_buffer)
else
}if (getlasterror() == error_invalid_data)
continue;
//// compare each entry in the buffer multi-sz list with our hardwareid.
//for (p=buffer;*p&&(p<&buffer[buffersize]);p+=lstrlen(p)+sizeof(tchar))
break;}}
if (buffer) localfree(buffer);
}if ((getlasterror()!=no_error)&&(getlasterror()!=error_no_more_items))
//// cleanup.
//cleanup_deviceinfo:
err = getlasterror();
setupdidestroydeviceinfolist(deviceinfoset);
return err;
}
自動安裝解除安裝驅動程式的原始碼
我本來希望我是往硬體底層驅動程式發展的,本來專業就是電路方面的,這兩年也做過usb驅動的一些東西,雖然能用,但是心裡一直感覺不舒服,對wdm的掌握總感覺有點飄忽,所以假期中在看unix的作業系統實現,現在心裡有點底了,可是沒有真的寫過徹底的驅動程式,總有點心虛,貼個帖子,以前bbs上的,自己也寫過,...
自動安裝解除安裝驅動程式的原始碼
我本來希望我是往硬體底層驅動程式發展的,本來專業就是電路方面的,這兩年也做過usb驅動的一些東西,雖然能用,但是心裡一直感覺不舒服,對wdm的掌握總感覺有點飄忽,所以假期中在看unix的作業系統實現,現在心裡有點底了,可是沒有真的寫過徹底的驅動程式,總有點心虛,貼個帖子,以前bbs上的,自己也寫過,...
轉貼 自動安裝解除安裝驅動程式的原始碼
轉貼 自動安裝解除安裝驅動程式的原始碼 include stdafx.h include make all functions unicode safe.include for the api updatedriverforplugandplaydevices include for setupdi...