windows中允許服務與桌面交互的更改方法
來源:易賢網(wǎng) 閱讀:2498 次 日期:2014-08-28 16:28:23
溫馨提示:易賢網(wǎng)小編為您整理了“windows中允許服務與桌面交互的更改方法”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了windows中允許服務與桌面交互的更改方法,需要的朋友可以參考下

在Windows服務的安裝類ProjectInstaller中加入以下方法:

 代碼如下:

protected override void OnCommitted(System.Collections.IDictionary savedState)

{

base.OnCommitted(savedState);

//將服務更改為允許桌面交互模式

ConnectionOptions coOptions = new ConnectionOptions();

coOptions.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope mgmtScope = new System.Management.ManagementScope(@"rootCIMV2", coOptions);

mgmtScope.Connect();

ManagementObject wmiService;

wmiService = new ManagementObject("Win32_Service.Name='這里是當前服務名'");

ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");

InParam["DesktopInteract"] = true;

ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);

}

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:windows中允許服務與桌面交互的更改方法
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網(wǎng)