如何创建一个COM $ P $使用SevenZipSharp pssed SFX文件? [英] How to create a compressed SFX file using SevenZipSharp?

查看:180
本文介绍了如何创建一个COM $ P $使用SevenZipSharp pssed SFX文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就明白了如何创建一个自解压使用SevenZipSharp库。

首先,我必须说,我找不到任何属性设置COM pression水平,以及所有。

当我尝试做一个文件的SFX,我得到这个错误:

 对象未设置为一个对象的实例。
 

如果我尝试做一个文件夹的SFX,我得到这个错误:

 访问路径C:\测试'。被拒绝
 

(但是是不是真的,我联系,我已经有更多的avaliable文件夹测试吧...)

这是完整的类在那里我试图理解这一切......

 进口SevenZip

公共类Form1中

昏暗的DLL作为字符串=7z64.dll

专用功能SevenZipSharp_Com press_SFX(BYVAL Input_DirOrFile作为字符串_
                                            BYVAL OutputFileName作为字符串)作为布尔
    尝试
        设置库路径
        SevenZipCom pressor.SetLibraryPath(DLL)

        创建COM pressor
        昏暗的COM pressor作为SevenZipSfx =新SevenZipSfx(SfxModule.Default)

        设置SFX参数
        '¿?

        启动COM pression
        COM pressor.MakeSfx(Input_DirOrFile,OutputFileName)

    抓住EX为例外
        返回错误的文件不是COM pressed
        抛出新的异常(ex.Message)
    结束尝试

    返回true'文件COM pressed

端功能

私人小组的button1_Click(发送者为对象,E作为EventArgs的)把手Button1.Click
    SevenZipSharp_Com press_SFX(C:\测试\ file.bat,C:\ 7zSFX.exe)
结束小组

末级
 

  

更新:

@For大家:

请我祈祷的人谁都会回答我的问题,至少你用于创建自解压SevenZipSharp告诉我什么,我做错了,如何解决这个问题,不回答说,他们是用户权限问题,请阅读注释。

解决方案

看起来可能有些混乱,以什么参数应该的。下面code为我工作了最新的SevenZipSharp code在 codePLEX

 私人小组的button1_Click(BYVAL发件人为对象,BYVAL E上EventArgs的)
        昏暗的COM pressor作为SevenZipSfx =新SevenZipSfx(7z.sfx)
        COM pressor.MakeSfx(C:\ TEMP \ cc_seal.7z,C:\ TEMP \ sfxseal.exe)
    结束小组
 

我试图与SevenZipSfx(SfxModule.Default)就像在你的榜样,但该模块的名字没有被设置,我相信这就是错误的未设置为一个对象的实例对象引用来自何处,因为我这样做:

 私人小组的button1_Click(BYVAL发件人为对象,BYVAL E上EventArgs的)
        昏暗COM pressor作为SevenZipSfx =新SevenZipSfx(SfxModule.Default)
        COM pressor.ModuleFileName =7z.sfx
        COM pressor.MakeSfx(C:\ TEMP \ cc_seal.7z,C:\ TEMP \ sfxseal.exe)
    结束小组
 

和它也为我工作没有错误。取出ModuleFileName行,我得到了相同的崩溃像你一样。

此外请注意COM pressor.MakeSfx第一个参数必须是一个.7z文件,而不是一个.bat文件。它将工作,但是当您尝试运行sfx.exe它会与一些工作不是一个有效的7zip的文件崩溃。所以,你需要COM preSS文件/目录第一。

请在您的应用程序目录肯定7z.sfx,或提供其路径(这是在codePLEX源码下载)

我试图用7zxSD_All.sfx的文件首先,它提取该文件,那么Windows 7中提供了有关它没有被正确安装错误(我假设Windows 7的认为它是一个安装文件,而不是一个自解压文件)。 7z.sfx工作虽然。

I will understand how to create a SFX using SevenZipSharp library.

First of all I need to say I can't find any property to set the compression level, and all of that.

And when I try to make an SFX of a file, I get this error:

"Object reference not set to an instance of an object."

If I try to make an SFX of a folder, I get this error:

"Access to the path 'C:\test' is denied."

(But is not True, I'm Admin and I've tested it with more avaliable folders...)

This is the full class where I'm trying to understand all of this... :

Imports SevenZip

Public Class Form1

Dim dll As String = "7z64.dll"

Private Function SevenZipSharp_Compress_SFX(ByVal Input_DirOrFile As String, _
                                            ByVal OutputFileName As String) As Boolean
    Try
        ' Set library path
        SevenZipCompressor.SetLibraryPath(dll)

        ' Create compressor
        Dim Compressor As SevenZipSfx = New SevenZipSfx(SfxModule.Default)

        ' Set SFX parameters
        ' ¿?

        ' Start compression
        Compressor.MakeSfx(Input_DirOrFile, OutputFileName)

    Catch ex As Exception
        'Return False ' File not compressed
        Throw New Exception(ex.Message)
    End Try

    Return True ' File compressed

End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    SevenZipSharp_Compress_SFX("C:\test\file.bat", "C:\7zSFX.exe")
End Sub

End Class

UPDATE:

@For Everyone:

please I pray to someone who will answer my question at least you used to create a SFX SevenZipSharp to tell me what I'm doing wrong and how to fix it, not to answer to say that they are user permission issues, please read the comments.

解决方案

It looks like there may be some confusion as to what the arguments should be. The following code worked for me with the latest SevenZipSharp code on codeplex.

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim compressor As SevenZipSfx = New SevenZipSfx("7z.sfx")
        compressor.MakeSfx("C:\Temp\cc_seal.7z", "C:\Temp\sfxseal.exe")
    End Sub

I tried with the SevenZipSfx(SfxModule.Default) like in your example, but the module name wasn’t being set and I believe that’s where the "Object reference not set to an instance of an object" error was coming from, because I did this:

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim compressor As SevenZipSfx = New SevenZipSfx(SfxModule.Default)
        compressor.ModuleFileName = "7z.sfx"
        compressor.MakeSfx("C:\Temp\cc_seal.7z", "C:\Temp\sfxseal.exe")
    End Sub

And it also worked for me without error. Take out the ModuleFileName line, and I got the same crash as you did.

Also notice that compressor.MakeSfx first argument needs to be a .7z file and not a .bat file. It will "work" but when you try to run the sfx.exe it will crash with something about it not being a valid 7zip file. So you'll need to compress your file/directory first.

Make sure 7z.sfx in in your application directory, or provide the path to it (it’s in the codeplex source download)

I tried it with the "7zxSD_All.sfx" file first, it extracts the file then Windows 7 gives an error about it not being installed correctly (I'm assuming Windows 7 thinks it's an install file and not a self extracting file). "7z.sfx" worked though.

这篇关于如何创建一个COM $ P $使用SevenZipSharp pssed SFX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆