Windows服务问题

Windows Service issue

本文关键字:问题 服务 Windows      更新时间:2023-10-16

我正在尝试让windows服务使用c++。这项服务目前没有什么特别之处。服务运行的代码是

int main(int argc, char** argv) {
    if (argc != 1) return -1;
    ofstream fTestFile;
    fTestFile.open("C:\ABC\ServiceTest.txt", ios::app);
    fTestFile << "argc=" << argc << endl;
    for (int i=0;i <argc;i++)
        fTestFile << "argv " << i << "=: " <<argv[i] << endl;
    for (int i=0; i<100000; i++) {
        fTestFile << i << ",";
        if (i % 50 == 0) fTestFile << "n";
        Sleep(10);
    }
    fTestFile << "n";
    return 0;
}

当我在此服务上通过services.msc单击"启动"时,该服务尝试启动,但失败,返回(1053错误,响应时间过长)。在servicetest.txt文件中,我看到了一些数据,比如调试语句和2663之前的数字。

有没有我错过的一步,任何帮助都非常感谢。

谢谢

您的服务需要与服务管理器(services.exe)通信,以报告和更新其当前状态。

在此处阅读http://msdn.microsoft.com/en-us/library/windows/desktop/ms687414%28v=vs.85%29.aspx