views:

26

answers:

0

Hey everyone,

I have 2 questions, maybe you could help me out.

  1. I built a DLL from the following code:

    using System; using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using System.Text;

namespace AutoAD {

public class Class1
{

    public static void addUser(string userName)
    {
        try
        {
            System.Console.WriteLine("Creating user {0} ", userName);
            DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
            DirectoryEntry NewUser = AD.Children.Add(userName, "user");
            System.Console.WriteLine("path is {0} ", AD.Path);
            NewUser.Invoke("SetPassword", new object[] { "#12345Abc" });
            NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET" });
            NewUser.CommitChanges();
            DirectoryEntry grp;


            grp = AD.Children.Find("Guests", "group");
            if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
            Console.WriteLine("Account Created Successfully");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.ReadLine();

        }
    }


    public static void Delete(string accountName)
    {
        try
        {
            DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
            DirectoryEntry user = localMachine.Children.Find(accountName, "user");
            localMachine.Children.Remove(user);
            user.Close();
            localMachine.Close();
            //Logger.Write(LogMessageType.Success, "Deleted Account " + accountName);
        }
        catch (Exception e)
        {
            throw e;
            //throw new LocalSecurityException(string.Format("deleting account {0} {1}", accountName, e.Message), "Account.Delete");
        }
    }

and a consul project containing only the following main func:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RunDll
{
    class Program
    {
        static void Main(string[] args)
        {
            AutoAD.Class1.addUser(args[0]);
            AutoAD.Class1.Delete(args[0]);

        }
    }
}

I don't know why but the main func won't invoke its two lines. each of them works fine separately but not sequentially. What could it be?

How can I set the new local users to be admins?

  1. Do you know of any code in c# which can configure the number of simultaneously active users in Win Server 2008 to be more than the default 2 ?

I'm sorry, it came out pretty long - but I don't expect you to read the above code carefully. just If you have any creative idea what could cause the main function invoke only 1 line and stop?

I'll appreciate any help