|
◆説明◆
|
|
アプリケーションの実行、終了待ちをするサンプルです。サンプルでは、メモ帳を開き、終了待ちします。 OSのインストール先によって、メモ帳のパスが違うので、違う場合は修正して下さい。
|
◆VBの場合◆
|
|
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Const STARTF_USESHOWWINDOW = &H1
Private Const SW_SHOWDEFAULT = 10
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const CREATE_NEW_PROCESS_GROUP = &H200
Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" ( _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As SECURITY_ATTRIBUTES, _
lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Const INFINITE = &HFFFF
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal _
dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
Public Sub Main()
Dim lngResult As Long
Dim StartInfo As STARTUPINFO
Dim ProcessInfo As PROCESS_INFORMATION
Dim SecurityAttributes As SECURITY_ATTRIBUTES
With StartInfo
.lpTitle = ""
.lpDesktop = ""
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = SW_SHOWDEFAULT
.lpReserved = ""
.lpReserved2 = 0
.cb = 68
End With
lngResult = CreateProcess( _
vbNullString, _
"C:\WINNT\NOTEPAD.EXE", _
SecurityAttributes, _
SecurityAttributes, _
False, _
HIGH_PRIORITY_CLASS + CREATE_NEW_PROCESS_GROUP, _
0&, vbNullString, _
StartInfo, _
ProcessInfo)
If lngResult <> 0 Then
Call WaitForSingleObject(
ProcessInfo.hProcess, INFINITE)
Call CloseHandle(ProcessInfo.hProcess)
End If
End Sub
|
◆VC++の場合◆
|
|
BOOL bResult;
STARTUPINFO StartInfo;
ZeroMemory(&StartInfo,sizeof(StartInfo));
StartInfo.lpTitle = NULL;
StartInfo.lpDesktop = NULL;
StartInfo.dwFlags = STARTF_USESHOWWINDOW;
StartInfo.wShowWindow = SW_SHOWDEFAULT;
StartInfo.lpReserved = NULL;
StartInfo.lpReserved2 = 0;
StartInfo.cb = sizeof(StartInfo);
PROCESS_INFORMATION ProcessInfo;
bResult = CreateProcess(
"C:\\WINNT\\NOTEPAD.EXE",
NULL,
NULL,
NULL,
FALSE,
HIGH_PRIORITY_CLASS + CREATE_NEW_PROCESS_GROUP,
NULL,
NULL,
&StartInfo,
&ProcessInfo);
if (bResult != 0)
{
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
CloseHandle(ProcessInfo.hProcess);
}
|
|