Public Structure PROCESS_INFORMATION Dim hProcess As Integer Dim hThread As Integer Dim dwProcessId As Integer Dim dwThreadId As Integer End Structure
Public Structure STARTUPINFO Dim cb As Integer Dim lpReserved As String Dim lpDesktop As String Dim lpTitle As String Dim dwX As Integer Dim dwY As Integer Dim dwXSize As Integer Dim dwYSize As Integer Dim dwXCountChars As Integer Dim dwYCountChars As Integer Dim dwFillAttribute As Integer Dim dwFlags As Integer Dim wShowWindow As Short Dim cbReserved2 As Short Dim lpReserved2 As Integer Dim hStdInput As Integer Dim hStdOutput As Integer Dim hStdError As Integer End Structure
Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _ ByVal lpApplicationName As String, ByVal lpCommandLine As String, _ ByRef lpProcessAttributes As String, ByRef lpThreadAttributes As String, _ ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, _ ByRef lpEnvironment As String, ByVal lpCurrentDriectory As String, _ ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Integer
分類:[.NET]
CreateProcessにて別プログラムを起動し、起動元のプログラムをすぐに終了させたいのですが、どうしてもうまくいきません。
System. TypeInitializationException
という例外が発生してしまいます。
CreateProcessからではなく、個別に起動させると正常に動作することは確認しています。
どなたか解決策をご存知の方、お助け下さい。
ちなみにソースは、
Public Structure PROCESS_INFORMATION
Dim hProcess As Integer
Dim hThread As Integer
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
Public Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As String
Dim lpDesktop As String
Dim lpTitle As String
Dim dwX As Integer
Dim dwY As Integer
Dim dwXSize As Integer
Dim dwYSize As Integer
Dim dwXCountChars As Integer
Dim dwYCountChars As Integer
Dim dwFillAttribute As Integer
Dim dwFlags As Integer
Dim wShowWindow As Short
Dim cbReserved2 As Short
Dim lpReserved2 As Integer
Dim hStdInput As Integer
Dim hStdOutput As Integer
Dim hStdError As Integer
End Structure
Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _
ByVal lpApplicationName As String, ByVal lpCommandLine As String, _
ByRef lpProcessAttributes As String, ByRef lpThreadAttributes As String, _
ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, _
ByRef lpEnvironment As String, ByVal lpCurrentDriectory As String, _
ByRef lpStartupInfo As STARTUPINFO, ByRef lpProcessInformation As PROCESS_INFORMATION) As Integer
と宣言しておき、
udtStartInfo.cb = Runtime.InteropServices.Marshal.SizeOf(udtStartInfo)
retc = CreateProcess(vbNullString, Program_Name, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, vbNullString, udtStartInfo, udtProcInfo)
となっています。