|
Thanks for your help. I finally figured out how to do this and it might help others who might need or want to know how to do this. Below is the bit of code I used to get the Point location of the insertion point.
rchEdit.GetPositionFromCharIndex(rchEdit.SelectionStart)
This did it. GetPositionFromCharIndex(...) when passed the selection start index, returns a Point instance at the insertion point's index (or at the beginning of a selection).
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
I have need to authenticate users using windows authentiateion. I am using following code to do that. But problem with this is after three unsuccessful attempts, it locks user out from other applications using Directory Service, the same way when we try to login to windows machine and three consecutive wrong passwords locks the users out.
Does anybody know how can I use Directory Service to make non-blocking call upon wrong password
DirectoryEntry entry = new DirectoryEntry("LDAP://RootDSE");<br />
String str = entry.Properties["defaultNamingContext"][0].ToString();<br />
MessageBox.Show(str);<br />
DirectoryEntry domain = new DirectoryEntry("LDAP://" + str, txtLogin.Text, txtPassword.Text);<br />
<br />
<br />
try<br />
{<br />
Object native = domain.NativeObject;<br />
MessageBox.Show(txtLogin.Text + " Authenticated. Hurray!!!");<br />
}<br />
catch(Exception )<br />
{<br />
MessageBox.Show(txtLogin.Text + " INVALID user :-((");<br />
}
Thanks you very much,
Ruchi
|
|
|
|
|
Hi Ruchi
The administrator (hopefully you) of the AD can change the setting that "locks out accounts on X failed login attempts". This would solve your problem.
Also, you could try the Win32 Logon user function, although I would presume that it will cause the exact same error, as your error is not an error but an AD feature. The following code will log in a user account. The token returned can be used to make ur code impersonate the specific user account, calling System.Security.Principal.WindowsIdentity.Impersonate((System.IntPtr)token), if you should ever need that. If the account is invalid, you should recieve a 0 in the token returned from the function, as well as an error in the error variable.
[DllImport("advapi32.dll", SetLastError=true) ]
public static extern bool LogonUser(string lpszUsername, string
lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider,
outint phToken);
[DllImport("C:\\Windows\\System32\\Kernel32.dll")]
public static extern int GetLastError();
public static int LogonWindowsUser(string username, string domain, string password)
{
int token;
bool isLoggedin = LogonUser(username, domain, password, 3, 0, out token);
int error = GetLastError();
return token;
}
/Zalkina
|
|
|
|
|
Hi,
Can any1 tell me, how could i open an excel application in a "windows form"? I know how to open an Excel application but i am tryin 2 open it in "Windows form". I am trying to do it in C#,
Help would be greatly appreciated.
Bob
|
|
|
|
|
I do not believe that you can do that. Mainly because excel is an independant process and does not expose an interface or control for use in a windows form. Using a data grid is about the best way to do this.
This signature left intentionally blank
|
|
|
|
|
Hi,
Can any1 tell me, how could i open an excel application in a "windows form"? I know how to open an Excel application but i am tryin 2 open it in "Windows form".
Help would be greatly appreciated.
Bob
|
|
|
|
|
Hi folks,
Im building an application that at some point accepts a user name and password. I want to check that a) this user is indeed a valid user and b) that the user account has the right to "Log On as a service" to the local machine on which the application runs.
The first part is easily accomplished by using the advapi32.dll - LogonUser function in an example I found elsewhere.
However, how to check if the user account has the "Log on as a service" right (SeServiceLogonRight)? Ive found out that I (probably) need to once again DllImport a function from advapi32.dll, and that this time it is the "LsaEnumerateAccountRights" function, which I should use to retrieve a list of rights, associated with the user.
However, I cant quite get this to work! Could anyone provide me with a working c# example for performing the above check, I would be very grateful!
/Zalkina
|
|
|
|
|
You might try something like this but I haven't tested it.
[DllImport("advapi32.dll", SetLastError=true)]
static extern uint LsaEnumerateAccountRights(
IntPtr PolicyHandle,
IntPtr AccountSid,
out string[] UserRights,
out ulong CountOfRights);
Another thought is that this would be a lot easier if done in a MC++ wrapper because the native types would be available to you, plus much easier to use in .NET afterwards. Yet another thought would be to place the user/users in a group, assign that group appropriate permissions and then you can easily check if that user is in the group:
AppDomain domain = Thread.GetDomain();
domain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
IPrincipal p = Thread.CurrentPrincipal;
if(p.IsInRole("YourServiceRole"))
{
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi Nick
Thanx for your reply!
Im used to checking user group memberships, as you specified in your second exaxple. However, this is a app for company, which would never ever allow me to change the structure of their Active Directory, adding my own groups etc.
I must find out how to check for the specific "SeServiceLogonRight" right on a user account.
The reason I need to check for this right is that I during install of a service prompt for a username/password, under which the service is configured and started. However, before allowing the user to bypass the install form prompting for the credentials, I want to make sure that the entered user credentials will actually work for the service "run as" credentials.
Besides this, its quite interesting on a general level for me (and others) to know how to actually check a user account for specific WinNT rights. The System.Secirity namespace obviously lacks functionality for this, and one is left to the mercy of the Win32 API.
Documentation clearly shows that for right checks one should use the LsaEnumerateAccountRights function. However, when I import it as you specified in your first code snippet, Im unable to determine what parameters I need to supply for it to work.
So, Im still not able to get my check down on code. But maby you, being more experienced than me (no MC++ exp what-so-ever) would be able to?
I challenge you to, given a user name and the corresponding password, to write a function, checking for the "SeServiceLogonRight" (or any other right for that matter) Or simply to sucessfully call the LsaEnumerateAccountRights function on a user account, as I should be able to evaluate the resulting string array of rights myself ...
/Zalkina
|
|
|
|
|
Zalkina wrote:
I challenge you to, given a user name and the corresponding password, to write a function, checking for the "SeServiceLogonRight" (or any other right for that matter) Or simply to sucessfully call the LsaEnumerateAccountRights function on a user account, as I should be able to evaluate the resulting string array of rights myself ...
Wouldn't the challenge be more beneficial if you were to challenge yourself, thus learning how the process works? Overall it shouldn't be too difficult. If you have questions along the way, feel free to post them here so we can help.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I'm not sure if this helps or not...but basically you find you have a 'valid user' by the pressence of the userID. ie. if they never logged into the network, they'd never have a credential. This is a snippet from my security manager
private static readonly string domainName = System.Environment.UserDomainName;
private static readonly string userName = System.Environment.UserName;
private static readonly string fullUserName = domainName + @"\" + userName;
private static readonly WindowsPrincipal currentPrincipal =
new WindowsPrincipal(WindowsIdentity.GetCurrent());
public bool CheckUserGroup(string groupName)
{
return currentPrincipal.IsInRole(domainName + @"\" + groupName);
}
This signature left intentionally blank
|
|
|
|
|
hello there
I have a program whit some textbox
when the cursor is inside the textbox
how can i change languish ?
the cursor direction ?
i dont want to press Alt+Shift
i want it automatically
thanks !!!
|
|
|
|
|
kings_1 wrote:
how can i change languish ?
Huh?
kings_1 wrote:
the cursor direction ?
You can change your cursor several different ways. If you want to use a predefined cursor you can do the following:
this.Cursor = Cursors.WaitCursor;
this.Cursor = Cursors.Default;
If you have a cursor file (i.e., *.cur), you can loaded that as such:
this.Cursor = new Cursor(GetType(), "MyCursor.Cur");
- Nick Parker My Blog | My Articles
|
|
|
|
|
not the mouse Cursor
i want to change the keybord cursor
&
i dont have any of that things
this.Cursor = Cursors.WaitCursor;
this.Cursor = Cursors.Default;
thanks anyway !!!
|
|
|
|
|
Your still not making yourself clear. If you could explain clearly what you are trying to do others would be able to help you.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Not sure exactly what you are asking.....but if it is language-based changes in various text boxes (ie: textBox1 = English while textBox2 = Chinese) then first you need to enable localization and second in textBox2 you would set RightToLeft = true;
This signature left intentionally blank
|
|
|
|
|
i am pretty new to programming but have quite some knowledge of it this thins i am doing it for my own learning.here is what i want to do.I got an access database which has all memebers information with their name addess and expiry Date. Now i want to make a program using either c,C++ or java that will go through the access database and look at expiry date and if its expired it will read the email address part and send an email to the address specifies with a predefined message that says Your membership has expired and stuff like that. Any links to something that can help me will be appreciated. Thanks a lot
|
|
|
|
|
funaki wrote:
using either c,C++ or java
If you have a specific C# question, please feel free to ask it, however you are asking about overall design, in particular, another language. There are many articles not only on this site but also on the Internet in general that cover how to programmatically access a database and send email. Good luck.
- Nick Parker My Blog | My Articles
|
|
|
|
|
i am really sorry about that.Yes i am asking about C/C++.any help would be appreciated. Also if you hook me up with some of the articles you said. THanks a lot.
|
|
|
|
|
Another problem I have encountered is using a timer in .NETCF. The start and stop methods are not available. I just want a timer to count 40 seconds, and at the end of 40 seconds, throw an error message. I feel like im crippled trying to use the CF....
|
|
|
|
|
|
I'm trying to make a progress bar using the COmpact Framework for a Pocket PC. However, in the Compact Framework, there is no step property, nor is there a performstep method. Does anyone have an example of a working progress bar using the Compact Framework?.
I just want it to float indepenently at the front of my application. Also, a messagebox of some sort with moving ... 's would be acceptable as well, but I don't know how to code it either.
|
|
|
|
|
|
j1e1g1 wrote:
I'm trying to make a progress bar using the COmpact Framework for a Pocket PC. However, in the Compact Framework, there is no step property, nor is there a performstep method.
The ProgressBar Class[^] is supported under the .NET Compact Framework, however if you are trying to write your own ProgressBar control, you will have to write your own methods and properties. The PerformStep method under the .NET Framework only calls the Increment method passing the step value. The Increment method increments the value to itself, checks to see if it is within bounds and updates the UI.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hy everyone!
I do want to split strings to get some special infos.
Lets say I want to split the following:
Winter, John\r\nBusinessnum. 1: +12 (23) 4567890\r\nMobile 1: +23 (456) 22562
Well I could get along with it using
string ltemp=""; // info is draged in here (e.g. the string above)
// remove characters a-z,A-Z and ,
ltemp=Regex.Replace(ltemp, @"[a-zA-z,]","");
//replace the + sign and replace it with 00
ltemp=Regex.Replace(ltemp, @"[+]",lreplaceplus);
// removes the /,(,),-,\r and \n signs or escapechars respectivly
ltemp=Regex.Replace(ltemp, @"[/()\-\r\n ]","");
After this my string looks like this:
. 1: 0012234567890:002345622562
Well now I do want to extract the 0012234567890 and 002345622562 in two seperate fields. Well I will take care of this later. At the moment I was trying to find out, what a regular expression has to look
1) removing the string in the beginning (meaning ". 1:") or any similar strings which might appear somewhere inbetween (meaning strings like this instead of just the ":"
2) extracting the first number (0012234567890) and the starting over at the next one, meaning I do want to do a loop similar to
while string not empty
parse it with regular expressions
store an extracted number in an array to collect them all
This means my aim is to get the following (explained with the string above)
stringarray[1]=0012234567890
stringarray[2]=002345622562
stringarray[3]= ......
If you might have wondered, yes the string above is a contact item of Outlook being an array of strings or a string respectively. And my aim is to pares this string, eliminating everything that's no (telephone)number and copying them in an array collecting the numbers in this string for furter use.
But well, as I described above I was able to eliminate almost everything except the numbers, but I was not able to remove the "separationstring" (the ". 1:" in the example above) and split the numbers apart.
Does anyone of you know any solution what my regular expression has to look like to solve my problem (because I guess an regular expression is easier, because otherwise my array would contain an empty field, if I split it bevor parsing it, e.g. if it was only text and no number).
Another solution which I was thinking about was to split the preparsed string, place it into the array and do the final parsing in accessing the arrayfields instead of the local string variable.
But at the moment I do not know which might be easier or if my solution, which I did so far, is already complicating the whole thing.
Thanks!
Stephan.
|
|
|
|
|