0

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")
676f6e65
  • 29
  • 4

2 Answers2

3

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())
Steve
  • 213,761
  • 22
  • 232
  • 286
1

Hi i use your code and fix your bug for launch bat.

This is my code in VB.NET:

        Dim sb As New StringBuilder
        Dim username As String

        username = "test"

        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 System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("C:\tmp\Launcher.bat", True)
        file.WriteLine(sb.ToString)
        file.Close()
        Process.Start("C:\tmp\Launcher.bat")
rdn87
  • 739
  • 5
  • 18