Dekaron-用于Win7 / Win2k8R2的服务器启动器
虽然很多朋友有了成品的工具,但是我发的是源代码。。。需要的可以拿去研究研究。。
// Win7_DKLauncher_v1.0 : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <io.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("Dekaron-Server Launcher by Toasty\n");
//查看文件“DekaronServer.exe”是否存在
if(_access("DekaronServer.exe", 0) == -1)
{
printf("DekaronServer.exe not found!\n");
printf("Program will close in 5seconds\n");
Sleep(5000);
}
else
{
//Only needed for the CreateProcess function below, no more use in this programm. More info at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
STARTUPINFO si;
//Structure where the CreateProcess function will write the ProcessID and ThreadID of the created Process. More info at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms684873(v=vs.85).aspx
PROCESS_INFORMATION pi;
//Debug event structure, needed for WaitForDebugEvent and ContinueDebugEvent. More info at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms679308(v=vs.85).aspx
DEBUG_EVENT dbge;
//Commandline that will used at CreateProcess
LPTSTR szCmdline = _tcsdup(TEXT("DekaronServer.exe"));
ZeroMemory( &si, sizeof(si) ); //Set memory of the startupinfo structure to Zero (because no initialization was made)
si.cb = sizeof(si); //Size of the Structure (see msdn)
ZeroMemory( &pi, sizeof(pi) ); //Set memory of the process_information structure to Zero (because no initialization was made)
//Start DekaronServer.exe
//More info fore CreateProcess function at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
if( !CreateProcess( NULL, // No module name (use command line)
szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
DEBUG_PROCESS,// Enables Debugging for the started Process http://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 0;
}
//Creating Process was sucessful
else
{
printf("Sucessfully launched DekaronServer.exe\n");
//Write ProcessId and ThreadId to the DEBUG_EVENT structure
dbge.dwProcessId = pi.dwProcessId;
dbge.dwProcessId = pi.dwThreadId;
while(true) //infinite loop ("Debugger")
{
WaitForDebugEvent(&dbge, INFINITE); //Wait for an debugevent to occur http://msdn.microsoft.com/en-us/library/windows/desktop/ms681423(v=vs.85).aspx
/*
<blockquote>通常,您必须在此处处理不同的调试事件(这些事件被写入dbge.dwDebugEventCode),
我是来学习的! 感谢楼主分享,我是来学习的 学习学习赞赞赞 每天报道一次! 学些大神分享,受用了
页:
[1]