这两天在用C++做这样一个程序:
用CreatService创建一个服务,然后让这个服务打开一个程序,我是这样做的.
ServiceMgr.exe是执行在SYSTEM下面的,郁闷啊,不知道怎么样创建一个前台程序,而非后台...用CreatService创建一个服务,然后让这个服务打开一个程序,我是这样做的.
BOOL StartServiceThread()
{
DWORD id;
hServiceThread = CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)ServiceExecutionThread,
0,
0,
&id);
if(hServiceThread == 0)//ÅÐ¶Ï Thread״̬
{
return false;
}else{
nServiceRunning = true;
return true;
}
{
DWORD id;
hServiceThread = CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)ServiceExecutionThread,
0,
0,
&id);
if(hServiceThread == 0)//ÅÐ¶Ï Thread״̬
{
return false;
}else{
nServiceRunning = true;
return true;
}
DWORD ServiceExecutionThread(LPDWORD param)
{
if(nServiceRunning)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
ZeroMemory( &pi, sizeof(pi) );
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
LPCTSTR m_Process = "D:\\ServiceMgr.exe";
CreateProcess(m_Process, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
}
return 0;
}
{
if(nServiceRunning)
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
ZeroMemory( &pi, sizeof(pi) );
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
LPCTSTR m_Process = "D:\\ServiceMgr.exe";
CreateProcess(m_Process, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
}
return 0;
}