473,732 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

LogonUser API

Dan
All,

I am attempting to use the LogonUser API in an
application. However, everytime I attempt to validate an
account using this I get an error. The code is 1421 which
has a description of "Control ID not found". I can't find
any information on what could be causing this error. Any
help would be appreciated. Thanks!
Nov 15 '05 #1
3 20502
Error 1421 is not related to LogonUser, could you please post your code, or a small repro?

Willy.
"Dan" <dd*****@fnisol utions.com> wrote in message news:04******** *************** *****@phx.gbl.. .
All,

I am attempting to use the LogonUser API in an
application. However, everytime I attempt to validate an
account using this I get an error. The code is 1421 which
has a description of "Control ID not found". I can't find
any information on what could be causing this error. Any
help would be appreciated. Thanks!

Nov 15 '05 #2
Dan
Thanks for the response. Here is the code

public class LogonAPI
{
// Declare the logon types as constants
const long LOGON32_LOGON_I NTERACTIVE = 2;
const long LOGON32_LOGON_N ETWORK = 3;

// Declare the logon providers as constants
const long LOGON32_PROVIDE R_DEFAULT = 0;
const long LOGON32_PROVIDE R_WINNT50 = 3;
const long LOGON32_PROVIDE R_WINNT40 = 2;
const long LOGON32_PROVIDE R_WINNT35 = 1;

//Import Needed DLL
[DllImport("adva pi32.dll",Entry Point
= "LogonUser" )]
private static extern bool LogonUser(

string lpszUsername,

string lpszDomain,

string lpszPassword,

int dwLogonType,

int dwLogonProvider ,

ref IntPtr phToken);
public LogonAPI()
{
}

public bool ValidateLogin( string
Username, string Password, string Domain )
{
IntPtr token = new IntPtr(0);
token = IntPtr.Zero;

// Call the API
if (LogonUser(
Username,
Domain,
Password,
(int)
LOGON32_LOGON_N ETWORK,
(int)
LOGON32_PROVIDE R_DEFAULT,
ref token))
{
return true;
}
else
{
return false;
}
}

}

When I attempt to call the ValidateLogin function I always
get a return value of false. I then use the
System.Runtime. InteropServices .Marshal.GetLas tWin32Error()
function to get the error and it returns 1421.

Dan
-----Original Message-----
Error 1421 is not related to LogonUser, could you please post your code, or a small repro?
Willy.
"Dan" <dd*****@fnisol utions.com> wrote in message

news:04******** *************** *****@phx.gbl.. .
All,

I am attempting to use the LogonUser API in an
application. However, everytime I attempt to validate an
account using this I get an error. The code is 1421 which has a description of "Control ID not found". I can't find any information on what could be causing this error. Any
help would be appreciated. Thanks!

.

Nov 15 '05 #3
- Why const long for logontypes and provider constants, change them to int so no cast is needed when calling LogonUser.
- Add SetLastError=tr ue to your DllImport declaration.

Willy.

"Dan" <dd*****@fnisol utions.com> wrote in message news:0a******** *************** *****@phx.gbl.. .
Thanks for the response. Here is the code

public class LogonAPI
{
// Declare the logon types as constants
const long LOGON32_LOGON_I NTERACTIVE = 2;
const long LOGON32_LOGON_N ETWORK = 3;

// Declare the logon providers as constants
const long LOGON32_PROVIDE R_DEFAULT = 0;
const long LOGON32_PROVIDE R_WINNT50 = 3;
const long LOGON32_PROVIDE R_WINNT40 = 2;
const long LOGON32_PROVIDE R_WINNT35 = 1;

//Import Needed DLL
[DllImport("adva pi32.dll",Entry Point
= "LogonUser" )]
private static extern bool LogonUser(

string lpszUsername,

string lpszDomain,

string lpszPassword,

int dwLogonType,

int dwLogonProvider ,

ref IntPtr phToken);
public LogonAPI()
{
}

public bool ValidateLogin( string
Username, string Password, string Domain )
{
IntPtr token = new IntPtr(0);
token = IntPtr.Zero;

// Call the API
if (LogonUser(
Username,
Domain,
Password,
(int)
LOGON32_LOGON_N ETWORK,
(int)
LOGON32_PROVIDE R_DEFAULT,
ref token))
{
return true;
}
else
{
return false;
}
}

}

When I attempt to call the ValidateLogin function I always
get a return value of false. I then use the
System.Runtime. InteropServices .Marshal.GetLas tWin32Error()
function to get the error and it returns 1421.

Dan
-----Original Message-----
Error 1421 is not related to LogonUser, could you please

post your code, or a small repro?

Willy.
"Dan" <dd*****@fnisol utions.com> wrote in message

news:04******** *************** *****@phx.gbl.. .
All,

I am attempting to use the LogonUser API in an
application. However, everytime I attempt to validate an
account using this I get an error. The code is 1421 which has a description of "Control ID not found". I can't find any information on what could be causing this error. Any
help would be appreciated. Thanks!

.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2315
by: Nimi | last post by:
When I run my application , the LogonUser method fails the exception is "LogonUser failed with error code :1314". I know the error is because of some privileges . I am using Windows 2000 sp4. I have not enabled the SE_TCB_NAME previlege. Do we need to enable this ? I enabled privileges using this: ManagementObject mo = new ManagementObject(new ManagementPath( ));
1
2896
by: Rich | last post by:
I am running IIS6 on a Win2k3 server. I have an ASP.Net app (C#) that a user logs into and then I use LogonUser to validate them and log them onto the server. I have Windows Authentication ONLY checked on the site in IIS. My problem is that eventhough I am using LogonUser to log on to the server as the user, I am still getting the Windows Authentication Challenge (login window).
3
814
by: Zeno Lee | last post by:
I'm trying to authenticate a user against a windows network. I want it to work across any kind of windows network from NT 4.0 up to Windows 2003 ADS. So far I've been using DirectoryEntry and DirectorySearcher and doing a search on Active Directory. With the addition of a customer on an NT 4.0 network, I've had to add DllImport using LogonUser() from advapi32.dll in addition to the directory search. To simplify my code, Is it...
2
5127
by: BLiTZWiNG | last post by:
Having a few strage behaviours with this function, mainly in that when I try to logon to another computer with a different name/pass to the current user of the local machine, it tries to impersonate me, not the credentials I gave it. LogonUser succeeds only when using LOGON32_LOGON_NEW_CREDENTIALS (9). Any other LogonType causes error 126: Specified module could not be found - whatever that means... The initial...
7
2382
by: Jason | last post by:
I have an ASP.NET application with forms authentication. However, the login details correspond to a Windows account (I cannot use Windows authentication). If I obtain a token with LogonUser, can I store it in a session variable and perform an impersonation on each page load? How long is that token valid? If I do an impersonation on each page load but never an Undo, will it cause problems? I think that once the response finishes, the...
3
8210
by: plmanikandan | last post by:
Hi, i need to use logonuser api in c# for windows 2000. Logonuser api is working fine in windowsXp,Windows2003 server.in windows 2000 for running logonuser api we need SE_TCB_NAME Privilege(act as part of operating system).i need to set the SE_TCB_NAME Privilege programatically with out restarting the
9
17611
by: schaf | last post by:
Hi NG ! I used the examples on the internet to create a Impersonate class which allows me to log on as another user. After logged on as the new user I could access files on a remote computer, which is in the same domain. So I tried the same on a computer which is not in the same domain. I could not access these files. I saw this in the MSDN: "You cannot use LogonUser to log on to a remote computer" So now I'm a little confused. It is...
1
1931
by: Sajid | last post by:
I use LogonUser for user authentication against AD. When I run this in XP is works fine. But it gives me a Win32 Error 1314 (ERROR_PRIVILEGE_NOT_HELD) in Win 2000. Any idea why and how do I solve it?
6
1864
by: nild | last post by:
Hello i have a strange problem. I'm using LogonUser to impersonate the user under which my program must run. On Win XP or Server 2003 it works. But on 2000 it doesn't. So i found out, to set SE_TCB_NAME privileg - it doesn't work. Then i read somewhere that this only work for local users and not domain users and so the changes in the domain policy don't work. But the strangest thing i've found out after some tests: LogonUser works...
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.