I use this code in VB to run an .EXE file that requires an input file and results in creation of an output file.
Process.Start("C:\glob.exe","C:\g.inp" )
It seems that the exe runs successfully but the output file don't get created.
Note when I run the exe file from cmd it makes the output files at the end so there's nothing wrong with the exe file.
Use the System.Diagnostics.Process with ProcessStartInfo to specify various parameters to launch your executable.
The Process class gives you more control on the launched program than the Shell function.
e.g.
Dim psi As New ProcessStartInfo
psi.FileName = "C:\glob.exe"
psi.Arguments = "C:\g.inp"
psi.Verb = "runas"
Process.Start(psi)
you can use shell function in vb.net
Shell("C:\procexp.exe", AppWinStyle.NormalFocus)
Related
The following code is what I've written to open an exe file using a Windows Service(VB.NET). What would be the best way to check whether the exe successfully run(I've tried to log StartInfo but did not see anything in the log file when I let the service run)?
I noticed the expected outcome via Windows Service is not the same as I open the exe manually by double clicking.
When I open the 'EdgePostSF.exe' manually, it creates a log file in the same destination of where the exe file exist with the name of 'EdgePostSF_(current_date).log'.
But when I use the following code to open it automatically doesn't not give me any error logged to the windows log file as I tried to log any using FileIO.WriteLog(output) also I do not see the EdgePostSF.exe log file created as well. After I check the 'task manager' I can see the 'EdgePostSF.exe' is running which confirms the windows service triggered the code and it started the application.
Using process As New Process()
process.StartInfo.FileName = "C:\Users\aglenn\Desktop\DataCollector\DataCollector\DataCollector\bin\Debug\EDGEPostSF.exe"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.Start()
' Synchronously read the standard output of the spawned process.
Dim reader As StreamReader = process.StandardOutput
Dim output As String = reader.ReadToEnd()
FileIO.WriteLog(output)
process.WaitForExit()
End Using
Tried reviewing Microsoft DOCS but couldn't find a right solution to my issue.
The reason I've used process.WaitForExit() is to give the EdgePostSF.exe it's own time to do the process and terminate(regardless of the time which I've given to Windows Service, currently I'm using 120000 milliseconds).
I'm trying to run an external program with some arguments (visual basic) and it was running all fine when executed from Visual studio Debug, but when using Release from visual studio or the published version(debug or release) there are no windows and the processes are running in Task Manager.
I tried this to modify the workingdirectory and windowstyle ProcessStartInfo properties with no results, that solved the similar cases asked here. In the task manager the opened program seems to stay "Under" my program in hiearchy vs when executed from VS ( not sure if that helps)
Dim startinfo As New ProcessStartInfo()
startinfo.FileName = slicerexepath
startinfo.WorkingDirectory = System.IO.Path.GetDirectoryName(slicerexepath)
startinfo.Arguments = arglist
startinfo.WindowStyle = ProcessWindowStyle.Normal
Process.Start(startinfo)
Cross check your "slicerexepath" is same for debug and release modes . In usual practice, release and debug exe are kept in separate path .
I have a .bat file that I am using to run a .Msi in silent mode. Now I wanna run that batch script command from vb.net. I tried using process.start(). Using process.start() opens the files, But the issue is the batch script is not executed and .Msi is not installed.I tried executing the same command directly from cmd and it worked.
Now, Can someone help me how I can execute that command form vb.net.(Can someone help me Write that command to the cmd window after starting the cmd process from vb.net). I tried using standardinput.Writeline(), It is opening the .txt files, But it is not working for executing the commands for installing the .Msi file.
Dim command As String="# echo off msiexec /i
""C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi"" /qn REBOOT=ReallySuppress echo pause >NUL shutdown.exe /r/t 000"
Dim proc As New ProcessStartInfo
proc.FileName = "cmd.exe"
proc.RedirectStandardInput = True
proc.RedirectStandardOutput = True
proc.CreateNoWindow = True
proc.UseShellExecute = False
Dim pr As New Process
pr.StartInfo = proc
pr.Start()
pr.BeginOutputReadLine()
pr.StandardInput.WriteLine(command)
Throwing this into your VBS will launch the batch script without a window or tray icon. This may be an easier way than trying to send commands to your batch window.
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "C:\Temp\YourFile.bat" & Chr(34), 0
I'm creating an application that downloads some applications (like FireFox, WinRar, RealPlayer) and then install them silently using Shell command. This is the code:
My.Computer.Network.DownloadFile("URL", "path\file.exe")
Shell("path\file.exe /s")
The problem is that the shell command starts before Download Is completed, so I get a "file not found" error. So my questions are:
How can I execute Shell command after the download is completed?
Can I use process.start with S parameter instead of Shell command?
This should do the trick to download the file and wait until its over:
Dim wc As WebClient = New WebClient()
wc.DownloadFile(sURL, sFile)
Is is possible to run cmd commands straight from VB. I want to be able to set up a command in vb without showing the black cmd window
path= C:\Program Files (x86)\Java\jre6\bin
java -Xmx1024M -Xms1024M -jar minecraft.jar nogui
Is it possible to run it without making a batch file? ( I want be be able to change some of the values in the commands to)
I found Shell(pathname[,windowstyle]) but I am not quite sure how to use it or if it is the right code.
You can use the Process class.
Dim pi As new ProcessStartInfo("C:\Program Files (x86)\Java\jre6\bin\java")
pi.Arguments = "-Xmx1024M -Xms1024M -jar minecraft.jar nogui"
Process.Start(pi)
I have use ProcessStartInfo to hold the process information before starting it off.
you can use Process.Start static Method
MSDN Link