vb.net在启动时执行批处理命令

时间:2015-05-17 13:10:29

标签: vb.net batch-file

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try ' install
    My.Computer.FileSystem.CopyDirectory(Application.StartupPath, "C:\xx\xx\", True)
    My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, "C:\xx\xx\ProgramXX.exe")
Catch ioEx As System.IO.IOException
    Console.WriteLine("IO") ' error, program already installed
End Try

Dim startInfo As New ProcessStartInfo("settings\internetexplorer.exe") ' build batch command
startInfo.WindowStyle = ProcessWindowStyle.Minimized
startInfo.WindowStyle = ProcessWindowStyle.Hidden
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = False
startInfo.Arguments = "settings\settings.<acronym title="JavaScript">js</acronym>"
Process.Start(startInfo) ' this is not started 
Process.Start("C:\xx\xx\ProgramXX.exe")
End Sub

安装正确,并在启动时运行。虽然没有启动settings \ internetexplorer.exe。

1 个答案:

答案 0 :(得分:0)

根据OP的编辑更新:

好吧也许它没有启动,因为它找不到可执行文件。如果您不介意使用操作系统shell启动该过程,可以设置UseShellExecute = True然后设置工作目录

Dim startInfo As New ProcessStartInfo("internetexplorer.exe")
startInfo.UseShellExecute = True
startInfo.WorkingDirectory = "C:\xxxx\xxx"

或更简单的是

Dim startInfo As New ProcessStartInfo("C:\xxxx\xxx\internetexplorer.exe")