Search in sources :

Example 1 with STARTUPINFO

use of com.sun.jna.platform.win32.WinBase.STARTUPINFO 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)

Example 2 with STARTUPINFO

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

the class Kernel32Test method testCreateProcess.

public void testCreateProcess() {
    WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO();
    WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReference();
    boolean status = Kernel32.INSTANCE.CreateProcess(null, "cmd.exe /c echo hi", null, null, true, new WinDef.DWORD(0), Pointer.NULL, System.getProperty("java.io.tmpdir"), startupInfo, processInformation);
    assertTrue(status);
    assertTrue(processInformation.dwProcessId.longValue() > 0);
}
Also used : DWORD(com.sun.jna.platform.win32.WinDef.DWORD) IntByReference(com.sun.jna.ptr.IntByReference) ShortByReference(com.sun.jna.ptr.ShortByReference) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference)

Aggregations

PROCESS_INFORMATION (com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION)1 STARTUPINFO (com.sun.jna.platform.win32.WinBase.STARTUPINFO)1 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)1 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)1 IntByReference (com.sun.jna.ptr.IntByReference)1 ShortByReference (com.sun.jna.ptr.ShortByReference)1 File (java.io.File)1