簡體   English   中英

無法訪問遠程Windows服務

[英]Could not access Remote Windows Services

我有一個網站,用戶可以在該網站上對遠程服務器進行模擬/身份驗證,並控制特定的Windows服務。 如果我在本地運行該項目,則工作正常 ,但是當我將該項目發布到運行IIS服務器Web 服務器上時,它會出現一個異常:

無法在計算機(計算機名稱)上打開Service Control Manager。 此操作可能需要其他特權。

我的工作:

  1. 冒充的班級(在本地工作良好):

     public class ImpersonationUtil { public static bool Impersonate() { string logon = "ADMIN"; string password = "PASS"; string domain = "THEDOMAIN"; IntPtr token = IntPtr.Zero; IntPtr tokenDuplicate = IntPtr.Zero; WindowsImpersonationContext impersonationContext = null; if (LogonUser(logon, domain, password, 2, 0, ref token) != 0) if (DuplicateToken(token, 2, ref tokenDuplicate) != 0) impersonationContext = new WindowsIdentity(tokenDuplicate).Impersonate(); return (impersonationContext != null); } [DllImport("advapi32.dll", CharSet = CharSet.Auto)] public static extern int LogonUser(string lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); [DllImport("advapi32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)] public extern static int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken); } 
  2. 連接服務的代碼:

      ServiceController controller = new ServiceController("serviceName", "machineAddress"); var status = controller.Status; 
  3. Web.config的東西(要讀取並接受網絡服務器上的模擬):

    <system.webServer> <validation validateIntegratedModeConfiguration="false"/> </system.webServer>

有幫助嗎?

更改

if (LogonUser(logon, domain, password, 2, 0, ref token) != 0)

if (LogonUser(logon, domain, password, 9, 0, ref token) != 0)

未經測試,但我認為它應該現在連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM