Installing an application based from the installer path using process.start - vb.net

Hi how can I install an application for example it was stored in C:\Temp\Filename\Filename\abc.exe and using process.start. Here's my code
Dim wi = WindowsIdentity.GetCurrent()
Dim wp = New WindowsPrincipal(wi)
Dim path = "C:\Temp\Unzip\IDGo800_Minidriver_32.zip\IDGo800_Minidriver_32"
Dim runAsAdmin As Boolean = wp.IsInRole(WindowsBuiltInRole.Administrator)
If Not runAsAdmin Then
' The following properties run the new process as administrator
Dim startInfo As New ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase)
startInfo.FileName = "C:\Windows\System32\cmd.exe"
startInfo.Arguments = "msiexec /i " & path & "\IDGo800_Minidriver_64.msi"" ALLUSERS=1 /qn /norestart"""
startInfo.WindowStyle = ProcessWindowStyle.Normal
startInfo.UseShellExecute = True
startInfo.Verb = "runas"
Dim myProcess As Process = Nothing
Try
myProcess = Process.Start(startInfo)
Do
If myProcess.HasExited Then
Console.WriteLine("Install complete")
End If
Loop While Not myProcess.WaitForExit(1000)
Catch ex As Exception
MsgBox(ex)
End Try
End If

Go the answer already.
startInfo.Arguments = "/c msiexec /i " & path & "\IDGo800_Minidriver_64.msi"" ALLUSERS=1 /qn /norestart"""

Related

The process tried to write to a nonexistent pipe vb.net

I'm currently writing a sub in vb.net that is supposed to create and/or erase tasks in the task scheduler that comes with windows 10. The creation part works fine, but when I try to erase the task I get this error in the visual studio console: "The process tried to write to a nonexistent pipe", and the task is (of course) still there. I've looked for a solution but can't find anything similar. Here is the code:
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles sbAutoRun.Click
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub CMDAutomate()
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Dim sTime As String = teAutoRun.Time.ToString("HH:mm")
Dim sCmdCommand As String = "SCHTASKS /CREATE /SC DAILY /TN ""MyTasks\task"" /TR ""'" & My.Application.Info.DirectoryPath & "\program.exe' Auto"" /ST " & sTime & " /RL HIGHEST"
Dim sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"""
My.Settings.AutoRun = ceAutoRun.Checked
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.CreateNoWindow = True '<---- if you want to not create a window
StartInfo.UseShellExecute = False 'required to redirect
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
If My.Settings.AutoRun And Not My.Settings.AutoRunExists Then
SW.WriteLine(sCmdCommand)
My.Settings.AutoRunExists = True
Console.WriteLine(sCmdCommand)
ElseIf My.Settings.AutoRun And My.Settings.AutoRunExists Then
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
SW.WriteLine(sCmdCommand)
Else
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
My.Settings.AutoRunExists = False
Console.WriteLine(sCmdCommand2)
End If
SW.WriteLine("exit") 'exits command prompt window
SW.Close()
SR.Close()
My.Settings.Save()
End Sub
Thanks..
Ps: The commands work fine when entered by hand in the cmd.
Update: Changed this
sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"""
SW.WriteLine(sCmdCommand2)
SW.WriteLine("y")
and wrote it like this
sCmdCommand2 As String = "SCHTASKS /DELETE /TN ""MyTasks\task"" /F"
SW.WriteLine(sCmdCommand2)
Now it works fine.

VB.Net Process Start Info With Arguments

Hello Can Anyone please help me i have a code here but it wont work when i use the argumenets
maybe someone can help me out
Dim procStartInfo As New ProcessStartInfo
Dim InstallVirtualBoxSetup As New Process
Dim Output As String = InstallVirtualBoxSetup.StandardOutput.ReadToEnd()
'Run As Admin
With procStartInfo
.UseShellExecute = True
.FileName = My.Application.Info.DirectoryPath & "\Components\Virtualbox.msi" & """ -quiet -norestart -l vlog.txt VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUNCHSHORTCUT=0 VBOX_START=0 VBOX_REGISTERFILEEXTENSIONS=1"
.Arguments = My.Application.Info.DirectoryPath & "\Components\Virtualbox.msi" & """ -quiet -norestart -l vlog.txt VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUNCHSHORTCUT=0 VBOX_START=0 VBOX_REGISTERFILEEXTENSIONS=1"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
InstallVirtualBoxSetup = Process.Start(procStartInfo)
Output = InstallVirtualBoxSetup.StandardOutput.ReadToEnd
InstallVirtualBoxSetup.WaitForExit()
When using Arguments, you should supply a list of the arguments only, without the file being executed.
The FileName should just be the path to the executed\opened file.
Here's the code that's been changed to reflect this:
With procStartInfo
.UseShellExecute = True
.FileName = My.Application.Info.DirectoryPath & "\Components\Virtualbox.msi"
.Arguments = "-quiet -norestart -l vlog.txt VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUNCHSHORTCUT=0 VBOX_START=0 VBOX_REGISTERFILEEXTENSIONS=1"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With

How to run CMD commands and hide it

Hey i am programming in Visual Basic (VB.NET) and i am trying to run cmd commands without showing the cmd screen on the computer, I have the following code but i cant get it to hide it.. :(
Code:
Dim CMD As New Process
CMD.StartInfo.FileName = "cmd.exe"
CMD.StartInfo.UseShellExecute = False
CMD.StartInfo.RedirectStandardInput = True
CMD.StartInfo.RedirectStandardOutput = True
CMD.StartInfo.CreateNoWindow = True
CMD.Start()
Dim SW As System.IO.StreamWriter = CMD.StandardInput
Dim SR As System.IO.StreamReader = CMD.StandardOutput
SW.WriteLine("exit")
Process.Start("Cmd.exe", "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt")
Thread.Sleep(5000)
Ugly code aside, you can basically do it like this:
Dim CMD As New Process
CMD.StartInfo.FileName = "cmd.exe"
CMD.StartInfo.UseShellExecute = False
CMD.StartInfo.RedirectStandardInput = True
CMD.StartInfo.RedirectStandardOutput = True
CMD.StartInfo.CreateNoWindow = True
CMD.Start()
Dim SW As System.IO.StreamWriter = CMD.StandardInput
Dim SR As System.IO.StreamReader = CMD.StandardOutput
SW.WriteLine("exit")
Dim p2 As New Process
p2.StartInfo.FileName = "Cmd.exe"
p2.StartInfo.Arguments = "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt"
p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
p2.Start()
Thread.Sleep(5000)
Process.Start is a static method with a limited set of parameters for modifying its behavior.
So where you give the name of the .exe and the parameters via the static method
Process.Start("Cmd.exe", "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt")
, is similar to:
Dim p2 As New Process
p2.StartInfo.FileName = "Cmd.exe"
p2.StartInfo.Arguments = "/C systeminfo > C:\Users\" & Environment.UserName & "\Pictures\hello.txt",
p2.Start()
But by doing it like that you have many more options available, including the option to set the WindowStyle to hidden:
p2.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

Using cmd in VB, using commands and receiving output

I need to know, if you could help me, how to insert commands in vb then they run in cmd and i get the output.
I need to do "net localgroup Administradores a58465 /add" and get the error message if there is one.
Solution: `Dim myProcess As Process = New Process
Dim s As String
myProcess.StartInfo.FileName = "c:\windows\system32\cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.Start()
Dim sIn As System.IO.StreamWriter = myProcess.StandardInput
Dim sOut As System.IO.StreamReader = myProcess.StandardOutput
Dim sErr As System.IO.StreamReader = myProcess.StandardError
'sIn.AutoFlush = True
sIn.Write("cls" & System.Environment.NewLine)
sIn.Write("net user" & System.Environment.NewLine)
sIn.Write("exit" & System.Environment.NewLine)
s = sOut.ReadToEnd()
If Not myProcess.HasExited Then
myProcess.Kill()
End If
LB1.Text = s
LB1.Visible = True
sIn.Close()
sOut.Close()
sErr.Close()
myProcess.Close()`
Check out Process.Start. http://msdn.microsoft.com/en-us/library/0w4h05yb(v=vs.110).aspx
Also look for the ProcessStartInfo class, which will give you options on how to kick off an external process.
Console input and output can be made available to your program through ProcessStartInfo.

VB.NET Custom Game Launcher "If" statement error:

Lately I have been trying to build a custom launcher for my Java game in VB.NET.
The only problem is that the code:
Dim appData As String = Environment.GetFolderPath(SpecialFolder.ApplicationData) & "\.ProjectSpideynn\"
Public Async Sub Start_Click(sender As System.Object, e As System.EventArgs) Handles Start.Click
If File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
startInfo.FileName = "cmd.exe"
startInfo.Arguments = "java -Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
startInfo.UseShellExecute = True
Process.Start(startInfo)
End If
If Not File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar")
Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
startInfo.FileName = "javaw.exe"
startInfo.Arguments = "-Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
startInfo.UseShellExecute = True
Process.Start(startInfo)
End If
End Sub
It errors at the If Not File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar") and I cant figure out why.
Error: `An exception of type 'System.IO.IOException' occurred in Microsoft.VisualBasic.dll but was not handled in user code
Additional information: Could not complete operation since a file already exists in this path 'C:\Users\Spideynn\AppData\Roaming.ProjectSpideynn\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar'.`
Any help will be greatly appreciated!
try this:
the problem is that your if is wrong because exists() will return false so yu have
if not false then
that is the same than:
if true then
so youer statement is true you have to use an else in your fisrt IF
If File.Exists(appData & "Pulsar\ProjectSpideynn-Pulsar.jar") Then
Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
startInfo.FileName = "cmd.exe"
startInfo.Arguments = "java -Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
startInfo.UseShellExecute = True
Process.Start(startInfo)
else
My.Computer.Network.DownloadFile("*hidden-link*", appData & "\.ProjectSpideynn\Pulsar\ProjectSpideynn-Pulsar.jar","","",false,100 ,true)
Dim startInfo As ProcessStartInfo = New ProcessStartInfo()
startInfo.FileName = "javaw.exe"
startInfo.Arguments = "-Xmx1024M -Xms1024M -jar" & appData & "Pulsar\ProjectSpideynn-Pulsar.jar"
startInfo.UseShellExecute = True
Process.Start(startInfo)
End If
for the new error try to overwrite your file.