、PrincipalContextを使用してリモートホストに接続を閉じるにはどうすればよいですか?私はこのコードを実行
PrincipalContext oPrincipalContext = new PrincipalContext(
ContextType.Machine,
computer.Name,
null,
ContextOptions.Negotiate,
Settings.UserName,
Settings.UserPassword))
GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(
oPrincipalContext,
Settings.AdministratorsGroup);
リモートマシンへの接続が作成されます。私はcmd.exeで "net use"と書いています。
しかし、アプリを閉じる前にこの接続を閉じる方法はわかりません。
アプリを終了すると自動的に終了します。
public Dictionary<Principal, ComputerPrincipal>
GetMembersOfAdministratorsGroup(ComputerPrincipal computer)
{
var usersList = new Dictionary<Principal, ComputerPrincipal>();
var tempUsersList = new Dictionary<string, Principal>();
using (PrincipalContext oPrincipalContext =
new PrincipalContext(
ContextType.Machine,
computer.Name,
null,
ContextOptions.Negotiate,
Settings.UserName,
Settings.UserPassword))
{
using (GroupPrincipal oGroupPrincipal =
GroupPrincipal.FindByIdentity(
oPrincipalContext,
Settings.AdministratorsGroup))
{
if (oGroupPrincipal != null)
{
var result = oGroupPrincipal.GetMembers();
foreach (Principal user in result)
{
if (!tempUsersList.ContainsKey(user.Name))
{
tempUsersList.Add(user.Name, user);
usersList.Add(user, computer);
}
}
}
}
}
return usersList;
}
接続が開いているとの問題は何ですか? – mellamokb
userNameとUserPasswordを変更すると、エラーが発生したためリモートマシンに接続できません。複数のユーザー名を使用して同じユーザーが複数のサーバーまたは共有リソースに接続することはできません。サーバーまたは共有リソースへの以前のすべての接続を切断し、再試行してください。 – andDaviD