如何关闭dos程序编程实现关闭dos程序
我先用Findwindow 找到句柄后, 再用postmessage(hwnd,wm_close,NULL,NULL)
来关闭dos程序但是常常会弹出一个对话框(问是否。)怎么能直接关闭dos程序,而不让它弹出那个对话框
麻烦贴出代码看看
我先用Findwindow 找到句柄后, 再用postmessage(hwnd,wm_close,NULL,NULL)
来关闭dos程序但是常常会弹出一个对话框(问是否。)怎么能直接关闭dos程序,而不让它弹出那个对话框
麻烦贴出代码看看
/* The following lines of code need to be placed in file scope, in
one source file, in your project. */ #include <stdio.h>
#include <wincon.h>PROCESS_INFORMATION pi;int InitConsoleWindow()
{
STARTUPINFO si = {0}; // Initialize all members to zero
si.cb = sizeof(STARTUPINFO); // Set byte count AllocConsole(); // Allocate console window
freopen("CONOUT$", "a", stderr); // Redirect stderr to console // Display user message in console window.
fprintf(stderr, "Application stderr output window\n");
fprintf(stderr, "DO NOT CLOSE THIS WINDOW, ");
fprintf(stderr, "it will terminate your application!\n"); return CreateProcess(NULL,// address of module name
"cmd.exe", // address of command line
NULL, // address of process security attributes
NULL, // address of thread security attributes
TRUE, // new process inherits handles
CREATE_SUSPENDED, // creation flags
NULL, // address of new environment block
NULL, // address of current directory name
&si, // address of STARTUPINFO
&pi); // address of PROCESS_INFORMATION
}int nInit = InitConsoleWindow();
Sample Code - Termination Section/* The following two lines need to be placed in the normal termination
procedure for your application. */ TerminateProcess(pi.hProcess, 0);
CloseHandle(pi.hProcess);
可以直接得到DOS窗体句柄!
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>BOOL GetProcessList ()
{
HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
PROCESSENTRY32 pe32 = {0};
// Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == (HANDLE)-1)
return (FALSE);
// Fill in the size of the structure before using it. pe32.dwSize = sizeof(PROCESSENTRY32);
// Walk the snapshot of the processes, and for each process,
// display information. if (Process32First(hProcessSnap, &pe32))
{
DWORD dwPriorityClass;
BOOL bGotModule = FALSE;
MODULEENTRY32 me32 = {0};
do
{
bGotModule = GetProcessModule(pe32.th32ProcessID,
pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32)); if (bGotModule)
{
HANDLE hProcess;
// Get the actual priority class.
hProcess = OpenProcess (PROCESS_ALL_ACCESS,
FALSE, pe32.th32ProcessID);
dwPriorityClass = GetPriorityClass (hProcess);
CloseHandle (hProcess); // Print the process's information.
printf( "\nPriority Class Base\t%d\n",
pe32.pcPriClassBase);
printf( "PID\t\t\t%d\n", pe32.th32ProcessID);
printf( "Thread Count\t\t%d\n", pe32.cntThreads);
printf( "Module Name\t\t%s\n", me32.szModule);
printf( "Full Path\t\t%s\n\n", me32.szExePath);
}
}
while (Process32Next(hProcessSnap, &pe32));
bRet = TRUE;
}
else
bRet = FALSE; // could not walk the list of processes
// Do not forget to clean up the snapshot object. CloseHandle (hProcessSnap);
return (bRet);
}