एक विस्टा देव मशीन मैं इस कोड सफलतापूर्वक इस्तेमाल उपयोगकर्ता को बदलने के लिए पर "व्यवस्थापक" पासवर्ड:DirectoryEntry पासवर्ड बदलने के लिए: विस्टा/Server2008 के बीच अलग-अलग व्यवहार
directoryEntry.Invoke("SetPassword", "new");
जब मैं इसे अपने सर्वर 2008 देव मशीन पर स्थानांतरित कर दी वह कोड काम नहीं करता था, और मुझे निम्नलिखित कोड का उपयोग करने के लिए मजबूर किया गया था:
directoryEntry.Invoke("ChangePassword", new object[] { "old", "new" });
मेरा प्रश्न है, क्यों?
दोनों ही मामलों के लिए, मैं इस तरह के रूप में मेरे DirectoryEntry वस्तु बनाया:
DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
धन्यवाद! 8)
यदि आप लोगों को यह उपयोगी लगता है, तो वास्तविक कोड है।
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.DirectoryServices;
using System.Security.Principal;
namespace AccountMod
{
class Program
{
static void Main()
{
Console.WriteLine("Attempting reset...\n");
try
{
String machineNameAndUser = WindowsIdentity.GetCurrent().Name.ToString();
String machineName = WindowsIdentity.GetCurrent().Name.ToString().Substring(0, machineNameAndUser.IndexOf('\\'));
Console.WriteLine("Computer's name: " + machineName);
ResetPassword(machineName, "Administrator", "new");
//ChangePassword("Administrator", "current", "new"); Console.WriteLine("Finished...");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Console.WriteLine(e.InnerException);
}
Console.ReadKey();
}
public static void ResetPassword(string computerName, string username, string newPassword)
{
DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
directoryEntry.Invoke("SetPassword", newPassword);
//directoryEntry.Invoke("ChangePassword", new object[] { "current", "new" });
}
}
}
किसी भी विवरण के बारे में आप जानते थे कि यह कैसे विफल रहा - यानी, क्या कोई अपवाद था? –
ओह, और यदि कोई अपवाद था, तो क्या आप पूरे अपवाद को पोस्ट कर सकते हैं? यही है, ex.ToString() के पूर्ण आउटपुट पोस्ट करें। –
कोई अपवाद नहीं। :( – sholsapp