Click here to Skip to main content
16,011,784 members
Home / Discussions / C#
   

C#

 
GeneralRe: Datagridview cell painting Pin
Dan Neely20-Mar-09 10:12
Dan Neely20-Mar-09 10:12 
GeneralRe: Datagridview cell painting Pin
Henry Minute20-Mar-09 10:18
Henry Minute20-Mar-09 10:18 
AnswerRe: Datagridview cell painting Pin
Jake Myers29-Apr-09 22:34
Jake Myers29-Apr-09 22:34 
GeneralRe: Datagridview cell painting Pin
Dan Neely30-Apr-09 8:41
Dan Neely30-Apr-09 8:41 
GeneralRe: Datagridview cell painting Pin
Jake Myers1-May-09 4:20
Jake Myers1-May-09 4:20 
GeneralRe: Datagridview cell painting Pin
Dan Neely1-May-09 4:37
Dan Neely1-May-09 4:37 
GeneralRe: Datagridview cell painting [modified] Pin
Jake Myers1-May-09 5:06
Jake Myers1-May-09 5:06 
QuestionUnlocking account in AD Pin
Jacob Dixon18-Mar-09 7:53
Jacob Dixon18-Mar-09 7:53 
I am trying to lock and unlock accounts in Active Directory. This is what I have but it is giving this error:

System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="System.DirectoryServices"
StackTrace:
at System.DirectoryServices.DirectoryEntry.InvokeGet(String propertyName)
at ITApp.GetInfo.get_IsLocked() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 125
at ITApp.GetInfo.GetInfo_Load(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 37
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at ITApp.Main.button1_Click_1(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Main.cs:line 346
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ITApp.Program.Main() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
Message="Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
Source=""
ErrorCode=-2147467259
InnerException:



I am not realy understanding it, but this is the code I have to do this:

This is to get the adspath:
private object GetDN(string Name)
{
    object userDN = null;

    using (DirectoryEntry root = new DirectoryEntry())
    {
        root.Path = "LDAP://adem.arkansas.gov";
        using (DirectorySearcher searcher = new DirectorySearcher())
        {
            searcher.SearchRoot = root;
            searcher.SearchScope = SearchScope.Subtree;
            searcher.Filter = "(&(objectClass=user)(name="+Name+"))";
            searcher.PropertiesToLoad.Add("adspath");

            SearchResultCollection results = searcher.FindAll();

            if (results != null)
            {
                foreach (SearchResult result in results)
                {
                    ResultPropertyCollection props = result.Properties;
                    foreach (string propName in result.Properties.PropertyNames)
                    {
                        if (propName.ToLower() == "adspath") userDN = props[propName][0].ToString();
                    }
                }
            }
        }

        if (userDN != null) return userDN;
        else return null;
    }
}


This is to unlock/lock the account (got this from CodeProject.com):
public bool IsLocked
{
    get { return Convert.ToBoolean(dEntry.InvokeGet("IsAccountLocked")); }
    set { dEntry.InvokeSet("IsAccountLocked", value); }
}




This is how I am calling it:
private DirectoryEntry dEntry;

private void GetInfo_Load(object sender, EventArgs e)
{
    object GetDNString = GetDN("Dixon, Jacob"); // Get the adspath

    MessageBox.Show(GetDNString.ToString()); // This just shows me for testing purposes

    dEntry = new DirectoryEntry(GetDNString.ToString()); // Create the new DirectoryEntry with the adspath

    MessageBox.Show(IsLocked.ToString()); // This does return False
    IsLocked = true; // This is where it fails
}



BTW our AD is running at Server 2008.
QuestionHelp understanding C# sockets Pin
John Joger18-Mar-09 7:47
John Joger18-Mar-09 7:47 
AnswerRe: Help understanding C# sockets Pin
John Joger21-Mar-09 16:23
John Joger21-Mar-09 16:23 
QuestionXML root element changes after manipulating XML file. Need help. Pin
shira_me18-Mar-09 7:39
shira_me18-Mar-09 7:39 
AnswerRe: XML root element changes after manipulating XML file. Need help. Pin
bgato2k618-Mar-09 11:02
bgato2k618-Mar-09 11:02 
QuestionHow old is F# ? Pin
Mohammad Dayyan18-Mar-09 7:29
Mohammad Dayyan18-Mar-09 7:29 
AnswerRe: How old is F# ? Pin
Yusuf18-Mar-09 7:35
Yusuf18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:19
Mohammad Dayyan18-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Judah Gabriel Himango18-Mar-09 8:55
sponsorJudah Gabriel Himango18-Mar-09 8:55 
AnswerRe: How old is F# ? Pin
musefan18-Mar-09 7:35
musefan18-Mar-09 7:35 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 7:50
Ravadre18-Mar-09 7:50 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 7:57
0x3c018-Mar-09 7:57 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:07
Ravadre18-Mar-09 8:07 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:19
0x3c018-Mar-09 8:19 
GeneralRe: How old is F# ? Pin
Mohammad Dayyan18-Mar-09 8:26
Mohammad Dayyan18-Mar-09 8:26 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:38
0x3c018-Mar-09 8:38 
GeneralRe: How old is F# ? Pin
Ravadre18-Mar-09 8:46
Ravadre18-Mar-09 8:46 
GeneralRe: How old is F# ? Pin
0x3c018-Mar-09 8:55
0x3c018-Mar-09 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.