如何使用 SevenZipSharp 创建压缩的 SFX 文件? [英] How to create a compressed SFX file using SevenZipSharp?

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

问题描述

我将了解如何使用 SevenZipSharp 库创建 SFX.

首先我需要说我找不到任何属性来设置压缩级别,以及所有这些.

当我尝试制作文件的 SFX 时,出现此错误:

未将对象引用设置为对象的实例."

如果我尝试制作文件夹的 SFX,我会收到此错误:

拒绝访问路径‘C:	est’."

(但事实并非如此,我是管理员,我已经用更多可用的文件夹对其进行了测试...)

这是我试图理解所有这些的完整课程......:

导入 SevenZip公开课表1Dim dll As String = "7z64.dll"私有函数 SevenZipSharp_Compress_SFX(ByVal Input_DirOrFile As String, _ByVal OutputFileName As String) As Boolean尝试' 设置库路径SevenZipCompressor.SetLibraryPath(dll)' 创建压缩器Dim Compressor As SevenZipSfx = New SevenZipSfx(SfxModule.Default)' 设置 SFX 参数' ?' 开始压缩Compressor.MakeSfx(Input_DirOrFile, OutputFileName)Catch ex 作为例外'返回错误'文件未压缩抛出新异常(例如消息)结束尝试Return True ' 文件压缩结束函数Private Sub Button1_Click(sender As Object, e As EventArgs) 处理Button1.ClickSevenZipSharp_Compress_SFX("C:	estfile.bat", "C:7zSFX.exe")结束子结束班

<块引用>

更新:

@对于每个人:

请我向能回答我问题的人祈祷,至少您曾经创建过 SFX SevenZipSharp 告诉我我做错了什么以及如何解决它,而不是回答说它们是用户权限问题,请阅读评论.

解决方案

对于参数应该是什么,看起来可能有些混乱.以下代码适用于 codeplex 上的最新 SevenZipSharp 代码.

 Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)Dim 压缩器 As SevenZipSfx = New SevenZipSfx("7z.sfx")压缩机.MakeSfx("C:Tempcc_seal.7z", "C:Tempsfxseal.exe")结束子

我在您的示例中尝试使用 SevenZipSfx(SfxModule.Default),但未设置模块名称,我相信这就是未将对象引用设置为对象的实例"错误的来源,因为我这样做了:

 Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)Dim 压缩器 As SevenZipSfx = New SevenZipSfx(SfxModule.Default)压缩机.ModuleFileName = "7z.sfx"压缩机.MakeSfx("C:Tempcc_seal.7z", "C:Tempsfxseal.exe")结束子

它也对我有用,没有错误.取出 ModuleFileName 行,我遇到了和你一样的崩溃.

另请注意,compressor.MakeSfx 第一个参数需要是 .7z 文件而不是 .bat 文件.它会工作",但是当您尝试运行 sfx.exe 时,它​​会崩溃,因为它不是有效的 7zip 文件.所以你需要先压缩你的文件/目录.

确保 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:	est' 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:	estfile.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:Tempcc_seal.7z", "C:Tempsfxseal.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:Tempcc_seal.7z", "C:Tempsfxseal.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.

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

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