I have a batch script that I have loaded into my solution. How can I reference this from the VB.NET application I am building to execute it?
Rather than
Shell.execute("C:\Users\Me\Desktop\application.bat")
How can I call the application.bat that is packaged within my solution?
Get the startup path of your application using Application.StartupPath and append it to your .bat file name.
Related
I am using VB.net.
I have problem with this command: Process.Start(System.Configuration.ConfigurationManager.AppSettings("ALL_ORACLEINTERFACEFILE"))
In appsetting of web.config, we found:
The problem is like this: Basically, SMSToOracleInterface.exe does two tasks:
Create a files in a local folder
Copy the files to a folder on Server.
When I double click the exe file directly, it worked well. However, when I run the web application (the application that contain Process.Start...), it did only the 1st task. 2nd task is not done at all.
Really appreciate your help.
The answer is that when we click .exe file to run, it get my window credentials to access the folder on server. Meanwhile, when we run from web application, it doesn't have credentials to access server.
I know there are plenty of questions about this topic but I reviewed them and I couldn't find what I need.
I need to run an exe in VB.Net but that exe needs some files that are in the exe's folder. When I try to run the exe using Shell or Process.Start() the exe looks for those files in my app folder (and throws an error) instead of the exe original folder. I can't move my app exe nor the external exe.
Have you tried Directory.SetCurrentDirectory Method ? It sets the application's current working directory to the specified directory. change the example below with the path of the application you want to execute prior calling it.
Imports System
Imports System.IO
Directory.SetCurrentDirectory("C:\test")
Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory())
'Execute an application from C:\test
Output :
Current directory: C:\test
You might be able to use the Windows startup path:
exePath = System.Windows.Forms.Application.StartupPath
I am writing an application in VB.NET. In the app, I have a function which calls a Powershell script and places the resulting information in a text box.
I have two issues:
How to I ensure that when my app is published, the powershell script is included?
How do I reference the script in my code?
Currently, I simply give my function the full path to the script, which is in a folder on my Desktop. Obviously, this will not work once I deploy the app to other computers.
You will need to create a Setup project to get your script in place on your target system.
A first step is to change the Build Action to Content and Copy to Output Directory to Copy always.
Your Setup project can pick up the script from the VB app build result and put it in place when installing your app.
As for your question concerning the user configurable install path: The easiest way to handle this would be to add registry entry containing the selected program file path and have your app read the path from there.
i need to execute a .lnk file in vb.net (lnk file that points at an exe file).
how can i do?
shell("path/file.lnk")
don't works
thx you for help.
You didn't indicate your platform, but on Windows 7, use Process.Start to launch an application using a .lnk file:
Process.Start(pathToLink)
i have created a batch file and have added it to the project using add items. Basically what i am aiming at is to execute this file on a button click action.
I am using System.Diagnostics.Process.Start("hello.bat") command to run this file
i have changed the build action to resource for this batch file.
But when i run this program, it is not able to locate the batch file.
I am required to give a relative path as the path my vary from machine to machine. how can i make this file accessable using a relative path?
Resource puts it inside of your EXE as data. You can google how to write a vb.net resource to a file, use the io tempfilename function to get a tempfile and use that (appending .bat), then run the batchfile from the name you gave it.
If you can ship the .bat with your EXE, this is convenient for debugging and production:
* Put the batchfile in the BIN subdir (debug or release) with your exe. May have to click 'show all files' in project explorer to see these dirs. Right click the .bat and pick 'include in project'. Don't make it a resource.
Run it using application.startuppath & "\" & batfilename. (application.startuppath is only in winforms. You can google 'how to get exe path in vb.net console app' etc. if you need another way).