How to run a silent mode batch script command in vb.net - vb.net

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

Related

Download a (.exe) file through vb or cmd

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.

How to run an exe file from a Vb program

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)

How to execute .bat file without opening console window using wix custiom action

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"

Download a file and then execute it

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)

Shell (pushd) behavior in vb.net

I am shelling in the a few push d statements based on a list of users from the active directory. 2 for example are
java.exe -version
and
dir /s
The search actually seems to search the actual computer and output the files from their directory. However, the java.exe only outputs the actual output from the computer that it is being ran on.
Is this even possible to run a remote exe from the pushd statement? Any thoughts would be great.
Here is the code as of right now in a simplified version. Let me know if anyone would like more.
Dim sCommand as String = "pushd \\***\C$ && java.exe -version 2>>C:\Testfile.txt"
Dim sCommand2 as String = "pushd \\***\C$ && dir /s blah.blah>>C:\Testfile.txt"
For each SelectedItem in Listbx.SelectedItems
Dim ReplaceCommand as String = sCommand.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand, True)
Dim ReplaceCommand as String = sCommand2.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand2, True, -1)
Next
To me, you'll need to find on the remote computer first the location of the JAVA executable. Your commands you're executing on the shell will search your local defined paths, not the remote paths.
Consider this.
first execution is local > running java 1.6.0.23
then I pushd to another computer. I re-execute the same command.
Since i'm not in the remote directory containing the java.exe file, it'll process my path to find it. >same version is returned
I then change to the remote's Java container and re-execute the statement.
This time it's finding the remote Java.exe and processes the command.