Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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?
 
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 7-Apr-10 7:37am
Edited 7-Apr-10 12:48pm
v4

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

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 7 Apr 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100