2

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.

andDaviD
  • 555
  • 1
  • 11
  • 26
  • All this is doing is writing a 3 line VBScript file. Why would you do this? Just create the VBS yourself and run it. – Jimmy D Oct 21 '11 at 19:10

1 Answers1

0

You want the Win32_UserAccount Note the c# code implementation here - the delete on top of should be trivial

Enumerate Windows user group members on remote system using c#

Are you looking at deleting the account, or just remove from that group? If you want to remove from the group check out the Win32_GroupUser object. http://msdn.microsoft.com/en-us/library/windows/desktop/aa394153%28v=vs.85%29.aspx

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71