3

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.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • There are a few things in my opinion I have noticed: first try setting up break points and see exactly where it is failing at. Secondly you can't compress a file and save it as an .exe with SevenZip (in your button click event). Third I have had the same case before (no able to get access to the path) and come to find out it was a permission issue. Have you actually gone into the security of that folder and check the permissions for yourself? – Trevor May 01 '13 at 05:16
  • of course like I said I'm sure this is not a permission issue, I'm admin user and I can create/delete/modify what I want, I don't had (never) any related problem with user permissions in my OS, I only have this problem with sevenzipsharp which is a lier, also I've tested it with files instead folders and then it launchs a different strange error that you can see in my question. also any folder/file tested was opened or in execution by any other process to launch that error. – ElektroStudios May 02 '13 at 05:20
  • I can't understand the reason why you said this: "Secondly you can't compress a file and save it as an .exe with SevenZip (in your button click event).", You can create a SFX so we can save it as exe, but it's not documented... I don't know how to do it. thankyou for your comment. – ElektroStudios May 02 '13 at 05:21

2 Answers2

2

You are probably using Windows 8, so in order to give your application the sufficient privileges to write-modify in (C:) partition, you should run the application in "As Administrator" mode even you're the admin.

IWIH
  • 417
  • 5
  • 17
  • Nope, How do you come to that conclusion?, I'm working in Windows 7, and like I said I'd never had ANY user permissions problem (NEVER, ANY), this is not a permissions issue, I don't need to start any program with admin rights 'cause I'm legitim admin, also I can do whatever thing with any file (for example compress using DotNetZip), but I can't make a SFX with sevenzipsharp, simple as this (but don't know if the solution is so simple as that) . thankyou anyway – ElektroStudios May 03 '13 at 09:17
  • @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. – ElektroStudios May 03 '13 at 09:23
  • @ElektroHacker After all, you have an answer, as I can see. But, for your knowledge, I read the comments before answering. I had same experience with writing to C: partition in windows 8, even when using admin-user, and I solved it with running the application in admin-mode. Contrary to window 7, using an admin-user is enough to write-modify within C: partition. Have a great day and code! :-) – IWIH May 04 '13 at 14:20
  • I appreciate everyones help and the "please read the comments" was not a special/sarcastic comment for you, only was a comment for everyone because I don't would more answers saying is a user permission issue. ps: sorry for my english and thanks! – ElektroStudios May 04 '13 at 15:24
2

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.

Ken Wilcox
  • 843
  • 7
  • 9