コード上でプログラムを実行する方法
実行プログラムの現在パスを取得する
Dim executePath As String() executePath = System.Reflection.Assembly.GetExecutingAssembly().Location.Split("\"c) Dim command As String = "" For i As Integer = 0 To executePath.Length - 2 command += executePath(i) & "\" Next System.Environment.CurrentDirectory = command
- 実行プログラムのパスには現在に実行プログラムのファイル名も含まれているため、プログラム名直円までをsplitで分解し、再構築する
- 現在のディレクトリを再設定する。(必要に応じて)
コマンドをプロセス上で実行する
Process.Start("execfile.exe", "1")
- 1個目のパラメータは実行ファイル名を設定
- 2個目移行はコマンド引数を設定することが出来る。