0

I've got a C# Screensaver on the Authentication Interface (Windows 7 and 8.x). The screensaver is a WebBrowser who show RSS, images... and two buttons. I'm using pGina credential provider. A specific parameter allows the right to create a local profil for a non local user.

The second button close the screensaver and let the user wrote his username and password (non local account, that's why I use pGina) into the credential provider of pGina. Its works perfectly.

For the first button, "Guest", what I want is to launch a session when I click on the button without enter username and password into the credential provider but into my screensaver code before closing.

The event is correctly triggered. My problem is to launch the session for the Guest user. I read the source code of pGina to log a local user (L.257) and translate it into C# code but didn't work...

bool retVal;
IntPtr hproc = GetCurrentProcess(), htok = IntPtr.Zero, ptUser = new IntPtr();
TokPriv1Luid tp;
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(null, SE_TIME_ZONE_NAMETEXT, ref tp.Luid)){
     if (AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero)){
         if(!LogonUser("USER", "USERDOMAIN", "PASSWORD", 
            LogonType.LOGON32_LOGON_INTERACTIVE, 
            LogonProvider.LOGON32_PROVIDER_DEFAULT, 
            out ptUser))
                MessageBox.Show(Marshal.GetLastWin32Error().ToString());
     }
}

LogonUser return true but nothing happens... I also tried differents values of LogonType.

I've read this link, it's exactly what I'm doing in VB.

I checked Marshal.GetLastWin32Error after LogonUser, it returns 0 "The operation completed successfully."

EDIT : I found this many times about using LogonUser to logon to Windows : "No you can not, using LogonUser() is only one step of many in the logon process"

I'm still searching about informations about the others steps, but someone has an idea or another solution for me ?

TheMightyX2Y
  • 1,473
  • 1
  • 16
  • 24
  • Wow, awkward, I misread what I blatantly copy-pasted here. When `LogonUser` returns `true`, it *has* succeeded. You could try checking out the Windows Event Log. – ErikHeemskerk Jul 17 '14 at 12:36
  • What exactly do you expect to "happen"? The user has logged on and you got a handle to its token. This has nothing to do with GINA. See [Create an interactive logon session](http://stackoverflow.com/questions/2134391/create-an-interactive-logon-session) – Remus Rusanu Jul 17 '14 at 12:42
  • I want to launch a specific session. I've already see this link, but I'm on Windows 7 and 8.x and this function doesn't exist into the DLL... – TheMightyX2Y Jul 17 '14 at 12:54
  • FWIW, you need to check the return value of `LogonUser` before calling `GetLastWin32Error`. Do read the documentation carefully to see why I say this. – David Heffernan Jul 21 '14 at 08:15
  • It's what I'm doing. I mentionned it but I updated my code. The return of LogonUser is true, so my code don't Show GetLastWin32Error but I checked it in an else condition and its value is 0. But maybe I misunderstanding the documentation too... – TheMightyX2Y Jul 22 '14 at 12:04
  • I updated my question because LogonUser(...) is just a step to logon into Windows session – TheMightyX2Y Jul 23 '14 at 06:45

0 Answers0