5

I am trying to publish a C# application that does two main things. First, it runs a VBScript that goes into the SAP (Software solutions business) service and retrieves information in an excel type format. Then my program runs the main C# part and manipulates the data and then stores it into an excel file on the desktop. It works very well on my computer; However, I need to publish this application on three other computers and I am not sure how to do this since the VBScript file I am running is ran through a specific WorkingDriectory that is found on my computer. Is there another way I should be trying to run the VBScript or can I put the file in a spot that has the same working directory no matter where it is installed?

I cannot seem to find many resources for this (probably because I do not know the specific buzzwords) and have only seen VBS files run by using a directory as opposed to being part of the program itself. All other searches to find ways to run other scripts have resulted in the same outcome, running from a specific directory. I have also seen a lot of people say that it is not possible to have the VBScript as a file in the solution and run it right from the program itself.

  • 1
    In C#, you usually don't need to specify the folderpath to access the files that are on the same folder than your application. So, in a pinch, just drop your .vbs on the same folder of your app and call it without specifying anything else but the filename. – T. Sar - Reinstate Monica Jun 28 '17 at 16:21
  • 1
    Alex, what about the solution suggested by T.Sar, can you please give some feedback if this works for you or, if not, why not? – Doc Brown Jun 28 '17 at 17:03
  • Yes of course @DocBrown! So I did end up with converting my code to C#. This is my final solution because it was clean and since my file was not too big it did not take a long time. I chose to try this one first because of how straightforward it was. I also was able to achieve a good result using another method. I embedded the VBS file in the project and then extracted and executed it during runtime. This worked just as well but did not look as elegant. – Alex Bochel Jun 28 '17 at 20:17
7

I see a few possible options here. There are probably other ways about this, too.

  1. See Microsoft Visual Studio 2017 Installer Projects and the MSDN docs on it. This will let you set up an installer project for your C# project. You can specify to include the .vbs file and where on the target machine you want that file copied. You can put that file either in the same directory as the C# program executable, or somewhere like AppData, etc. Then, in your code, point to that location when looking for the .vbs script.

    • (+) This will provide a consistent and simple way to set up the app on each target machine.
    • (-) You'll have to make another project and it there's a slight learning curve to getting it set up correctly.
  2. You can execute the commands from the .vbs script from within your C# code. This eliminates the need for the extra .vbs file. This SO question covers how to do that, but there are resources all over if you Google it.

    • (+) You don't have to worry about the extra .vbs file
    • (+) All code for the app is in one place
    • (-) If the vbs code needs to change, then you'll have to recompiple and re-deploy on all machines
  3. Re-write all of the vbs code in actual C#. This might work if the vbs is short and simple, but I understand if there's a lot to it than this is a lot of extra work.

To answer your question more directly, though, usually files used by the program are kept in the same folder that the program will be installed in, or somewhere under AppData, such as \AppData\Local\MyProgram\MyProgramsScript.vbs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.