|
Cool, works like a charm... thanks Aryadip!
So what's up with the values though, can you use them instead of the text?
Ron
|
|
|
|
|
Hey,
Anybody know how to generate a LM and NT hashes? This is for generating samba passwords.
Sample C# code would be greatly appreciated. Im writing a windows forms application. I need to be able to get text from a text box hash it to LM and NT then write it to my ldap server.
Cheers,
Rhys
|
|
|
|
|
First of all, it's "NTLM" not "LM and NT". It stands for "Windows NT LAN Manager". The older "LM" just refers to LAN Manager (before NT, but still supported in part).
Second of all, it's not just a simple hash like MD5 or SHA1. The server creates a 16-byte random number (the challenge). The client hashes the password and encrypts the challenge with it. This is the response. If it's the client hash you're talking about, this is described in the Samba ENCRYPTION[^] documentation.
Why are you communicating with the LDAP server directly, though? If possible, you should use the negotiate security package, or Windows Integrated security. Since the hash of the password will always be the same, sending across the wire would be subject to replay attacks. A cracker wouldn't need the plain-text password - the hash would suffice, which is why the server sends a challenge to the client with either authentication request to be encrypted (the response).
You should go through the proper "channels" to authenticate the user, not do it yourself. One such easy way is to call the LogonUser API. This negotiates the security package and authenticates the user. If youre LDAP server is part of the Active Directory domain, there should be no problems doing it this way.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Aight, cool thanks for that, that clears things up for me a bit.
I'll give a little more background... My clients/users will be authenicating with with samba. My openldap Server is being used for a samba backend. I am writing a windows app to manage the directory backend, that is adding users and so on. The directory seems to store the the password in two seperate attributes: sambaLMpassword and sambaNTpassword.
Currently I have to two ways of adding users: (1)using the smbpasswd samba tool wich generates the passwords it self and (2)also the idealx smbldap-tools, wich use a little linux util called mkntpwd wich when you feed it a string it spits out two hases a LM and a NT. Both of these are command line tools, I'd like to try my hand a creating a small and usable windows GUI.
Kind Regards,
Rhys
|
|
|
|
|
My suggestion would be, then, to find the source for those two utilities. Being open-source software, it's around somewhere. You might check the Samba web site[^]. They probably have CVS instructions somewhere - typically - to download the source. You could see how they do it, then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have the following code but i don't know c++ language.
How to write in C# language ?
http://www.codeguru.com/Cpp/controls/treeview/misc-advanced/article.php/c679/
Anybody can ?
|
|
|
|
|
We LEARN by doing!
At least make an attempt at it, then we can help you with any problems. If you read the code and then look up keywords in the Visual Studio Help for C++, you can read what it does and translate into C#. C# and C++ are different languages, but not as much as you might think.
RageInTheMachine9532
|
|
|
|
|
Just wondering how this can be accomplished? I've played with fraps so I know it can be done. Just wondering how difficult ^^
|
|
|
|
|
Hi. I'm new to C# and I'm trying to create
C# implementations of Controls I did in
Delphi in the past. In Delphi there is
a flag 'csDesigning' that will be set in
'ComponentState' if you're in design mode.
Using that I can do stuff like create a
Guid String to get a unique program ID
and the control can do stuff like File
Mapping or whatever to share data between
instances of the same app etc..
In C# I see something called 'DesignMode'
but it seems like it's always false!
Is there an easy way to set properties
when a UserControl is dropped on a form
that will be the same for all instances
of the application?
IOW, if I create a Guid String just using
a constructor I'll get a different string
for each app instance when I want the
property values to be the same for all
app instances, but be unique in each
app where the control is used.
This one has me baffled!
TIA
|
|
|
|
|
hi,
Well at design time youi can set a default value to whatever property you are defining in your custom control. Here is the way to do that
// Attribute applied to a property.
[DefaultValue(false)]
public new bool TabStop {...
}
and also you can use
System.Windows.Forms.Design.ControlDesigner
class to give the design time support to your control. Here you need to override the Initialize method to do all your custom setting of properties.
Hope this helps you...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Wow! That's like, way too much work.
All I'm trying to do is create a convenience
where a component is dropped on a form and
a unique string is generated to ID the app
as a property of the component.
I'm coding a simple instance component where
the programmer can set the number of concurrent
instances allowed to run on the same machine.
In the Delphi version (s)he just has to drop
it on the form and call one method on app startup.
Looks like in C# I'll have to settle for a string
property with a suggestive name( "GuidString" )
to hint that the programmer should use a Guid
Generator utility to paste a unique string in
this property. It works just as well but it's just cooler if it would fill in without the programmer's intervention. Unfortunately
with C# if you use any contructor you get
a different Guid every time the form is
created, which is no good for my purpose.
Oh well.. can't have everything I guess!
Thanks for the info. I would have looked
around for days only to find there ain't
no easy way to do it!
|
|
|
|
|
Just FYI after playing around for
about 6 hours I hacked my way into
a component that will initialize
the way I want when dropped on
a form.
Maybe I'll work up a short article
showing how 'cause it's definitely
a feature that's very convenient.
When my C# programming book arrives
in the mail I'll consult that first
of course.
|
|
|
|
|
I am trying to customize PrintPreviewDialog for changing functionality of existing buttoms and add a few new buttons using C#, please tell me which dll need to be imported and what are the various methods available or need to be overriden for the same.
Sample code will help a lot.
regards
|
|
|
|
|
Did you read the documentation for the PrintPreviewDialog ? It states right at the bottom: the System.Windows.Forms.dll assembly. Read the documentation to learn what you can override. You will need to use Reflection to change existing behavior for buttons and other controls, however. The PrintPreviewDialog extends Form and just hosts a PrintPreviewControl with some buttons and combo boxes. You might consider a similar approach which would be easier depending on how much you want to change.
Just extend the Form class and host an instance of the PrintPreviewControl . Add your own controls and behavior to the form.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your valuable suggestion. I am using PrintPreviewControl to make customized dialog, but the problem is that, how to integrate vertical scroll bar with next/previous page in co-ordination with the present zoom status. please do suggest
regards
|
|
|
|
|
I suggest you look at how the PrintPreviewDialog works. Download something like .NET Reflector[^] and find the PrintPreviewDialog in the System.Windows.Forms assembly. Use the decompiler to see how it works.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can't find the equivalent to PostMessage in Windows Forms. I'm currently using BeginInvoke, as it's much like it, but then I get memory leaks, since I ignore the AsyncResults. What should I do with them? Store them in a queue which I walk through later to see if the Completedflag is set and can then safelly call endinvoke?
Thanks in advance
|
|
|
|
|
You won't get memory leaks if you ignore AsyncResult s. .NET is GC'd. More than likely you're not using Control.InvokeRequired and Control.Invoke to call methods and get/set properties on controls created in a different thread. This is a common problem. When you comunicate with a control that was created on a different thread (the UI thread), you must use the ISynchronizeInvoke impementation that every control inherits from Control . This makes sure that communciate with the control happens in the UI thread.
If you want PostMessage , why not just P/Invoke it? If you read the forms, we're continually telling people to P/Invoke SendMessage to send the message immediately, but P/Invoking PostMessage is really no different. It would just look like this:
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
IntPtr lParam); If you need to pass a struct or reference to a struct or something, instead of marshaling the struct yourself and passing it as an IntPtr , you could overload PostMessage like so:
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
int wParam,
ref LVITEM lvItem); Of course, you'd need to declare a managed LVITEM struct (can be named whatever you like, though) that would marshal correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much for your answer. Although I don't agree on your discussion, I'll use the code you gave me.
I tested calling BeginInvoke(Nada) a hundred thousand times and then GC.Collect(); The memory footprint after the collection was over a hundred megs. ??? And the reason I ask is that I do use BeginInvoke, but am not satisfied with it. And Invoke is no option since it causes deadlocks in my case. (The UI is updated from a background process.)
|
|
|
|
|
Doesn't really matter if you don't agree with me - it's documented in the .NET Framework SDK. I suppose, then, that you disagree with Microsoft.
I didn't say that ignoring the AsyncResult s doesn't incur a certain performance hit with memory consumption, I said it didn't incur any memory leaks. There is a difference. The very fact that the GC was able to collect the unused references proves that the objects where indeed tracked. The GC would've collected them eventually.
Memory leaks are when memory is lost and unreferenced, so it cannot be freed again, like when a variable references an alloc'd region of memory which is not freed. Once that variable goes out of scope it's practically impossible to free that memory again.
The fact remains that calling methods or setting properties (often getting as well) on controls from a different thread may cause problems. This is what's documented well in the .NET Framework if you read the right topics. Sometimes things may work. Other times they may not. Often times it is certain functionality that doesn't work as expected. It call comes down to the synchronization of threads, like it or not.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have two clients installed on my PC.
Q1: How do I test/investigate (generally) a workstation to find out what email clients are available on a PC ?
I have a Class called OutlookConnector.CS that I use to retrieve the emails from my Outlook Client.
Q2: Is there a similar class for Outlook Express ?
Thanks in advance ! 
|
|
|
|
|
wfe wrote:
How do I test/investigate (generally) a workstation to find out what email clients are available on a PC ?
Nothing in the Windows API will supply you with this info. You'll problably have to search through the installed applications list, looking for specific application names, or go through the registry, or just ask the user what they use.
wfe wrote:
Is there a similar class for Outlook Express ?
Don't know. What does this class do? Where did it come from? If the class you have is pretty general in nature, then the same class might work for Outlook Express since you programatically use both of them the same way.
RageInTheMachine9532
|
|
|
|
|
 Thanks Dave,
Q1a: How do I search 'installed applications list' on a local PC from C#/.NET ?
Q1b: How do I search the registry ?
If I ask the user for what they use, I still have the problem of addressing the mailboxes locally on Outlook Express. Also, I would like to learn the Windows API and general environment by making the application 'fool proof'.
I don't know where the class came from - probably a former colleaque of mine.
I have enclosed the class below.
Thanks for your help
William
<br />
using System;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.Windows.Forms;<br />
<br />
namespace test<br />
{<br />
public delegate void OutlookItemProcessed();<br />
<br />
public class OutlookConnector : IDisposable<br />
{<br />
private Outlook.Application objOutlook = null;<br />
private Outlook.NameSpace objNamespace = null;<br />
private Outlook.MAPIFolder objFolder = null;<br />
private Outlook.Items objItems = null;<br />
public event OutlookItemProcessed ItemProcessed;<br />
<br />
public OutlookConnector()<br />
{<br />
objOutlook = new Outlook.ApplicationClass();<br />
objNamespace = objOutlook.GetNamespace("MAPI");<br />
}<br />
<br />
public void Dispose()<br />
{<br />
if (objOutlook != null) objOutlook.Quit();<br />
}<br />
<br />
public int getFolderCount(Outlook.OlDefaultFolders folder)<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(folder);<br />
return objFolder.Items.Count;<br />
}<br />
<br />
public DataSet getCalendarDataSet()<br />
{<br />
Outlook.AppointmentItem item;<br />
DataSet rv = new DataSet();<br />
rv.DataSetName = "Calendar";<br />
rv.Tables.Add("Appointment");<br />
rv.Tables[0].Columns.Add("Subject");<br />
rv.Tables[0].Columns.Add("Location");<br />
rv.Tables[0].Columns.Add("Start");<br />
rv.Tables[0].Columns.Add("End");<br />
rv.Tables[0].Columns.Add("AllDayEvent");<br />
rv.Tables[0].Columns.Add("Duration");<br />
rv.Tables[0].Columns.Add("Organizer");<br />
rv.Tables[0].Columns.Add("Importance");<br />
rv.Tables[0].Columns.Add("Sensitivity");<br />
rv.Tables[0].Columns.Add("Body");<br />
<br />
try<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);<br />
Debug.WriteLine(objFolder.Items.Count + " Appointments found.");<br />
for (int i=0; i < objFolder.Items.Count; i++) <br />
{<br />
item = (Outlook.AppointmentItem)objFolder.Items.Item(i);<br />
rv.Tables[0].Rows.Add(new object[] {<br />
item.Subject,<br />
item.Location,<br />
item.Start,<br />
item.End,<br />
item.AllDayEvent,<br />
item.Duration,<br />
item.Organizer,<br />
item.Importance,<br />
item.Sensitivity,<br />
item.Body<br />
});<br />
this.ItemProcessed();<br />
}<br />
Debug.WriteLine(rv.Tables[0].Rows.Count + " Appointments exported.");<br />
}<br />
catch (System.Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
return rv;<br />
}<br />
<br />
public DataSet getContactDataSet()<br />
{<br />
Outlook.ContactItem item;<br />
DataSet rv = new DataSet();<br />
rv.DataSetName = "Contacts";<br />
rv.Tables.Add("Contact");<br />
rv.Tables[0].Columns.Add("FirstName");<br />
rv.Tables[0].Columns.Add("LastName");<br />
rv.Tables[0].Columns.Add("CompanyName");<br />
rv.Tables[0].Columns.Add("Email");<br />
rv.Tables[0].Columns.Add("HomePhone");<br />
rv.Tables[0].Columns.Add("WorkPhone");<br />
<br />
try<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);<br />
Debug.WriteLine(objFolder.Items.Count + " Contacts found.");<br />
for (int i=0; i < objFolder.Items.Count; i++) <br />
{<br />
item = (Outlook.ContactItem)objFolder.Items.Item(i);<br />
rv.Tables[0].Rows.Add(new object[] {<br />
item.FirstName,<br />
item.LastName,<br />
item.CompanyName,<br />
item.Email1Address,<br />
item.HomeTelephoneNumber,<br />
item.BusinessTelephoneNumber<br />
});<br />
this.ItemProcessed();<br />
}<br />
Debug.WriteLine(rv.Tables[0].Rows.Count + " Contacts exported.");<br />
}<br />
catch (System.Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
return rv;<br />
}<br />
<br />
public DataSet getInboxDataSet()<br />
{<br />
Outlook.MailItem item;<br />
DataSet rv = new DataSet();<br />
rv.DataSetName = "InboxEmails";<br />
rv.Tables.Add("Email");<br />
rv.Tables[0].Columns.Add("Name");<br />
rv.Tables[0].Columns.Add("To");<br />
rv.Tables[0].Columns.Add("Cc");<br />
rv.Tables[0].Columns.Add("Subject");<br />
rv.Tables[0].Columns.Add("Received");<br />
rv.Tables[0].Columns.Add("Message");<br />
<br />
<br />
try<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); <br />
objItems = objFolder.Items.Restrict("[MessageClass]='IPM.Note'");<br />
<br />
<br />
Debug.WriteLine(objItems.Count + " E-Mails found.");<br />
for (int i=1; i <= objItems.Count; i++) <br />
{<br />
item = (Outlook.MailItem)objItems.Item(i); <br />
{<br />
rv.Tables[0].Rows.Add(new object[] {<br />
item.SenderName,<br />
item.To,<br />
item.CC,<br />
item.Subject,<br />
item.ReceivedTime,<br />
item.Body<br />
});<br />
<br />
}<br />
this.ItemProcessed();<br />
}<br />
Debug.WriteLine(rv.Tables[0].Rows.Count + " E-Mails exported.");<br />
<br />
}<br />
catch (System.Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
return rv;<br />
}<br />
<br />
public DataSet getNoteDataSet()<br />
{<br />
Outlook.NoteItem item;<br />
DataSet rv = new DataSet();<br />
rv.DataSetName = "Notes";<br />
rv.Tables.Add("Note");<br />
rv.Tables[0].Columns.Add("Subject");<br />
rv.Tables[0].Columns.Add("Categories");<br />
rv.Tables[0].Columns.Add("CreationTime");<br />
rv.Tables[0].Columns.Add("LastModificationTime");<br />
rv.Tables[0].Columns.Add("Contents");<br />
<br />
try<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderNotes);<br />
Debug.WriteLine(objFolder.Items.Count + " Notes found.");<br />
for (int i=0; i < objFolder.Items.Count; i++) <br />
{<br />
item = (Outlook.NoteItem)objFolder.Items.Item(i);<br />
rv.Tables[0].Rows.Add(new object[] {<br />
item.Subject,<br />
item.Categories,<br />
item.CreationTime,<br />
item.LastModificationTime,<br />
item.Body<br />
});<br />
this.ItemProcessed();<br />
}<br />
Debug.WriteLine(rv.Tables[0].Rows.Count + " Notes exported.");<br />
}<br />
catch (System.Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
return rv;<br />
}<br />
<br />
public DataSet getTaskDataSet()<br />
{<br />
Outlook.TaskItem item;<br />
DataSet rv = new DataSet();<br />
rv.DataSetName = "Tasks";<br />
rv.Tables.Add("Task");<br />
rv.Tables[0].Columns.Add("Subject");<br />
rv.Tables[0].Columns.Add("StartDate");<br />
rv.Tables[0].Columns.Add("DueDate");<br />
rv.Tables[0].Columns.Add("Status");<br />
rv.Tables[0].Columns.Add("Contents");<br />
<br />
try<br />
{<br />
objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);<br />
Debug.WriteLine(objFolder.Items.Count + " Tasks found.");<br />
for (int i=0; i < objFolder.Items.Count; i++) <br />
{<br />
item = (Outlook.TaskItem)objFolder.Items.Item(i);<br />
rv.Tables[0].Rows.Add(new object[] {<br />
item.Subject,<br />
item.StartDate,<br />
item.DueDate,<br />
item.Status,<br />
item.Body<br />
});<br />
this.ItemProcessed();<br />
}<br />
Debug.WriteLine(rv.Tables[0].Rows.Count + " Tasks exported.");<br />
}<br />
catch (System.Exception e)<br />
{<br />
Console.WriteLine(e);<br />
}<br />
return rv;<br />
}<br />
}<br />
}<br />
<br />
|
|
|
|
|
wfe wrote:
Q1a: How do I search 'installed applications list' on a local PC from C#/.NET ?
The easiest way is using WMI. See the System.Management namespace in the clas library documentation of the .NET Framework SDK. Make a request on the remote machine (or even your local machine, which you can refer to as "." or just don't specify a machine at all) for the Win32_Product CIMv2 class.
See System.Management Lets You Take Advantage of WMI APIs within Managed Code[^] in MSDN Magazine online for more information, sample code, and a link to an add-in for VS.NET 2002 (and if you search, for 2003) that lets you browse the WMI repository on any machine and to create managed wrapper classes just by dragging and dropping classes into your project.
wfe wrote:
Q1b: How do I search the registry ?
The .NET FCL (Framework Class Library) does not let you access the registry of a remote machine. You either need to P/Invoke the registry APIs yourself or find a project that already does this for you. I'd recommend the method above, though, since it's far more robust and less error-prone (messing with the registry is dangerous, especially if you don't know what you're doing).
As far as the connector goes, both Outlook and Outlook Express are MAPI clients so you can use MAPI wrappers, like Simple MAPI.NET[^]. There are many restrictions in the MAPI implementations these days, however, because of script kiddies (responsible for all those malicious worms you hear about). The basic stuff should work fine, however, like sending a mail message. Accessing the address book using MAPI (which is scriptable, where Extended MAPI is not) will either fail or prompt the user that some program is trying to access their address book and prompt them to allow it and for how long, or to simply deny the request. There is plenty of documentation about this subject online. Just google for MAPI or something and you'll find a lot of information. Another good place is to search on MSDN[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your reply.
I know your intentions are good but I am not getting much help from this.
All I need is a SPECIFIC and CONCRETE code description, not references to millions of linked articles that I do not yet understand as I am not yet familiar with the underlying development environment under Windows.
Heath Stewart wrote:
Make a request on the remote machine (or even your local machine, which you can refer to as "." or just don't specify a machine at all) for the Win32_Product CIMv2 class.
Q1: How do I 'make a request' ? I have read your references in the SDK but cannot find anything relating to Win32_Product class. All I get is a list of classes, delegates and enumerations ?
Please, can you provide specific help ?
Heath Stewart wrote:
As far as the connector goes, both Outlook and Outlook Express are MAPI clients so you can use MAPI wrappers
Q2: Good, then why does it pick the emails from Outlook and not from Outlook Express and how do I change it ?
Thanks (and sorry for the panic !)
William
|
|
|
|
|