How do I rename the administrator on a given machine via c#(System.Management?)

I've found a few bread crumbs, but i have not as of yet figured this out.. here's what i know.

You're supposed to be able to do it using WMI via win32_useraccount.Rename,

You can call WMI stuff in c# via System.Management.

What I need is how to tie those two pieces of information togther to allow me to make the changes.

Can anyone help Give me a few more breadcrumbs to follow

Thanks,

 Eric-

 



Answer this question

How do I rename the administrator on a given machine via c#(System.Management?)

  • Shrek.NET

    Thanks!

    That worked perfectly!

    Eric-


  • brb.1977

    Can you suggest a different mechnaism by which the same thing can be achieved programatically, or is it impossible

    to do in Win 2k

    Thanks,

    Eric-


  • georgeduke

     

     

    Can anyone tell me how to do this in Win2k The XP code works perfectly, but aparently we are running on a few 2k machines as well, and the Rename method does not exist there.

    Thanks,

    Eric-


  • Woyler

    I was trying to look for this for you earlier but couldnt find one. the technet scripting guy article(s) did state that there was no way to rename an account in WMI since the Rename method does not exist in W2K. I also remember a previous colleague who I was with (who is a guru of infrastructure engineering) who suggested this at one point to me.....

    ...I think you maybe able to do it if it was on a domain (don't quote me)...looking at this here (its vbscript but can be easily converted to C# directoryServices classes)

    http://www.microsoft.com/technet/scriptcenter/guide/sas_usr_udgt.mspx mfr=true

    ill post anything else I find that may work with W2K

    another cool tool you can use to see what methods exist in the WMI for the current running version of Windows, is a WMI Code Creator by Microsoft - a cool nifty utility (pure genius in my opinion)

    http://www.microsoft.com/downloads/details.aspx familyid=2CC30A64-EA15-4661-8DA4-55BBC145C30E&displaylang=en



  • wangfang

    I figured out how to do this using renuser.exe...
    it's pretty simple the hardest part is finding a copy of renuser.exe.

    I found it on the Korean verison of the english site that everyone links to.

    http://www.ntfaq.co.kr/download/renuser.zip

    Eric-


  • x868

    some functions are not available on Windows 2000 (SP4). - the rename method overall does not exist in Windows 2000

  • Dave Jenkins

     

     

    Alas in this case they are not in a domain or on Active Directory... they chose to stay in the darkages,

    network management wise, and that's why i have to write software to do all this.

    Thanks, any help is greatly apprciated.

    Eric-


  • eldiener

    try this:

    ManagementObject theInstance = new ManagementObject("root\\CIMv2", "Win32_UserAccount.Domain='" + Environment.MachineName + "',Name='" + AccountName + "'", null);

    ManagementBaseObject inputParams = theInstance.GetMethodParameters("Rename");

    inputParams.SetPropertyValue("Name", newNameForAccount);

    ManagementBaseObject outParams = theInstance.InvokeMethod("Rename", inputParams, null);



  • How do I rename the administrator on a given machine via c#(System.Management?)