|
I am trying to retrieve the password age from Active Directory using the classes in System.DirectoryServices. how ever when I get that property it is returning a COM object. What do I need to do with that to get the password age out?
Cheers,
Andy.
|
|
|
|
|
"COM object" is not specific. Please tell us what type the debugger reports. You should also set a breakpoint after getting the property and examine the data in the object to determine what is exposed. You may have to declare COM interfaces to extract the data, but without knowing more it's difficult to help you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
"COM object" is not specific. Please tell us what type the debugger reports.
That IS what the debugger reports. To be exact it is a System.__ComObject
If I drop it into the watch window and expand it out it still gives me no new inforomation.
Heath Stewart wrote:
You may have to declare COM interfaces to extract the data
Maybe that is what I need to know. What COM interfaces do I have to declare? I have searched all over the place, MSDN, Google, Google Groups and this seems to be something that is just swept under the carpet. No one either knows or wants to know. There are a few VBScripts out there, but that does not really help me. Or perhaps my search terms are not quite right. I've searched on various combinations of: LDAP DirectoryServices DirectoryEntry PasswordAge Active Directory .NET C#
What I am trying to do is authenticate a user as they log in to my system (as described in How To Use Forms Authentication with Active Directory http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT02.asp[^]) and then warn them if their password is about to expire. Perhaps I am not looking at this from the right angle.
If it helps I wrote a little test app to try some things out. Perhaps I'm doing something wrong here:
static void Main(string[] args)
{
string thePath = "LDAP://company.co.uk/DC=company,DC=co,DC=uk";
string domainAndUsername = domain + @"\" + username;
Console.Write("Enter Password:");
string password = Console.ReadLine();
for(int i=0;i<300;i++)
Console.WriteLine();
DirectoryEntry entry = new DirectoryEntry( thePath,
domainAndUsername, password);
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return;
}
thePath = result.Path;
string theFilterAttribute = (string)result.Properties["cn"][0];
PropertyCollection coll = entry.Properties;
Console.Write("Number of properties: {0}", coll.Count);
foreach (string name in coll.PropertyNames)
{
PropertyValueCollection pvc = coll[name];
object val = pvc.Value;
if ((name == "minPwdAge") || (name == "maxPwdAge"))
Debugger.Break();
Console.WriteLine("{0}: {1}", name, val);
}
Console.ReadLine();
}
|
|
|
|
|
Take a look at WinNT Custom User Properties[^]. PasswordAge is a Time type, but I'm not sure why that would appear as __ComObject (which, btw, is more helpful to me than just "COM object"). You should dig through the related documentation from above about the Time type. I would expect this to be a VARIANT . You could try Marshal.GetNativeVariantForObject which would give you an IntPtr which you could then use (more than likely, but there are numerous ways) Marshal.PtrToStructure .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
hi there,
is it possible to add a custom property to an object during runtime?
i have a string that represents the property name and a type that represents the property type. i have to do that at runtime because both parameter values are not available before. would that be possible with emit? or do i need to create the whole clase with emit then?
regards, andré
|
|
|
|
|
Yes and no. You can't actually add a property at runtime to a class, but there are two options. You can compile a new class that's a derivative of the one you'd like to modify (and rely on polymorphism) using Reflection Emit or CodeDom. Read Emitting Dynamic Assemblies[^].
Another way is to create the illusion that you've added properties, but this only works for component model clients (like TypeConverter s, TypeDescriptor , and the PropertyGrid by implementing ICustomTypeDescriptor . You can read about it[^] in the .NET Framework SDK.
Basically, you override GetProperties like so:
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(this, true);
return props;
}
You would extend PropertyDescriptor (you wouldn't have to, but I often find it easier) to support creatable properties at runtime.
Again, though, this only works for clients of the component model that actually use the ICustomTypeDescriptor implementation. If you just tried to access such a property using early binding like myObject.MyNewProp then it would fail because that property isn't actually defined on the class.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
actually that's what i'm doing. but infragistics webgrid columns seem to accept just real-properties...
regards, andré
|
|
|
|
|
I need a help.
if i only click the master data grid link column, it has to pass that column value & display details in the grid below the master gird in the same asp.net form.( both master and details has to display)
i set the target as self,but it displays only the details grid.
help will be appriciated.
thanks
|
|
|
|
|
Your question belongs in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
How can i arrange data in an xml file alphabetically?
<?xml version="1.0" ?>
<names>
<name>>Matt Daimon</name>
<name>Kate Winsilet</name>
<name>Martha Stewarts</name>
<name>Will Smith</name>
<name>Britiny Spears</name>
<name>Jenifer Lopez</name>
<name>Jenifer Aniston</name>
</Names>
<pre>
Plz any sort of help will be gr8!
|
|
|
|
|
That's a rather ambiqous question. Do you want to have it sorted in the file and rewritten? You can do that with an XSL Transform that looks like so:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" standalone="yes"/>
<xsl:template match="Names">
<xsl:element name="Names">
<xsl:apply-templates select="Name">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="Name">
<xsl:element name="Name">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet> To transform the XML, you can do something simple like this:
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
class Test
{
static void Main(string[] args)
{
if (args.Length != 2) Environment.Exit(1);
Transform(args[0], args[1]);
}
static void Transform(string xml, string xsl)
{
XmlDocument doc = new XmlDocument();
doc.Load(xml);
XslTransform tran = new XslTransform();
tran.Load(xsl);
tran.Transform(doc, null, Console.Out, null);
}
} If you just want to read the data in and sort it, you can do something like this:
using System;
using System.Collections;
using System.IO;
using System.Xml;
class Test
{
static void Main(string[] args)
{
if (args.Length != 1) Environment.Exit(1);
Sort(args[0]);
}
static void Sort(string file)
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Names/Name");
string[] names = new string[nodes.Count];
int i=0;
foreach (XmlNode node in nodes)
names[i++] = node.InnerText;
Array.Sort(names, Comparer.Default);
foreach (string name in names)
Console.WriteLine(name);
}
} There's practically an infinite amount of ways you can sort this data - it just depends on your needs.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
How would I go about searching for a specific file on my local drives at runtime.
Something like this (psuedo code)
if (searchForFileMethod('myFile.dat')
// get the path to the file
else
// inform the user that file is not found
Any hints or tips would be appreciated.
Thanks,
Einar
|
|
|
|
|
A recursive method that calls Directory.GetFiles and Directory.GetDirectories
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks for the reply. That is just what I needed to get started. I figured it had to be something recursive.
Thanks,
Einar
|
|
|
|
|
Hello -
I'm working on a gui using Gtk in C#. My gui is periodically updated by a background thread to display status information. My problem is that the gui only refreshes the screen when the mouse moves over it. What I really need is for the gui to automatically refresh whenever it is updated.
I've seen posts that suggest using ThreadNotify to fix this problem. ThreadNotify does fire the method that I pass it, but the gui is still not refreshed until I move the mouse.
I've also tried using QueueDraw(), both on the Window and on the TextView that I am updating, but again it does not refresh correctly.
Any suggestions would be much appreciated.
Thanks!
Some test code that I have been playing around with follows:
namespace Test {
using System;
using System.Threading;
using Gtk;
using Glade;
using GtkSharp;
public class Test
{
[Glade.Widget] private TextView textview1;
[Glade.Widget] private Button button1;
[Glade.Widget] private Window window1;
private TextBuffer tb;
private ThreadNotify tn;
private Thread t;
private int cnt = 0;
public Test()
{
Gtk.Application.Init();
Glade.XML gxml = new Glade.XML (null, "test.glade", "window1", null);
gxml.Autoconnect (this);
tb = new TextBuffer(null);
textview1.Buffer = tb;
tn = new ThreadNotify( new ReadyEvent(Ready) );
t = new Thread(new ThreadStart(Fill) );
t.IsBackground = true;
Application.Run();
}
public void Fill()
{
int i = 0;
for ( ; ; )
{
cnt = i;
i = (i < 100) ? (i + 1) : 0;
tn.WakeupMain();
}
}
public void Ready()
{
tb.Insert(tb.EndIter, cnt.ToString() + "\n");
}
public void OnWindow1DeleteEvent (object o, DeleteEventArgs args)
{
t.Abort();
Application.Quit ();
}
public void OnButton1Clicked(object o, EventArgs args)
{
t.Start();
button1.Sensitive = false;
}
public static void Main()
{
Test t = new Test();
}
}
}
|
|
|
|
|
See Refresh . This forces an immediately invalidation and redraw of the control. Of course things work a little differently with GTK so I'm not sure. Since this is primarily a Microsoft development site, you might check with other sites more appropriate for CLI apps on non-Microsoft systems (or using non-Microsoft APIs like GTK).
Also, be sure than when you're updating your controls from a separate thread you do so in the thread that created the control using InvokeRequired and Invoke . We've discussed this many times in this forum, and you can click "Search comments" above to find those discussions if you're interested in learning more.
Again, though, that's true on Windows platforms. Of course, with the way threads are handled this is probably true on any platform.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I have an application that is using a panel to hold a bitmap, for a skin. What I wanted to do was to load the app, then launch the function on form load. It takes a few seconds to load the form, but by the time the form has finaly loaded the update process on the application is already complete. I need my users to know that an update took, place using a progress bar.
What is the easiest way to check that the main form is loaded, prior to the function firing ?
D
|
|
|
|
|
Seems like you are trying to do a something like a splash screen. If you application starts so fast maybe you can find a better way of notifing the user that an update took place.
|
|
|
|
|
Basically just looking to delay my function from firing right away.
|
|
|
|
|
A delay can be achieved with a Timer.
Set your timer interval to a specified amount of time (1000 = 1 second)
when your application starts, start the timer as well
In your timer TICK event, stop and dispose the timer, and execute your update function.
Jon G
www.Gizmocoder.com
|
|
|
|
|
One way would be to hook an event handler to Application.Idle in the handler you have for Form.Load. The Idle event will be raised right after the Form is actually visible to the user. Remember to unhook your handler for Application.Idle in your handler for it.
You could also use BeginInvoke, which basically uses WM_POST to acheive a delayed call. So at the end of your Form.Load handler, you could do something like "BeginInvoke(new EventHandler(MyFunction));"
|
|
|
|
|
Hi all,
In MAPI C# programming, I find that I can only send email to the
outlook express "out" folder, but can't program MAPI to ask it to send
the email directly. What should I do ?
Thanks
|
|
|
|
|
That's what the Mail API does. An server application implements the API which you use. What the server application does is up to its implementation.
If you want to send email directly, consume the SMTP protocol. I recommend you click "Search comments" directly above this forum and search for "SMTP". We've discussed this several times, and I have posted code before to get the MX record of the mail server (which is the server that you connect to over port 25) at http://www.codeproject.com/aspnet/emailvalidator.asp?msg=305731#xx305731xx[^].
The SMTP protocol is actually a very simple protocol, BTW, and you can read more about it at http://www.ietf.org/rfc/rfc0821.txt[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello all.
I'm handling the keypress event of a data grid. I would like to know if the CapsLock key is pressed or not, but I haven't found nothing to do it.
Is possible this ? Can anyone help me ?
Thanks.
|
|
|
|