0

I have a .vbs file working perfectly, but only when I put it into the Debug folder. I want to get it from the Resources folder, so when the person executes the .exe file it will be there already. Any tips on how I can do this?

This is the piece of code I am using so far:

         Process scriptProc = new Process();
        //scriptProc.StartInfo.FileName = @"file.vbs";
        scriptProc.StartInfo.Arguments = path;
        MessageBox.Show(scriptProc.StartInfo.FileName = @config + ".vbs");
        scriptProc.Start();
        scriptProc.WaitForExit();
        scriptProc.Close();
Diego Fortes
  • 207
  • 2
  • 9
  • extract resource to temp path & then execute it !. – Parimal Raj Dec 16 '14 at 18:27
  • Thank you very much for your comment! Do you have any examples on how to do that? This is a "secret" file too as well, so the user could not see them at any moment, wouldn't this method be unsafe? – Diego Fortes Dec 16 '14 at 18:37

2 Answers2

1

You can follow this answer : How can I extract a file from an embedded resource and save it to disk?

Now regarding the comment about this file must be a secret, i would say :

if a file can be executed on user PC it certain can be accessed, all u can do make the accessing part hard, that way not everyone would be able to access it.

The script file u have cannot be executed by extracting it from memory (unless you write your own script runner). For now all you can do is extract file to temp path, execute it and delete it.

Community
  • 1
  • 1
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
  • Thank you for replying, this actually kinda helped me! I mean kinda mainly because I couldn't understand this piece of code, but instead I found a video-tutorial (https://www.youtube.com/watch?v=_61pLVH2qPk) which helped me a lot. It's the exact same logic, but he doesn't use a string array. It works just fine, tho. Maybe later I will focus on using a string array to make the code look better. Thanks a lot, man! – Diego Fortes Dec 17 '14 at 00:02
  • Edit: To make the file "secret", I made sure to make it hidden and delete right after using it. So the file is available for like 5 seconds only & it's hidden. Thanks again! – Diego Fortes Dec 17 '14 at 02:16
  • @DiegoFortes - glad i could be of help ! – Parimal Raj Dec 17 '14 at 08:52
0

To access VBS files (or any other kind of files) located in Resources.resx (or any other folder) and execute it simply follow this step-by-step tutorial w/ source-code included, that's how I made it!

If you get any erros about values being null, try doing this:

  1. Go to the folder where the files are located within Visual Studio;
  2. Right click on the file and select "Properties";
  3. On "Build Action" select "Embedded Resource".

Good luck!!

https://www.youtube.com/watch?v=_61pLVH2qPk

Diego Fortes
  • 207
  • 2
  • 9