Play Star Wars in CMD with Visual basic - vb.net

I know that the 2 commands I need to run are:
pkgmgr /iu:"TelnetClient"
Telnet Towel.blinkenlights.nl
I would like it to keep cmd open after running Telnet Towel.blinkenlights.nl.
This is what I have tried:
Dim start As New Process()
start.StartInfo.FileName = "cmd.exe"
start.StartInfo.Arguments = "/c pkgmgr /iu:" & """" & "TelnetClient" & """"
start.StartInfo.CreateNoWindow = True
start.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
start.StartInfo.UseShellExecute = False
start.Start()
System.WaitForExit()
Dim playSW As New Process()
playSW.StartInfo.FileName = "cmd.exe"
playSW.StartInfo.Arguments = "/k Telnet Towel.blinkenlights.nl"
playSW.Start()
playSW.WaitForExit()

You can use the Process's WaitForExit command to ensure a process is completed:
Dim start As New Process()
start.StartInfo.FileName = "cmd.exe"
start.StartInfo.Arguments = "/c pkgmgr /iu:" & """" & "TelnetClient" & """"
start.StartInfo.CreateNoWindow = True
start.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
start.StartInfo.UseShellExecute = False
start.Start()
start.WaitForExit()
Dim playSW As New Process()
playSW.StartInfo.FileName = "cmd.exe"
playSW.StartInfo.Arguments = "/c Telnet Towel.blinkenlights.nl"
playSW.Start()
playSW.WaitForExit()
Reference: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?view=netframework-4.7.2

Related

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

Command line works in command prompt but not in VB.NET

My command:
c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log
This works fine when executed by the command prompt.
But from VB.NET, it doesn't work (the log file was created but blank, the log file should contain log processes of abc.exe, abc.exe was not executed also).
Dim p as Process = new Process()
Dim pi as ProcessStartInfo = new ProcessStartInfo()
pi.Arguments = "/C c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log "
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
p.WaitForExit()
Why?
Update: While waiting for an explanation, this is my workaround.
Dim p as Process = new Process()
Dim pi as ProcessStartInfo = new ProcessStartInfo()
pi.Arguments = "c:\temp\abc.ini"
pi.FileName = "c:\temp\abc.exe"
p.StartInfo = pi
p.Start()
Dim output as String = p.StandardOutput.ReadToEnd()
p.WaitForExit()
WriteLog("c:\temp\log.log", output)

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.