jry9524
驱动牛犊
驱动牛犊
  • 注册日期2002-01-10
  • 最后登录2005-03-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1837回复:3

驱动程序的自动安装

楼主#
更多 发布于:2002-08-08 15:55
hi:
   我已设计.inf和.sys文件,在系统提示下安装是绝对好用,但我想用INSTALLSHIELD制作一个安装程序,使驱动程序自动安装并连同我其他文件如:.DLL,.EXE文件一次性安装成功。
   我大致知道用NTDDK下的INSTALL的例子,但却不知如何实现,不知哪位兄弟知道能告知一二。
   还有,如用NTDDK下的INSTALL的例子,在WIN98和WIN2000下都好使吗?如果要卸载,是否要用到NTDDK下的REMOVE的例子?
   I am at sea.help me!please!

最新喜欢:

mapoflmapofl jackywu2kjackyw... tjmtjm
Beyon
fchwfchw
驱动牛犊
驱动牛犊
  • 注册日期2002-01-21
  • 最后登录2018-05-29
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望20点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-08-09 08:48
InstallShield 可以调用的DLL中函数的格式为
LONG WINAPI FOO(
  HWND hwnd,
  LPSTR szSrcDir,
  LPSTR szSupport,
  LPSTR szInst,
  LPSTR szDbase)
返回非0的值表示成功
      0 表示失败
这个你可以看看InstallShield的帮助文档去了解,以及这五个参数的含义。
你可以参考NTDDK的例子Install去完成这个DLL,然后在InstallShield的某一个过程后调用。
我这里有做好的例子。如下:
LONG WINAPI Install(HWND hwnd, LPSTR szSrcDir, LPSTR szSupport, LPSTR szInst, LPSTR szDbase)
{
DWORD iResult=1;
//get inf file path and name INFFileName=AddDirectoryWithINFFileName(TempPathBuffer,\"LAN.inf\");
//get hardwareID
HardwareID = \"*fft\\\\LAN\" ;
//Install Driver by INF and HaradwareID
//This function you can reference MS NTDDK SAMPLE Install
InstallDriveByINFAndHardwareID(INFFileName,HardwareID);

return iResult;
}
int InstallDriveByINFAndHardwareID(_TCHAR *INFFileName,_TCHAR *HardwareID)
{
WIN32_FIND_DATA FindFileData;
    BOOL RebootRequired = 0;
if (FindFirstFile(INFFileName,&FindFileData)==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,\"Install failure, inf file not exist\",\"DLL Info\",MB_OK);
return 2; //install failure, inf file not exist
}

    if (FindExistingDevice(HardwareID))
{
if(End_User_Select==0)
{
if(MessageBox(NULL,
\"Press Yes to force upgrade the driver\\nPress No to use the current driver\",
\"DLL INFO\",MB_YESNO)==IDYES)
{
End_User_Select=1;
//remove driver
//MessageBox(NULL,\"remove driver\",\"DLL info\",MB_OK);
RemoveDriveByHardwareID(HardwareID);
//install driver
//MessageBox(NULL,\"install driver\",\"DLL info\",MB_OK);
InstallDriveByINFAndHardwareID(INFFileName,HardwareID);

}
}
else
{
//Remove driver
RemoveDriveByHardwareID(HardwareID);
//install driver
//MessageBox(NULL,\"install driver\",\"DLL info\",MB_OK);
InstallDriveByINFAndHardwareID(INFFileName,HardwareID);
}

return 3;//install failure, driver already existing
}
    
GUID ClassGUID;
TCHAR ClassName[MAX_CLASS_NAME_LEN];

if(!SetupDiGetINFClass(INFFileName,&ClassGUID,ClassName,sizeof(ClassName),0))
{
if(MessageBox(NULL,\"Install failure, get inf class error\",\"DLL info\",MB_OK)==IDYES)
{
};
return 4;//install failure, Get inf class
}

HDEVINFO DeviceInfoSet=0;
DeviceInfoSet=SetupDiCreateDeviceInfoList(&ClassGUID,0);
if(DeviceInfoSet==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,\"Install failure, create device info list error\",\"DLL info\",MB_OK);
return 5;//install failure, Create device info list
}

SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize=sizeof(SP_DEVINFO_DATA);
if(!SetupDiCreateDeviceInfo(DeviceInfoSet,ClassName,&ClassGUID,NULL,0,DICD_GENERATE_ID,&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
MessageBox(NULL,\"Install failure, create device info error\",\"DLL info\",MB_OK);
return 6;//install failure, Create device info
}


BYTE PropertyBuffer[32];
memset(PropertyBuffer,0,32);
memcpy(PropertyBuffer,HardwareID,strlen(HardwareID));

if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,&DeviceInfoData,SPDRP_HARDWAREID,
PropertyBuffer,(lstrlen(HardwareID)+1+1)*sizeof(TCHAR)))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
MessageBox(NULL,\"Install failure, set device registry property error\",\"DLL info\",MB_OK);
return 7;//install failure, set device registry property
}

if(!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,DeviceInfoSet,&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
MessageBox(NULL,\"Install failure, class install error\",\"DLL info\",MB_OK);
return 8;//install failure,call class install
}

if(!UpdateDriverForPlugAndPlayDevices(0,HardwareID,INFFileName,INSTALLFLAG_FORCE,&RebootRequired))
{
if(!SetupDiCallClassInstaller(DIF_REMOVE,DeviceInfoSet,&DeviceInfoData))
{
//remove calss installer error
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
MessageBox(NULL,\"Install failure, update for plug and play device error\",\"DLL info\",MB_OK);
return 9;//install failure, update for plug and play device error
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);

if (RebootRequired)    
        return 1; // Install Success, reboot required.
else
return 0; // Install Success, no reboot required.
}

其实到这里应该说是很明白了,不过如果你还有不明白的地方,我们可以继续探讨。
如果回答得好,请给分。

孤独的人是可耻的
jry9524
驱动牛犊
驱动牛犊
  • 注册日期2002-01-10
  • 最后登录2005-03-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-08-09 11:40
Dear friend:
     我还是比较糊涂,在NTDDK下的INSTALL的例子编译后是。EXE文件,按你的例子好象可以直接调用.INF文件自动安装了,用不着再调用.DLL了。
    还有,如果用你的例子在WIN98和WIN2K下都能好用吗?我现在理解在WIN2K下用updatedriverplugandplaydevice()函数就可以了,但我不知道这个函数到底在哪儿用?
    Would you like to reply to me quickly!
Beyon
elufar
驱动牛犊
驱动牛犊
  • 注册日期2002-07-02
  • 最后登录2005-08-18
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-08-16 15:35
游客

返回顶部