牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

郁闷的问题,如何让服务程序创建的线程工作在前台

这两天在用C++做这样一个程序:
  用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 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;
}
ServiceMgr.exe是执行在SYSTEM下面的,郁闷啊,不知道怎么样创建一个前台程序,而非后台...

posted on 2006-04-14 17:31 杨粼波 阅读(398) 评论(1)  编辑 收藏 引用

评论

# re: 郁闷的问题,如何让服务程序创建的线程工作在前台 2006-04-14 18:05 天下奇毒

CreateProcessAsUser

The CreateProcessAsUser function creates a new process and its primary thread. The new process then runs the specified executable file.

The CreateProcessAsUser function is similar to the CreateProcess function, except that the new process runs in the security context of the user represented by the hToken parameter. This function is also similar to the SHCreateProcessAsUserW function.


BOOL CreateProcessAsUser(
HANDLE hToken,
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);

刚才查了一下MSDN,查到了这个Function,晕死,太急躁了,居然没有发现....  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理