已经有inf和sys,如何打包为exe安装,设备也许已经安装了驱动,但必须替换为新的驱动,而驱动程序的名字也许不一样。要求win98和win2000都能用。谢谢
(最好有详细例子,我知道Setup API,但没有用过,如能用现成的安装程序制作最好不过)

解决方案 »

  1.   

    删除设备,完整程序在DDK的src\general\setup\remove目录下
    将程序中argv[1]改成你的硬件ID
        HDEVINFO DeviceInfoSet;
        SP_DEVINFO_DATA DeviceInfoData;
        DWORD i,err;    //
        // Verify the Arguments.
        //
        if (argc < 2)
        {
            _tprintf(TEXT("usage: remove <Hardware_ID>\n"));
            return 1; // Remove Failure
        }    //
        // Create a Device Information Set with all present devices.
        //
        DeviceInfoSet = SetupDiGetClassDevs(NULL, // All Classes
            0,
            0, 
            DIGCF_ALLCLASSES | DIGCF_PRESENT ); // All devices present on system
        if (DeviceInfoSet == INVALID_HANDLE_VALUE)
        {
            DisplayError(TEXT("GetClassDevs(All Present Devices)"));        
            return 1;
        }
        
        //
        //  Enumerate through all Devices.
        //
        DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
        for (i=0;SetupDiEnumDeviceInfo(DeviceInfoSet,i,&DeviceInfoData);i++)
        {
            DWORD DataT;
            LPTSTR p,buffer = NULL;
            DWORD buffersize = 0;
            
            //
            // We won't know the size of the HardwareID buffer until we call
            // this function. So call it with a null to begin with, and then 
            // use the required buffer size to Alloc the nessicary space.
            // Keep calling we have success or an unknown failure.
            //
            while (!SetupDiGetDeviceRegistryProperty(
                DeviceInfoSet,
                &DeviceInfoData,
                SPDRP_HARDWAREID,
                &DataT,
                (PBYTE)buffer,
                buffersize,
                &buffersize))
            {
                if (GetLastError() == ERROR_INVALID_DATA)
                {
                    //
                    // May be a Legacy Device with no HardwareID. Continue.
                    //
                    break;
                }
                else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
                {
                    //
                    // We need to change the buffer size.
                    //
                    if (buffer) 
                        LocalFree(buffer);
                    buffer = LocalAlloc(LPTR,buffersize);
                }
                else
                {
                    //
                    // Unknown Failure.
                    //
                    DisplayError(TEXT("GetDeviceRegistryProperty"));
                    goto cleanup_DeviceInfo;
                }            
            }        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))
            {
                _tprintf(TEXT("Compare device ID: [%s]\n"),p);            if (!_tcscmp(argv[1],p))
                {
                    _tprintf(TEXT("Found! [%s]\n"),p);                //
                    // Worker function to remove device.
                    //
                    if (!SetupDiCallClassInstaller(DIF_REMOVE,
                        DeviceInfoSet,
                        &DeviceInfoData))
                    {
                        DisplayError(TEXT("CallClassInstaller(REMOVE)"));
                    }
                    break;
                }
            }        if (buffer) LocalFree(buffer);
        }    if ((GetLastError()!=NO_ERROR)&&(GetLastError()!=ERROR_NO_MORE_ITEMS))
        {
            DisplayError(TEXT("EnumDeviceInfo"));
        }
        
        //
        //  Cleanup.
        //    
    cleanup_DeviceInfo:
        err = GetLastError();
        SetupDiDestroyDeviceInfoList(DeviceInfoSet);
      

  2.   

    删除设备之后还要将原来的inf(在%SYSTEMROOT%\inf下)和sys(在%SYSTEMROOT%system32\drivers下)删除,同时将inf下的oem*.inf(win98下在inf\other下的备份)删除
    然后将你的新inf和sys分别复制到相应目录下,同时修改inf文件,将复制文件的部分全部用';'注释掉,插入设备就可以自动找到新的驱动程序了
    如果在2000下还可以调用UpdateDriverForPlugAndPlayDevices提前预安装设备
      

  3.   

    去看看DDK中带的这个例子吧 netcfg在%ntddk%\src\network\config\netcfg例子本身可以根据命令行参数、.inf、.sys文件完成网络相关驱动的安装、卸载和查看
      

  4.   

    i wrote such as this script in installshield.
    NUMBER  nvResult;
    STRING  svResult;
    STRING  szDllName;
    LPSTR  szBuf;
    NUMBER  size; 
    BOOL    bCopy;
    BOOL    bDelete; 
    begin
        //////////////////////////////////////////////
        GetSystemInfo (OS,nvResult,svResult);  //Get system Operation system type
        //Disable the component that not for windowsNT or Win2000
         if (nvResult = IS_WINDOWSNT) then
       //  XCopyFile (SUPPORTDIR^"xxx.inf",WINDIR^"inf",COMP_NORMAL|LOCKEDFILE);
    szDllName = WINSYSDIR^"setupapi.dll";
    UseDLL(szDllName);
    bCopy =SetupCopyOEMInfA(SUPPORTDIR^"xxx.inf",NULL,0,8,NULL,0,0,NULL) ;
    UnUseDLL(szDllName);
    // if (!bCopy) then
    // exit;
    // endif;
        endif;              
        if (nvResult = IS_WINDOWS9X) then
         bCopy=XCopyFile (SUPPORTDIR^"xxx.sys",WINDIR^"system32\\drivers",COMP_NORMAL|LOCKEDFILE);    
         bCopy=XCopyFile (SUPPORTDIR^"xxx.inf",WINDIR^"inf",COMP_NORMAL|LOCKEDFILE);
         szDllName = WINSYSDIR^"kernel32.dll";
    UseDLL(szDllName);
    DeleteFileA(WINDIR^"Inf\\Drvidx.bin");
    bDelete =DeleteFileA(WINDIR^"Inf\\Drvdata.bin");
    UnUseDLL(szDllName);
    // if (!bDelete) then
    // exit;
    // endif;      
        endif;
      

  5.   

    我现在的解决方案(用Setup factory 6):
    根据inf将文件拷贝到各自的目录,在安装完成后,
    win98下删除drvidx.bin和drvdata.bin
    win2000下调用SetupAPI.dll中的SetupCopyOEMInf注册inf文件。欢迎大家继续讨论,我在网上查过,关于这方面的资料不多,写出来应该对大家有用。
    NTDDK\src\general\setup下有例子,我没有看过,有兴趣的可拿来一读。