VB.NET Custom Game Launcher "If" statement error: - vb.net

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.

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

Play Star Wars in CMD with Visual basic

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

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.

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

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"""