Search in sources :

Example 1 with PROCESS_INFORMATION

use of com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION in project jna by java-native-access.

the class Advapi32Test method testCreateProcessWithLogonW.

public void testCreateProcessWithLogonW() {
    String winDir = Kernel32Util.getEnvironmentVariable("WINDIR");
    assertNotNull("No WINDIR value returned", winDir);
    assertTrue("Specified WINDIR does not exist: " + winDir, new File(winDir).exists());
    STARTUPINFO si = new STARTUPINFO();
    si.lpDesktop = null;
    PROCESS_INFORMATION results = new PROCESS_INFORMATION();
    // i have the same combination on my luggage
    boolean result = Advapi32.INSTANCE.CreateProcessWithLogonW("A" + System.currentTimeMillis(), "localhost", "12345", Advapi32.LOGON_WITH_PROFILE, new File(winDir, "notepad.exe").getAbsolutePath(), "", 0, null, "", si, results);
    // we tried to run notepad as a bogus user, so it should fail.
    assertFalse("CreateProcessWithLogonW should have returned false because the username was bogus.", result);
    // should fail with "the user name or password is incorrect" (error 1326)
    assertEquals("GetLastError() should have returned ERROR_LOGON_FAILURE because the username was bogus.", W32Errors.ERROR_LOGON_FAILURE, Native.getLastError());
}
Also used : PROCESS_INFORMATION(com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION) STARTUPINFO(com.sun.jna.platform.win32.WinBase.STARTUPINFO) File(java.io.File)

Aggregations

PROCESS_INFORMATION (com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION)1 STARTUPINFO (com.sun.jna.platform.win32.WinBase.STARTUPINFO)1 File (java.io.File)1