jeudi 23 juin 2005 - Messages

LCS et WMI : activer ou desactiver les comptes Messenger

Voici un exemple de code simple  qui permet d’activer ou désactiver tous les comptes LCS.

Ce code a été testé sur le serveur LCS avec un utilisateur du goriupe RTCHSDomainServices, Adminitrators, Domain admins, Domain USers.

 

using System;

using System.Management;

namespace ConsoleApplication1

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class Class1

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

try

{

// code a executer sur le serveur

ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from MSFT_SIPESUserSetting");

foreach(ManagementObject temp in searcher.Get())

{

Console.WriteLine(temp["DisplayName"].ToString() +" | " + temp["Enabled"].ToString() +" | " + temp["UserDN"].ToString());

// On inverse les activations

temp.SetPropertyValue("Enabled",!(bool)temp.GetPropertyValue("Enabled"));

// On commit les changements

temp.Put();

Console.WriteLine(temp["DisplayName"].ToString() +" | " + temp["Enabled"].ToString() +" | " + temp["UserDN"].ToString());

}

}

catch(Exception ews)

{

Console.WriteLine(ews.Message);

}

Console.ReadLine();

}

}

}

 

 

posté par Memnoch avec 0 Commentaires