Re: ADSI and C#
- From: "Victor Pereira" <taintmode@xxxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 14:10:15 -0300
Hi Marc,
I want to rename the logon name. Now i changed my approach and now i'm using
WMI. But my problem is: This code does not work in W2k, just in XP and 2003.
Do you know how can i do it in a W2k Enviroment ?
Look my code:
void RenameUsr(string hostname, string admusr)
{
try
{
ConnectionOptions oConn = new ConnectionOptions();
string myMachine = @"\\" + hostname + @"\root\cimv2" ;
string myQuery = "Select * from Win32_UserAccount WHERE Domain = " + "'" +
hostname + "'" + " AND SIDType = 1 ";
ManagementScope oMs = new ManagementScope(myMachine, oConn);
ObjectQuery oQuery = new ObjectQuery(myQuery);
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection queryCollection1 = oSearcher.Get();
foreach( ManagementObject mo in queryCollection1 )
{
try
{
string sLogin = mo["Name"].ToString();
if(sLogin.StartsWith("Admin"))
{
ManagementBaseObject iPar = mo.GetMethodParameters("Rename");
iPar["Name"] = admusr;
ManagementBaseObject outPar= mo.InvokeMethod("Rename", iPar, null);
uint ret = (uint)outPar.Properties["ReturnValue"].Value;
if(ret != 0)
{
MessageBox.Show("Error " + ret.ToString() + " trying to rename user");
}
}
}
catch(Exception ez)
{
MessageBox.Show(hostname + " " + admusr + " " + ez.Message);
}
}
}
catch(Exception zz)
{
MessageBox.Show(hostname + " " + admusr + " " + zz.Message);
}
}
}
Thanks in advance,
Victor
"Marc Scheuner [MVP ADSI]" <m.scheuner@xxxxxxxxxxxxxxxxxxx> wrote in message
news:s4v171l7lvk2hssn6i6eiros5d4djqkpfa@xxxxxxxxxx
> >I'm trying to rename the Administrator Login, and i want to know if my
> >approach is right:
>
> What do you mean by "rename"? What name (there are plenty!) do you
> want to change? The actual logon name? The LDAP object name? The
> display name ?
>
> Also, are you running on a local machine, or in a network?? If you're
> on a network, I'd STRONGLY recommend using LDAP instead of the
> deprecated WinNT provider.
>
> Marc
.
- Follow-Ups:
- Re: ADSI and C#
- From: Willy Denoyette [MVP]
- Re: ADSI and C#
- From: Marc Scheuner [MVP ADSI]
- Re: ADSI and C#
- References:
- ADSI and C#
- From: Victor Pereira
- Re: ADSI and C#
- From: Marc Scheuner [MVP ADSI]
- ADSI and C#
- Prev by Date: Re: casting Object to byte array
- Next by Date: Converting from Char to ASCII
- Previous by thread: Re: ADSI and C#
- Next by thread: Re: ADSI and C#
- Index(es):
Relevant Pages
|