我有一个设备想做一个自动安装的程序,目前只有inf 文件和驱动文件
如何做成一个setup文件,让他自动安装!

解决方案 »

  1.   

    Private Declare Function WritePrivateProfileString _
    Lib "kernel32" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationname As String, ByVal _
    lpKeyName As Any, ByVal lsString As Any, _
    ByVal lplFilename As String) As LongPrivate Declare Function GetPrivateProfileString Lib _
    "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationname As String, ByVal _
    lpKeyName As String, ByVal lpDefault As _
    String, ByVal lpReturnedString As String, _
    ByVal nSize As Long, ByVal lpFileName As _
    String) As Long
    '
    '读INI文件.
    '函数:GetIniStr
    '参数:AppName 项目名.In_Key 键名,sFileName 文件名
    '返回值:成功:对应的键值.失败或不存在:""
    Public Function GetIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal sFileName As String) As String
        
        On Error GoTo GetIniStrErr
        
        If VBA.Trim$(In_Key) = "" Then
           GoTo GetIniStrErr
        End If    Dim GetStr As String
        GetStr = VBA.String(128, 0)
        GetPrivateProfileString AppName, In_Key, "", GetStr, 256, sFileName
        GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")
        If GetStr = "" Then
           GoTo GetIniStrErr
        Else
           GetIniStr = GetStr
           GetStr = ""
        End If
        Exit FunctionGetIniStrErr:
           Err.Clear
           GetIniStr = ""
           GetStr = ""
    End Function'
    '写INI文件.
    '函数:WriteIniStr
    '参数:AppName 项目名.In_Key 键名,In_Data 键值,sFileName 文件名
    '返回值:成功=TRUE.失败=FALSE
    Public Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal in_data As String, ByVal sFileName As String) As Boolean
        On Error GoTo WriteIniStrErr
        WriteIniStr = True
        If VBA.Trim(in_data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then
           GoTo WriteIniStrErr
        Else
         WritePrivateProfileString AppName, In_Key, in_data, sFileName
        End If
        Exit Function
        
    WriteIniStrErr:
           Err.Clear
           WriteIniStr = False
    End Function
      

  2.   

    我是菜鸟,请问你定义的函数是用来执行*.inf里面内容的吗?
    ini文件和inf文件一样吗?
    一个设备驱动inf文件,如何执行他?一般如果执行inf文件,就可以把设备驱动装好的。
      

  3.   

    MSTOP(陈建华(东莞立晨企业资讯服务有限公司)) 应该是看错问题了:)
    //一般如果执行inf文件,就可以把设备驱动装好的。
    你的认识可能不对:)
      

  4.   

    参考:
    http://tech.sina.com.cn/c/2003-05-22/19471.html
      

  5.   

    Shell "C:\WINDOWS\rundll.exe setupx.dll,InstallHinfSection DefaultInstall 132 " & "abc.inf"或用ShellExecute VB声明 
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 
    说明 
      查找与指定文件关联在一起的程序的文件名 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    hwnd Long,指定一个窗口的句柄,有时候,windows程序有必要在创建自己的主窗口前显示一个消息框 
    lpOperation String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它 
    lpFile String,想用关联程序打印或打开一个程序名或文件名 
    lpParameters String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数 
    lpDirectory String,想使用的完整路径 
    nShowCmd Long,定义了如何显示启动程序的常数值。参考ShowWindow函数的nCmdShow参数 偶也会帖了。
      

  6.   

    非常感谢,可惜不是我想要的,我其实想找一个函数,就是系统用来执行、处理INF文件的函数,这样我inf文件已经记录了硬件安装所有信息,我写一个setup执行inf内容就可以把硬件安装好了。
      

  7.   

    用LaunchINFSectionEx,应该能满足你的要求。
    以下是M$的MSDN对LaunchINFSectionEx的解释:
    http://msdn.microsoft.com/library/default.asp?url=/workshop/delivery/download/overview/launchinfsectionex.aspLaunchINFSectionEx Function  Internet Development Index --------------------------------------------------------------------------------Launches a section of an information (INF) file.SyntaxHRESULT WINAPI LaunchINFSectionEx(          HWND hwnd,
        HINSTANCE hInst,
        PSTR pszParams,
        INT nShow
    );
    Parametershwnd
    HWND that specifies the owner window on which to display error messages. This parameter is typically NULL, which causes the Desktop to be the owner window.
    hInst
    Handle to the instance of the program. This parameter is typically NULL.
    pszParams
    Comma-delimited string that specifies the INF file, the section of the INF file to launch, the fully qualified path of the cabinet file (CAB) that contains the INF file, and the flags that specify the installation mode, in that order. If you do not specify the fully qualified path of the INF file, the INF file is extracted from the specified CAB file. If you do not specify a section, that is, if the section portion of the pszParams string is an empty string or is set to NULL, then the DefaultInstall section of the INF file is launched. The following flags are used to specify the installation mode. 
    4 Quiet mode, no UI 
    8 Don't run GrpConv 
    16 Force self-updating on user's system 
    32 Backup data before install 
    64 Rollback to previous state 
    128 Validate the backup data 
    256 Complete rollback to previous state 
    512 Force delay of OCX registration 
    nShow
    Variable of type INT that specifies whether to reboot the user's machine upon completion. Can be one of the following values.
    A
    Always reboot.
    I
    Default. Reboot if needed.
    N
    No reboot.
    Return ValueReturns one of the following values.S_OK The section launched successfully. 
    E_FAIL The section failed to launch. 
    ResYou can call this function using Rundll32.exe from the command line.Note  Using an entry point function with Rundll32.exe does not resemble a normal function call. The function name and the name of the .dll file where it is stored are used only as command line parameters. The function definition shown in the Syntax section of this topic is only a standard prototype for all functions that you can call using Rundll32. The specific values for hwnd and hInst are not provided by the user, but are handled behind the scenes by Rundll32.
    ExamplesThe following examples demonstrate how to call the LaunchINFSectionEx function using Rundll32.
    This example demonstrates how to extract the myinf.inf INF file from the c:\temp\mydata.cab CAB file in Quiet|Backup mode, and reboot if needed.rundll32.exe advpack.dll,LaunchINFSectionEx myinf.inf,,c:\temp\mydata.cab,36
    This example demonstrates how to roll back to the state before the myinf.inf INF file was installed.rundll32.exe advpack.dll,LaunchINFSectionEx c:\windows\inf\myinf.inf,,,256
    Function InformationStock Implementation advpack.dll 
    Custom Implementation No 
    Import library None 
    Minimum availability Internet Explorer 5.01 
    Minimum operating systems Windows 2000 See AlsoAbout INF File Architecture, Using INF Files 
      

  8.   

    Declare Function LaunchINFSection Lib "advpack.dll" (ByVal hwnd As Long, ByVal hinstance As Long, ByVal pstr As String, ByValt As Long ) As LongDeclare Function LaunchINFSectionEx Lib "advpack.dll" (ByVal hwnd As Long, ByVal hInstance As Long, ByVal pszParms As String, ByVal nShow As Long ) As Long这两个申明是从一个德文网站找的,有解释,但看不懂。
      

  9.   

    Minimum operating systems 
    操作系统的最低版本是Windows 2000 ,我们98的又要干瞪眼了,郁闷!
      

  10.   

    唉,我正是要win98下面的执行inf文件的方法
    我在运行里面执行
    rundll.exe setupx.dll,InstallHinfSection DefaultInstall 132 C:\usb驱动\x.inf
    没什么反应,是不是什么地方错了
    大家交流一下
      

  11.   

    在inf文件的右键菜单里选[安装],不也是没什么反应吗?
    这个路径就是从注册表里找的,为什么不行我就不知道了。
    要不试试这样的:
    rundll32.exe advpack.dll,LaunchINFSectionEx c:\windows\inf\myinf.inf,,,256
      

  12.   

    试试这样:Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Command1_Click()
      Dim i As Long
      i = ShellExecute(Me.hwnd, "install", "你的inf文件路径", vbNullString, vbNullString, 1)
    End Sub