如何使用C#计算内存的私有工作集?我有兴趣制作大致相同的数字taskmgr.exe.
我正在使用Process命名空间并使用类似WorkingSet64和的方法/数据PrivateMemorySize64,但这些数字有时会减少100MB或更多.
在Vista开发机器上,我成功使用此代码更改用户"管理员"密码:
directoryEntry.Invoke("SetPassword", "new");
Run Code Online (Sandbox Code Playgroud)
当我将它移动到我的Server 2008开发机器上时,代码不起作用,我被迫使用以下代码:
directoryEntry.Invoke("ChangePassword", new object[] { "old", "new" });
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么?
对于这两种情况,我都是这样创建了DirectoryEntry对象:
DirectoryEntry directoryEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1}", computerName, username));
Run Code Online (Sandbox Code Playgroud)
谢谢!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); …Run Code Online (Sandbox Code Playgroud)