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)
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 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 need a way of downloading a program through either visual basic or cmd. I have tried these, but the file after it's downloaded is only about 600 bytes and doesn't work. I own this website and have ftp access, if I download it through ftp it's fine. I'm using Visual Studio 2013 by the way. These are the methods I've tried:
CMD through VB:
Dim MyCmd, Ws, Ret
Ws = CreateObject("wscript.Shell")
MyCmd = "cmd /c Powershell.exe -ExecutionPolicy bypass -noprofile -WindowStyle Hidden (New-Object System.Net.WebClient).DownloadFile('http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe','C:\Users\user\Desktop\The_Map_Makers_Tool.exe'); Start-Process C:\Users\user\Desktop\The_Map_Makers_Tool.exe;"
Ret = Ws.run(MyCmd, 0, True)
VB:
My.Computer.Network.DownloadFile("http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe", "C:\Users\user\Desktop\The_Map_Makers_Tool.exe")
Thanks in advance :)
I think there is no built in tool in Windows that would do that for you. But there are plenty free programs on the web, that you can install and then call from your batch script. Here is one of them: CURL
Here is a basic example of how to use it (using your link)
#echo Off
Title
Pause
CD C:\Users\Jah\desktop
curl http://www.jah.com/ofac/downloads/t11sdn.pdf > download.pdf
This would download and save the file from the URL you have provided to download.pdf
Another possible alternative would be WGET.
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)
Am executing .bat file in custom action using wix. When i run the set up it successfully exceuting .bat file but with console window. I don't want any console window. It is possibe to hide window using wix or with .bat file.
Thanks in Advance
You can do:
start program args
exit
but this will open command line window for just a moment, until the program starts, afterwhich it closes. Alternatively, and equivalently, you can do:
Start "" "program args"
So, to start notepad and then exit the cmd terminal, you'd do:
start notepad
exit
or:
Start "" "notepad"