Trying to create a batch file from VB 2010 Express
Why does a batch file run when I create it in Notepad, but not when I create it in my VB code?
Dim strStartFile As String = "C:\Documents and Settings\All Users\StartMenu\Programs\Startup\Starter.bat"
If Not File.Exists(strStartFile) Then
Dim strBatLine1 As String = "cd C:\Progra~1\Applic~1 &开发者_运维技巧amp;& start Application.exe"
My.Computer.FileSystem.WriteAllText(strStartFile, strBatLine1, False)
SetAttr(strStartFile, FileAttribute.Normal)
End If
It creates the file just fine. It looks exactly the same as the handmade version, it just won't launch the exe when double clicked. I've tried appending CR+LF, vbCrLf, but no go.
There is an inherent problem when trying to launch the exe directly from Startup, it runs it from that directory and can't find the related files (in the Application directory) so the cd is necessary.
Using VB 2010 Express. Thanks in advance for your help!
You probably need to pass in the Systems ANSI CodePage, because you are executing the file from cmd.exe
My.Computer.FileSystem.WriteAllText(strStartFile, strBatLine1, False, System.Text.Encoding.Default);
精彩评论