Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hey everyone,

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

1. I built a DLL from the following code:
C#
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?

2. 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

===========

Fromk JSOP: I edited your title because the original version ("number of active users in Windows server 2008 using c#") was worded in such a way as to imply that you wanted to know how many users on windows server 2008 was using C#. Of course, there's no way to determine this with any reliability, but since that's not really what you meant, I'll leave it at that.
Posted
Updated 7-Apr-10 11:48am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900