当我尝试运行下面的代码时,我得到了
“值不能为空 . 参数名称:类型”
运行时出错 .
如何处理此异常以及为什么我的 objectName 在此处为空?我希望 objectName 能够在我的计算机上保存本地用户帐户的值 .
namespace Users {class EnableDisableUsers {public static void Main(string [] args){
Console.WriteLine("Enter user account to be enabled or disabled");
var user = Console.ReadLine();
Console.WriteLine("Enter E to enable and D to disable the user account");
string enableStr = Console.ReadLine();
bool enable;
var computer = ".";
if (enableStr.Equals("E") || enableStr.Equals("e"))
{
enable = true;
var objectName = "WinNT://" + computer + "/" + user + ",user";
dynamic objUser = Activator.CreateInstance(Type.GetTypeFromProgID(objectName));
objUser.AccountDisabled = false;
objUser.SetInfo();
Console.WriteLine(user + " Enabled = " + result.ToString());
Console.ReadLine();
}
else if (enableStr.Equals("D") || enableStr.Equals("d"))
{
enable = false;
var objectName = "WinNT://" + computer + "/" + user + ",user";
dynamic objUser = Activator.CreateInstance(Type.GetTypeFromProgID(objectName));
objUser.AccountDisabled = true;
objUser.SetInfo();
Console.WriteLine(user + " Enabled = " + result.ToString());
Console.ReadLine();
}
else
{
Console.WriteLine("Operation for " + user + " failed ");
}
}
}
任何帮助都会有用 .