0

I am looking to find the path of files in the resources of a VB application. The application is simple.

It will automatically make a .7z file into a self extracting and launching file.

3 parts to this, 7zS.sfx, config.txt and an .7z archive i.e. Fruits.7z

The 7zS.sfx and config.txt will never change, so I am hoping to embed them, the .7z archive will be dragged into the application.

Now I need to run a commmand which is: copy /b RESOURCE PATH\7zS.sfx + RESOURCE PATH\config.txt + C:\Users\%username%\Desktop\Fruits\Fruit_List.7z Fruits.exe

I have tried this several times with My.Resource.config.txt, put it loads the files as a byte. I need the file untouched the command prompt will handle it after constructed too.

MyUtilities.RunCommandCom("copy /b c:\FruitTemp\7zS.sfx + c:\FruitTemp\config.txt + C:\Users\%username%\Desktop\Fruit\FruitArchive.7z c:\users\%username%\desktop\Fruit.exe", "/C", True)


Shared Sub RunCommandCom(command As String, arguments As String, permanent As Boolean)
        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
        pi.FileName = "cmd.exe"
        p.StartInfo = pi
        p.Start()
    End Sub

The embedded resources are now run through the byte and stored in a temp location as you can see from the commands above. However this command will not run. It states the syntax is incorrect.

MrAnderson1992
  • 399
  • 1
  • 3
  • 11
  • The resources are usually embedded in your application. You have to take the byte array and write it to a file before you can use them with external applications. – Visual Vincent Jun 24 '16 at 09:39
  • So write the embedded file to a temp location and then run the command based on that temp location? Any tips how to do that? – MrAnderson1992 Jun 24 '16 at 09:57
  • `File.WriteAllBytes()` is a good start. – Visual Vincent Jun 24 '16 at 13:03
  • I have done this now and it works, which is a great thing. I have a problem though, when I add the .sfx file as a resource it can stay as .sfx or change to .txt no matter which one I do it becomes invalid and jumps from 800kb to 1500kb. The file is completely messed up and doesnt allow the command to be run. – MrAnderson1992 Jun 24 '16 at 13:05
  • Could you please elaborate that? I don't understand what you mean. You might also want to update your question with your new code (preferrably post it below your original question). – Visual Vincent Jun 25 '16 at 10:49

1 Answers1

0

Firstly, there are no resource files at run time. The whole point is that resources are compiled into the binary code of the EXE. Secondly, if you add a file named 'config.txt' to your resources then the resource property will be My.Resources.config. You can't have a property name with a dot in it.

So, you need to determine the type of that property and then save it to a file in the appropriate way. It will likely be either String or Byte(), so you can call File.WriteAllText or File.WriteAllBytes.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46