0
我有一個應用程序與OPC服務器交談。 當我將它作爲Windows服務運行時,它無法打開到OPC服務器的連接。 當我激活選項「允許服務與桌面交互」時,它可以工作! 但是,我怎樣才能使這作爲我的服務應用程序的默認值。 我試圖使用'CreateService'API函數的SERVICE_INTERACTIVE_PROCESS標誌,但它失敗了0x0057(無效的參數)。允許服務與桌面交互 - Windows服務與OPC服務器通信
// Install the service into SCM by calling CreateService
schService = CreateService(
schSCManager, // SCManager database
pszServiceName, // Name of service
pszDisplayName, // Name to display
SERVICE_QUERY_STATUS, // Desired access
SERVICE_WIN32_OWN_PROCESS, // Service type
dwStartType, // Service start type
SERVICE_ERROR_NORMAL, // Error control type
szPath, // Service's binary
NULL, // No load ordering group
NULL, // No tag identifier
pszDependencies, // Dependencies
pszAccount, // Service running account
pszPassword // Password of the account
);
if (schService == NULL)
{
wprintf(L"CreateService failed w/err 0x%08lx\n", GetLastError());
goto Cleanup;
}
對於pszAccount和pszPassword是NULL使用本地系統帳戶。如果服務類型參數沒有設置正確
schService = CreateService(
schSCManager, // SCManager database
pszServiceName, // Name of service
pszDisplayName, // Name to display
SERVICE_QUERY_STATUS, // Desired access
SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, // Service type
dwStartType, // Service start type
SERVICE_ERROR_NORMAL, // Error control type
szPath, // Service's binary
NULL, // No load ordering group
NULL, // No tag identifier
pszDependencies, // Dependencies
pszAccount, // Service running account
pszPassword // Password of the account
);
這正是我一直在嘗試的 – Matthias
我嘗試使用SERVICE_INTERACTIVE_PROCESS而不是SERVICE_WIN32_OWN_PROCESS。 – Matthias
您需要像這樣使用它們:SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS – CoreTech