I am trying to get my program to write a .bat file to run, it writes the file fine but the file wont run properly as it needs to be encoded with ANSI but i don't know how to set it to write that. Can someone help please?

The code for this part so far:

Private Sub start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start.Click
        If My.Computer.FileSystem.FileExists(".\run\run.bat") Then
            My.Computer.FileSystem.DeleteFile(".\run\run.bat")
        End If
        Dim map As String
        Dim crrtdir As String
        crrtdir = My.Computer.FileSystem.CurrentDirectory
        map = List1.SelectedItem
        My.Computer.FileSystem.CreateDirectory(".\run")
        My.Computer.FileSystem.WriteAllText(".\run\run.bat", crrtdir & "\srcds.exe -console -game " & game & " +map " & map, False)
        System.Diagnostics.Process.Start(crrtdir & "\run\run.bat")
    End Sub

Thank's

Recommended Answers

All 4 Replies

Use the StreamWriter class.

Dim writer As New System.IO.StreamWriter(fileName, False, System.Text.Encoding.Default)

Use the StreamWriter class.

Dim writer As New System.IO.StreamWriter(fileName, False, System.Text.Encoding.Default)

Thank you for your reply.
I am not quite sure how to use this could you or someone else help please?

Thank you for your reply.
I am not quite sure how to use this could you or someone else help please?

'Import System.IO and System.Text

        Dim fileName As String = "C:\Work\StreamWriterExample.txt"
        Dim myData As String = "This is what you want to write to the file."
        Dim writer As New StreamWriter(fileName, False, Encoding.Default)

        'to write to file, use .Write or .WriteLine
        writer.Write(myData)

        'close file and release resources
        writer.Close()
        writer.Dispose()

        'done

Thank's though i still can't get it to encode it as ANSI which i need as the bat file doesn't run properly unless its ANSI.

Does anyone know how to get it to encode it to ANSI?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.