I was trying to recreate the sourcecode for a launcher to a game I made that requires making and launching a .bat file. When it came time to wrap up the appended lines into a .bat, I found this error. I have researched, thoroughly even. The reason I am asking myself is because none of the answers I came across matched my case. The batch sets variables, echoes some text, then will launch the game. Here's the code, thank you for helping me. I will add more information if you need it, I'll be as helpful as I can.
sb.AppendLine("@echo off")
sb.AppendLine("set ttiUsername=" + username)
sb.AppendLine("set ttiPassword=password")
sb.AppendLine("set TTI_GAMESERVER=10.0.0.77")
sb.AppendLine("set TTI_PORT=7198")
sb.AppendLine("set /P PPYTHON_PATH=<PPYTHON_PATH")
sb.AppendLine("echo ===============================")
sb.AppendLine("echo Welcome to Toontown Rebuilt, %ttiUsername%!")
sb.AppendLine("echo You are connecting to server %TTI_GAMESERVER%!")
sb.AppendLine("echo The server port is %TTI_PORT%")
sb.AppendLine("echo ===============================")
sb.AppendLine("%PPYTHON_PATH% -m toontown.toonbase.ToontownStart")
Dim File As New System.IO.StreamWriter
File.WriteLine(sb.ToString())
Process.Start("C:\Toontown Rebuilt Source\ToontownRebuilt\Launcher.bat")
System.IO.StreamWriter constructor requires a parameter. The name of the file or the already created Stream where the successive Write
will dump the content of your string. You are missing that parameter.
But there are other issues that need a change here
Using File = New System.IO.StreamWriter("C:\Toontown Rebuilt Source\ToontownRebuilt\Launcher.bat")
File.WriteLine(sb.ToString())
End Using
The encapsulation in the Using statement ensures a proper closing and disposing of the stream
Another useful approach is File.WriteAllText
Dim file = "C:\Toontown Rebuilt Source\ToontownRebuilt\Launcher.bat"
File.WriteAllText(file, sb.ToString())