开发者

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);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜