找回密码
 加入
搜索
查看: 4261|回复: 8

[系统综合] 已解决 Devcon.exe 中的Install 调用的是哪个API?

  [复制链接]
发表于 2012-3-24 15:00:04 | 显示全部楼层 |阅读模式
本帖最后由 Qokelate 于 2012-3-27 21:39 编辑

如题,想用纯AU3做个自动安装驱动的工具,SetupAPI.au3看不明白,有人解答下吗?

无解。。。
发表于 2012-3-24 15:20:39 | 显示全部楼层
如果是一个API能解决我就不会到现在也看不懂P版的帖子了
 楼主| 发表于 2012-3-24 15:31:52 | 显示全部楼层
本帖最后由 Qokelate 于 2012-3-24 15:35 编辑

回复 2# 502762378


    ??   这和你看不看得懂P版的帖子有什么关系?  你要求的是直接给个文件名就能傻瓜式使用,而我想知道的只是它首先调用或核心调用是哪个API,有关系吗?
发表于 2012-3-24 15:35:47 | 显示全部楼层
回复 3# Qokelate


呵呵,是我淡疼多言了,希望你早日解决问题,当然偶没折
 楼主| 发表于 2012-3-24 15:55:35 | 显示全部楼层
找到原型如下,不知是否正确
int cmdInstall(__in LPCTSTR BaseName, __in LPCTSTR Machine, __in DWORD Flags, __in int argc, __in_ecount(argc) TCHAR* argv[])
/*++

Routine Description:

    CREATE
    Creates a root enumerated devnode and installs drivers on it

Arguments:

    BaseName  - name of executable
    Machine   - machine name, must be NULL
    argc/argv - remaining parameters

Return Value:

    EXIT_xxxx

--*/
{
    HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
    SP_DEVINFO_DATA DeviceInfoData;
    GUID ClassGUID;
    TCHAR ClassName[MAX_CLASS_NAME_LEN];
    TCHAR hwIdList[LINE_LEN+4];
    TCHAR InfPath[MAX_PATH];
    int failcode = EXIT_FAIL;
    LPCTSTR hwid = NULL;
    LPCTSTR inf = NULL;

    if(Machine) {
        //
        // must be local machine
        //
        return EXIT_USAGE;
    }
    if(argc<2) {
        //
        // at least HWID required
        //
        return EXIT_USAGE;
    }
    inf = argv[0];
    if(!inf[0]) {
        return EXIT_USAGE;
    }

    hwid = argv[1];
    if(!hwid[0]) {
        return EXIT_USAGE;
    }

    //
    // Inf must be a full pathname
    //
    if(GetFullPathName(inf,MAX_PATH,InfPath,NULL) >= MAX_PATH) {
        //
        // inf pathname too long
        //
        return EXIT_FAIL;
    }

    //
    // List of hardware ID's must be double zero-terminated
    //
    ZeroMemory(hwIdList,sizeof(hwIdList));
    if (FAILED(StringCchCopy(hwIdList,LINE_LEN,hwid))) {
        goto final;
    }

    //
    // Use the INF File to extract the Class GUID.
    //
    if (!SetupDiGetINFClass(InfPath,&ClassGUID,ClassName,sizeof(ClassName)/sizeof(ClassName[0]),0))
    {
        goto final;
    }

    //
    // Create the container for the to-be-created Device Information Element.
    //
    DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID,0);
    if(DeviceInfoSet == INVALID_HANDLE_VALUE)
    {
        goto final;
    }

    //
    // 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))
    {
        goto final;
    }

    //
    // Add the HardwareID to the Device's HardwareID property.
    //
    if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
        &DeviceInfoData,
        SPDRP_HARDWAREID,
        (LPBYTE)hwIdList,
        (lstrlen(hwIdList)+1+1)*sizeof(TCHAR)))
    {
        goto final;
    }

    //
    // Transform the registry element into an actual devnode
    // in the PnP HW tree.
    //
    if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
        DeviceInfoSet,
        &DeviceInfoData))
    {
        goto final;
    }

    FormatToStream(stdout,MSG_INSTALL_UPDATE);
    //
    // update the driver for the device we just created
    //
    failcode = cmdUpdate(BaseName,Machine,Flags,argc,argv);

final:

    if (DeviceInfoSet != INVALID_HANDLE_VALUE) {
        SetupDiDestroyDeviceInfoList(DeviceInfoSet);
    }

    return failcode;
}
发表于 2012-3-24 22:24:16 | 显示全部楼层
 楼主| 发表于 2012-3-25 00:11:46 | 显示全部楼层
本帖最后由 Qokelate 于 2012-3-25 00:47 编辑

回复 6# hzxymkb


    这个是Update方式的,不能用于添加新硬件,我想要的是Install的,相当于添加新硬件并安装驱动,而且  iFlag 类型是 DWORD 但却用个字符串传入,表示不解,该贴作者测试过可用性了吗?
关于Devcon MS有详细使用说明 http://msdn.microsoft.com/en-us/library/windows/hardware/ff544780(v=vs.85).aspx
发表于 2012-3-25 02:57:54 | 显示全部楼层
去搜p侠的setupapi
发表于 2012-8-19 17:51:17 | 显示全部楼层
学习一下下哈哈
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-30 03:32 , Processed in 0.079397 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表