How can I remove user local account of administrators group with the help of WMI in C#. (NOT using System.DirectoryServices
and System.DirectoryServices.AccountManagement
).
I have tried this code. but I don't know how to run it.
using (var myDeleteUser = new StreamWriter("DeleteUser.vbs"))
{
myDeleteUser.WriteLine("Set objAdminGroup = GetObject(\"WinNT://" + hostHame + "/" + Settings.AdministratorsGroup + ",group\")");
myDeleteUser.WriteLine("Set objUser = GetObject(\"WinNT://" + domain + "/" + userName + ",user\")");
myDeleteUser.WriteLine("objAdminGroup.Remove(objUser.ADsPath)");
}
EDIT: I try to do this:
Process proc = new Process();
proc.StartInfo.FileName = "DeleteUser.vbs";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
But I have an error(vbs permission denied Getobject) in VBS file.