Im trying to write a program for work; because of our security policies it will need to run as a domain administrator. I plan to take the token created here and use it to start a new process that will run the main program that needs the administrator privlidges. The username and password I type are valid and are domain admins, I always get ERROR_PRIVELDGE_NOT_HELD no matter with dwLogonType I use... keeping in mind that LOGON32_LOGON_NETWORK doesnt require the SE_TCB_NAME privledge (so I shouldnt get that error!). What am I doing wrong? Ive never had to enumerate a token, adjust a token, or pretty much work with tokens in the past and Im getting quite frustrated with the whole process. MSDN has resulted in nothing but more frustration. FYI, this program will run on NT4 and 2000 computers. Somebody who knows this stuff please help!
Code (snippets):
static extern Int32 LogonUser (string lpszUsername, string lpszDomain, string lpszPassword, Int32 dwLogonType, Int32 dwLogonProvider, Int32 phToken);
[DllImport("kernel32.dll")]
static extern Int32 CloseHandle (Int32 hObject);
const Int32 LOGON32_LOGON_INTERACTIVE = 2;
const Int32 LOGON32_LOGON_BATCH = 4;
const Int32 LOGON32_PROVIDER_DEFAULT = 0;
const Int32 LOGON32_LOGON_NETWORK = 3;
const Int32 LOGON32_LOGON_SERVICE = 5;
........................
in Main():
ret = LogonUser("username", "domainname", "apwd", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, pUser);
if(ret==0)
Console.WriteLine("LogonUser Failed! with error {0}", GetLastError());
ret = CloseHandle(pUser);
Code (snippets):
static extern Int32 LogonUser (string lpszUsername, string lpszDomain, string lpszPassword, Int32 dwLogonType, Int32 dwLogonProvider, Int32 phToken);
[DllImport("kernel32.dll")]
static extern Int32 CloseHandle (Int32 hObject);
const Int32 LOGON32_LOGON_INTERACTIVE = 2;
const Int32 LOGON32_LOGON_BATCH = 4;
const Int32 LOGON32_PROVIDER_DEFAULT = 0;
const Int32 LOGON32_LOGON_NETWORK = 3;
const Int32 LOGON32_LOGON_SERVICE = 5;
........................
in Main():
ret = LogonUser("username", "domainname", "apwd", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, pUser);
if(ret==0)
Console.WriteLine("LogonUser Failed! with error {0}", GetLastError());
ret = CloseHandle(pUser);