2017-11-06 3 views
1

Microsoft.Management.Infrastructure名前空間を使用してリモートコンピュータに接続し、WMI情報を取得して動作させます。しかし、私がドメイン以外のPCに接続しようとすると、動作しません。誰でも私が間違っていることを特定することはできますか?私は、ローカルコンピュータのドメインとユーザー名のためのPARAMATERSとして取るべきかわからないWMIへの接続ドメイン外のPCへのC#によるリモート接続

string computer = "Computer_B"; 
string domain = "WORKGROUP"; 
string username = ".\\LocalAdminUserName"; 
string plaintextpassword; 

Console.WriteLine("Enter password:"); 
plaintextpassword = Console.ReadLine(); 

SecureString securepassword = new SecureString(); 
foreach (char c in plaintextpassword) 
{ 
    securepassword.AppendChar(c); 
} 

CimCredential Credentials = new 
CimCredential(PasswordAuthenticationMechanism.Default, domain, 
username,securepassword); 

WSManSessionOptions SessionOptions = new WSManSessionOptions(); 
SessionOptions.AddDestinationCredentials(Credentials); 

CimSession Session = CimSession.Create(computer, SessionOptions); 

var allVolumes = Session.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_LogicalDisk"); 

// Loop through all volumes 
foreach (CimInstance oneVolume in allVolumes) 
{ 
     Console.Writeline(oneVolume.CimInstanceProperties["SystemName"].Value.ToString()); 
} 

: は、ここでは、コードです。私はすでに行っている/以下しようと試み:リモート、ローカルコンピュータ上

  • 実行のWinRM quickconfigを私はKerberosを読んだ

  • 使用PasswordAuthenticationMechanism.Negotiate原因ドメインユーザーとパスワード

  • のためだけ
    作品
  • コンピュータを追加しました。ローカルコンピュータのTrustedHostsにコードを実行しました。また、*をTrustedHostsに追加しようとしました。

  • username = "computer_B \ LocalAdminUserName"に使用されます。私はドメイン= ""で試しました

私は間違って何をしていますか?

私が得るエラーは次のとおりです。WinRMは要求を処理できません。 [Negotiate authentication]を使用中に、次のエラーコード0x8009030eのエラーが発生しました。指定されたログオンセッションが存在しません。すでに終了している可能性があります。
これは、提供された資格情報がターゲットサーバー上で有効でない場合、またはサーバーIDを確認できなかった場合に発生します。サーバーIDを信頼する場合は、サーバー名をTrustedHostsリストに追加して、要求を再試行します。 winrm.cmdを使用して、TrustedHostsリストを表示または編集します。 TrustedHostsリストのコンピュータは認証されていない可能性があります。 TrustedHostsリストを編集する方法の詳細については、次のコマンドを実行します。winrm help config。

答えて

0

下記のコードを試してみてください。これは偽装ロジックで動作しています。

ConnectionOptions cOption = new ConnectionOptions(); 
       ManagementScope scope = null; 
       Boolean isLocalConnection = isLocalhost(machine); 

       if (isLocalConnection) 
       { 
        scope = new ManagementScope(nameSpaceRoot + "\\" + managementScope, cOption); 
       } 
       else 
       { 
        scope = new ManagementScope("\\\\" + machine + "\\" + nameSpaceRoot + "\\" + managementScope, cOption); 
       } 

       if (!String.IsNullOrEmpty(ACTIVE_DIRECTORY_USERNAME) && !String.IsNullOrEmpty(ACTIVE_DIRECTORY_PASSWORD) && !isLocalConnection) 
       { 
        scope.Options.Username = ACTIVE_DIRECTORY_USERNAME; 
        scope.Options.Password = ACTIVE_DIRECTORY_PASSWORD; 
       } 
       scope.Options.EnablePrivileges = true; 
       scope.Options.Authentication = AuthenticationLevel.PacketPrivacy; 
       scope.Options.Impersonation = ImpersonationLevel.Impersonate; 
       scope.Connect(); 
関連する問題