Trying my first steps in c# : create local user account, check if os is english, german or something other, choose groupname and move into it
i am trying my first steps in c#. I am using c# 2010 express edition. 

so my first little projekt will be something easy:
My Idea: 
Check, do we have administation rights (are we admin)
Check, if a lokal user exists
check the os language to get the spelling for the groupname, eG in english name of administrator group is "Administrators", in German it is "Administratoren", if OS isnt English or German exit script
create user with given parameters
exit

optional: write a log file
optional2: giving the parameters for username, password, description, group(s) in an seperate ini-file or commandline
Masterlevel: getting all options with programmname.exe /?

My Code until now, with a lot of errors:

> Blockquote

using System;
using System.DirectoryServices;
using System.Globalization;
using System.Security.Permissions;
using System.Threading;

[assembly:SecurityPermission( SecurityAction.RequestMinimum, ControlThread = true )]

class CreateUser

{
    static void Main(string[] args)
    {
        try
        {

            // Parameter for the account
            string s_Username = "EmpService";
            string s_Password = "password";
            string s_Description = "Empirum Service User for Management";

            // string s_Group1 = "Administrators";
            // string s_Group2 = "Administratoren";


            // Check if Useraccount allready exists
            private bool Check(string s_username)
            {
            DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");

            foreach (DirectoryEntry child in entry.Children)
            {
             if (child.SchemaClassName == "User")
            {
             if (child.Name == s_username)
            {
                return true;
                 Console.WriteLine("User Account allready exists.");
            {
        } 
    }
    return false;
            

                public static CultureInfo CurrentCulture { get; };
if (CultureInfo.CurrentCulture.Name.StartsWith("de-"))
    

{
    string s_group= "Administratoren";
    Console.WriteLine (" OS Language is GERMAN.");
}
else 
{
    string s_group = "Administrators";
    Console.WriteLine("OS Language is NOT German.");
}
               
            // Create User Account
            DirectoryEntry NewUser = AD.Children.Add(s_Username, "user");
            
            // Useraccount-Settings
            NewUser.Invoke("SetPassword", new object[] { s_Password });
            NewUser.Invoke("Put", new object[] { "Description", s_Description });

            // Add User to a Group, for example  
            // Check if OS is German or English
            // if OS is english, use "Administrators" as group
            // if OS is german, use "Administratoren" as group

          

            // grp = AD.Children.Find("Guests", "group");
            // if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
            // needs to be completed   
         
            // SuccessMessage
            NewUser.CommitChanges();
            Console.WriteLine("EmpServiceBenutzer erfolgreich angelegt.");
        }
        catch (Exception err)
        {
            // ErrorMessage
            Console.WriteLine(err.Message);
        }}
    ;
}


i have so much errors, i think the syntax is broken somewhere. 
could anybody help to geh this running? 

thanks in advance

Peter

Trying my first steps in c# : create local user account, check if os is english, german or something other, choose groupname and move into it
===

i am trying my first steps in c#. I am using c# 2010 express edition. 

so my first little projekt will be something easy:
My Idea: 
Check, do we have administation rights (are we admin)
Check, if a lokal user exists
check the os language to get the spelling for the groupname, eG in english name of administrator group is "Administrators", in German it is "Administratoren", if OS isnt English or German exit script
create user with given parameters
exit

optional: write a log file
optional2: giving the parameters for username, password, description, group(s) in an seperate ini-file or commandline
Masterlevel: getting all options with programmname.exe /?

My Code until now, with a lot of errors:

> Blockquote

using System;
using System.DirectoryServices;
using System.Globalization;
using System.Security.Permissions;
using System.Threading;

[assembly:SecurityPermission( SecurityAction.RequestMinimum, ControlThread = true )]

class CreateUser

{
    static void Main(string[] args)
    {
        try
        {

            // Parameter for the account
            string s_Username = "EmpService";
            string s_Password = "password";
            string s_Description = "Empirum Service User for Management";

            // string s_Group1 = "Administrators";
            // string s_Group2 = "Administratoren";


            // Check if Useraccount allready exists
            private bool Check(string s_username)
            {
            DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");

            foreach (DirectoryEntry child in entry.Children)
            {
             if (child.SchemaClassName == "User")
            {
             if (child.Name == s_username)
            {
                return true;
                 Console.WriteLine("User Account allready exists.");
            {
        } 
    }
    return false;
            

                public static CultureInfo CurrentCulture { get; };
if (CultureInfo.CurrentCulture.Name.StartsWith("de-"))
    

{
    string s_group= "Administratoren";
    Console.WriteLine (" OS Language is GERMAN.");
}
else 
{
    string s_group = "Administrators";
    Console.WriteLine("OS Language is NOT German.");
}
               
            // Create User Account
            DirectoryEntry NewUser = AD.Children.Add(s_Username, "user");
            
            // Useraccount-Settings
            NewUser.Invoke("SetPassword", new object[] { s_Password });
            NewUser.Invoke("Put", new object[] { "Description", s_Description });

            // Add User to a Group, for example  
            // Check if OS is German or English
            // if OS is english, use "Administrators" as group
            // if OS is german, use "Administratoren" as group

          

            // grp = AD.Children.Find("Guests", "group");
            // if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
            // needs to be completed   
         
            // SuccessMessage
            NewUser.CommitChanges();
            Console.WriteLine("EmpServiceBenutzer erfolgreich angelegt.");
        }
        catch (Exception err)
        {
            // ErrorMessage
            Console.WriteLine(err.Message);
        }}
    ;
}


i have so much errors, i think the syntax is broken somewhere. 
could anybody help to geh this running? 

thanks in advance

Peter
