如何在vb中打开exe文件(即一种arj压缩文件,其中包括很多文本文件)

解决方案 »

  1.   

    '添加 Command1  Command2'本代码是使用Winrar 如你没安装或 rar.exe不在你的公用路径,请下载一个并拷到winnt或system32目录下面'本代码是压缩 e:\music\*.mp3 到 c:\test.rar 路径你自己要改
    '     解压缩是将c:\test.rar 解压到你的桌面上Option Explicit
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
    Dim jj&, wsource$, wtarget$, aa$, tmpstr$, starttm&, objWMIService, colProcesslist
    Private Sub Form_Load()
       Command1.Caption = "压缩"
       Command2.Caption = "解压缩"
    End SubPrivate Sub Command1_Click()
       wsource = "e:\music\*.mp3"
       wtarget = "c:\test.rar"
       aa = "rar a -ep " & wtarget & " " & wsource
       Call Shell(aa, vbHide)
       starttm = Timer
       Do
          DoEvents
          If Isrunexe("rar.exe") = False Then Exit Do
       Loop Until Timer > starttm + 60
       MsgBox "压缩完成!"
    End SubPrivate Sub Command2_Click()
        wsource = "c:\test.rar"
        wtarget = Environ("userprofile") & "\桌面"
        wtarget = Getshortname(wtarget)
        aa = "rar x " & wsource & " " & wtarget
        Call Shell(aa, vbHide)
        starttm = Timer
        Do
           DoEvents
           If Isrunexe("rar.exe") = False Then Exit Do
        Loop Until Timer > starttm + 60
        MsgBox "解压缩完成!"
    End SubPublic Function Isrunexe(ExeNm As String) As Boolean
       tmpstr = "."
       Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & tmpstr & "\root\cimv2")
       Set colProcesslist = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & ExeNm & "'")
       Isrunexe = IIf(colProcesslist.Count > 0, True, False)
       Set objWMIService = Nothing
       Set colProcesslist = Nothing
    End FunctionPublic Function Getshortname(ByVal sLongFileName As String) As String
       Dim lRetVal&, sShortPathName$, iLen%
       sShortPathName = Space(255)
       iLen = Len(sShortPathName)
       lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
       Getshortname = Left(sShortPathName, lRetVal)
       jj = InStr(Getshortname, Chr(0))
       If jj > 0 Then Getshortname = Mid(Getshortname, 1, jj - 1)
    End Function
      

  2.   

    这么复杂啊, 后面两个函数Isrunexe、Getshortname看不懂啊
    必须要装Winrar并拷到system32下吗?
      

  3.   

    你要简单的我就弄个简单的, 但请注意两点1.解压缩的 .rar 与解压后的存放路径, 请别指定在 ?:\program Files\....或 ?:\Documents and Settings等路径, 因为我已将改为短路径的Getshortname拿掉了.2.rar.exe 放在 ?:\windows 或 ?:\windows\system32 之下,因为是公用路径, 如果你不愿拷到 c:\windows之下,aa = "rar x -y -o+ c:\test.rar c:\test\"
    改为
    aa = "?:\?\?\rar.exe x -y -o+ c:\test.rar c:\test\"  '? 是代表你自己喜欢的文件夹路径3,Isrunexe是用来检查压缩的动作是否已完成4.下面代码只有解压缩, 代码短些可能你才看得懂.5.我用 c:\test.rar 你改为你自己的
    Option Explicit
    Dim jj&, aa$, starttm&, objWMIService, colProcesslistPrivate Sub Command1_Click()
        aa = "rar x -y -o+ c:\test.rar c:\test\"
        Call Shell(aa, vbHide)
        starttm = Timer
        Do
           DoEvents
           If Isrunexe("rar.exe") = False Then Exit Do
        Loop Until Timer > starttm + 10
        MsgBox "解压缩完成!"
    End SubPublic Function Isrunexe(ExeNm As String) As Boolean
       Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
       Set colProcesslist = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & ExeNm & "'")
       Isrunexe = IIf(colProcesslist.Count > 0, True, False)
       Set objWMIService = Nothing
       Set colProcesslist = Nothing
    End Function
      

  4.   

    你说的是以EXE为后缀的自解压的文件
    直接用shell函数
    shell "原文件路径 解压文件路径",1 即可

    shell "c:\myfile d:\mydoc",1             参数值设成 1,可让该程序以正常大小的窗口完成,并且拥有焦点。