我现在需要做一个开机自启动(不用登陆)的服务程序,用来启动别的拥有窗体的进程,能做吗?关键是被启动的进程拥有窗体,在用户不登陆的情况下也可以启动吗?

解决方案 »

  1.   

    我也知道做成服务程序。
    我在onstart事件中,执行启动外部程序
    使用shellexecute(null,'open','f:\**.exe',nil,nil,SW_SHOWNORAML)这样的语句,用run /install安装后,在控制面板里服务就不能启动,说是内部错误
    是不是服务程序中启动的进程不能拥有窗体啊
      

  2.   

    我遇到过你这样的问题,利用 CreateProcess 创建进程的方式即可解决。
        STARTUPINFO si;
        PROCESS_INFORMATION pi;    ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );    // Start the child process.
        if( !CreateProcess( AppNamePath.c_str(), // No module name (use command line).
            NULL, // Command line.
            NULL,             // Process handle not inheritable.
            NULL,             // Thread handle not inheritable.
            FALSE,            // Set handle inheritance to FALSE.
            0,                // No creation flags.
            NULL,             // Use parent's environment block.
            NULL,             // Use parent's starting directory.
            &si,              // Pointer to STARTUPINFO structure.
            &pi )             // Pointer to PROCESS_INFORMATION structure.
        )
        {
    //        ErrorExit( "CreateProcess failed." );
        }    // Wait until child process exits.
        WaitForSingleObject( pi.hProcess, INFINITE );    // Close process and thread handles.
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );