[英]how to start a program using a windows service?
I created a windows service in c++ using visual studios and now I want the service to run an exe file. 我使用Visual Studio在C ++中创建了Windows服务,现在我希望该服务运行exe文件。 The service is set to start every time the computer starts
该服务设置为在每次计算机启动时启动
i know i need to use code to locate the path of the exe like C:\\MyDirectory\\MyFile.exe
but how to I actually run the file from the service? 我知道我需要使用代码来定位exe的路径,例如
C:\\MyDirectory\\MyFile.exe
但如何实际从服务中运行文件?
i read about the process start method here but i am not sure how to use it 我在这里阅读了有关流程启动方法的信息,但是我不确定如何使用它
You can use createprocess function in your service to run an exe. 您可以在服务中使用createprocess函数来运行exe。
TCHAR* path = L"C:\\MyDirectory\\MyFile.exe";
STARTUPINFO info;
PROCESS_INFORMATION processInfo;
ZeroMemory( &info, sizeof(info) );
info.cb = sizeof(info);
ZeroMemory( &processInfo, sizeof(processInfo) );
if (CreateProcess(path, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
::WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.