Click here to Skip to main content
15,897,187 members
Home / Discussions / C#
   

C#

 
GeneralRe: TroubleShotting working with Data Set Pin
Om@r3-Oct-03 3:20
Om@r3-Oct-03 3:20 
GeneralRe: TroubleShotting working with Data Set Pin
STW3-Oct-03 4:17
STW3-Oct-03 4:17 
GeneralRe: TroubleShotting working with Data Set Pin
Om@r3-Oct-03 4:23
Om@r3-Oct-03 4:23 
GeneralRe: TroubleShotting working with Data Set Pin
STW3-Oct-03 7:17
STW3-Oct-03 7:17 
GeneralRe: TroubleShotting working with Data Set Pin
Om@r4-Oct-03 13:52
Om@r4-Oct-03 13:52 
GeneralRe: TroubleShotting working with Data Set Pin
STW4-Oct-03 23:07
STW4-Oct-03 23:07 
GeneralLogonUser and Interop problem Pin
devvvy2-Oct-03 4:49
devvvy2-Oct-03 4:49 
GeneralRe: LogonUser and Interop problem Pin
devvvy2-Oct-03 5:39
devvvy2-Oct-03 5:39 
I invoked LoadUserProfile before call LogonUser - it failed to solve the problem. GetLastError still returns error 203 after LogonUser.

Here's how I did it:
//MSDN Sample: http://msdn.microsoft.com/vstudio/using/understand/interop/default.aspx?pull=/library/en-us/dnnetsec/html/SecNetHT13.asp
const int SecurityImpersonation = 2;
IntPtr dupeTokenHandle = DupeToken(
WindowsIdentity.GetCurrent().Token,
SecurityImpersonation); //CAUTION: Current user is different from the user I wish to impersonate.
if(IntPtr.Zero == dupeTokenHandle)
{
Console.WriteLine("Unable to duplicate token.");
}

PROFILEINFO profile = new PROFILEINFO();
profile.dwSize = 32;
profile.lpUserName = "AA02\\CustomAppUser";
bool retval = LoadUserProfile(dupeTokenHandle, ref profile);
if(retval==false)
{
Console.WriteLine("LoadUserProfile failed. Error code: " + Marshal.GetLastWin32Error());
return;
}

bool loggedOn = LogonUser(
"CustomAppUser", //Username
"AA02", //Computer name
"customappuser", //Passwd (Remember, this is case-sensitive.)
3, //Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
0, //Logon provider = LOGON32_PROVIDER_DEFAULT.
out token //token for the specified user.
);
int ret = GetLastError();
if(ret!=0)
{
Console.WriteLine("Impersonation error. Error code: " + ret.ToString());
return;
}

It seems to me that you don't need to call LoadUserProfile prior to calling LogonUser - am I right? But what else can be the problem?

THanks!

norm
GeneralRe: LogonUser and Interop problem Pin
devvvy2-Oct-03 6:29
devvvy2-Oct-03 6:29 
GeneralDecoding SNMP Packets Pin
MrEyes2-Oct-03 3:56
MrEyes2-Oct-03 3:56 
GeneralThreadPool and COM Interop Pin
DuaneP2-Oct-03 2:17
DuaneP2-Oct-03 2:17 
GeneralRe: ThreadPool and COM Interop Pin
DuaneP2-Oct-03 11:01
DuaneP2-Oct-03 11:01 
GeneralIsInRole Pin
devvvy2-Oct-03 1:35
devvvy2-Oct-03 1:35 
GeneralRe: IsInRole Pin
Julian Bucknall [MSFT]2-Oct-03 6:05
Julian Bucknall [MSFT]2-Oct-03 6:05 
GeneralRe: IsInRole Pin
devvvy2-Oct-03 6:25
devvvy2-Oct-03 6:25 
GeneralDatabase confusion question Pin
rama_ii2-Oct-03 1:33
rama_ii2-Oct-03 1:33 
GeneralRe: Database confusion question Pin
Daniel Turini2-Oct-03 1:49
Daniel Turini2-Oct-03 1:49 
GeneralSectionGroup and CMAB Pin
lionhurt20002-Oct-03 0:46
lionhurt20002-Oct-03 0:46 
GeneralRIP , Play and convert audio and video files Pin
Velichko Sarev2-Oct-03 0:36
Velichko Sarev2-Oct-03 0:36 
GeneralString question Pin
Mazdak1-Oct-03 23:23
Mazdak1-Oct-03 23:23 
GeneralRe: String question Pin
Corinna John1-Oct-03 23:38
Corinna John1-Oct-03 23:38 
GeneralRe: String question Pin
Mazdak2-Oct-03 1:14
Mazdak2-Oct-03 1:14 
GeneralRe: String question Pin
Rickard Andersson201-Oct-03 23:51
Rickard Andersson201-Oct-03 23:51 
GeneralRe: String question Pin
Mazdak2-Oct-03 1:16
Mazdak2-Oct-03 1:16 
GeneralRe: String question Pin
jparsons2-Oct-03 5:26
jparsons2-Oct-03 5:26 

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.