我将了解如何使用SevenZipSharp库创建SFX。
首先,我需要说,我找不到任何属性来设置压缩级别,以及所有这些。
当我试图创建一个文件的SFX时,我得到了以下错误:
"Object reference not set to an instance of an object."如果我试图创建一个文件夹的SFX,我会得到以下错误:
"Access to the path 'C:\test' is denied."(但不是真的,我是管理员,我用更多的文件夹进行了测试.)
这是我试着理解所有这些的全班.:
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更新:
@每个人:
请有人回答我的问题--至少你曾经创建了一个SFX SevenZipSharp --告诉我我做错了什么以及如何修复它,而不是回答他们是用户权限问题,请阅读评论。
发布于 2013-05-03 23:55:29
在争论应该是什么的问题上,看上去可能有些混乱。下面的代码适用于我在codeplex上使用最新的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我尝试使用SevenZipSfx(SfxModule.Default),就像在您的示例中一样,但是没有设置模块名,而且我相信“对象引用没有设置为对象的实例”错误就是从那里来的,因为我这样做了:
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而且它对我也有效,没有错误。把ModuleFileName线拿出来,我就和你一样崩溃了。
还请注意,compressor.MakeSfx第一个参数需要是.7z文件,而不是.bat文件。它将“工作”,但当您尝试运行sfx.exe时,它会崩溃,因为它不是一个有效的7zip文件。因此,您需要首先压缩文件/目录。
确保7z.sfx在您的应用程序目录中,或者提供它的路径(它在codeplex源代码下载中)
我首先尝试使用“7zxSD_All.sfx”文件,它提取文件,然后Windows 7给出一个错误,说明它没有正确安装(假设Windows 7认为它是一个安装文件,而不是一个自解压缩文件)。不过,"7z.sfx“起了作用。
发布于 2013-05-03 08:13:53
您可能正在使用Windows 8,因此为了给应用程序足够的权限在(C:)分区中编写修改,您应该在"As Administrator“模式下运行应用程序,甚至您是管理员。
https://stackoverflow.com/questions/16069470
复制相似问题