@Test public void getPIDWhenProcessIsNull() { int pid = WinProcess.getPID( null ); Assert.assertEquals( -1, pid ); }
public static int getPID( Process proc ) { int pid = -1; try { if ( proc.getClass().getName().equals( "java.lang.Win32Process" ) || proc.getClass().getName() .equals( "java.lang.ProcessImpl" ) ) { Field f = proc.getClass().getDeclaredField( "handle" ); f.setAccessible( true ); long handl = f.getLong( proc ); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer( Pointer.createConstant( handl ) ); pid = kernel.GetProcessId( handle ); } } catch ( Exception e ) { e.printStackTrace(); } return pid; }
WinProcess { public static int getPID( Process proc ) { int pid = -1; try { if ( proc.getClass().getName().equals( "java.lang.Win32Process" ) || proc.getClass().getName() .equals( "java.lang.ProcessImpl" ) ) { Field f = proc.getClass().getDeclaredField( "handle" ); f.setAccessible( true ); long handl = f.getLong( proc ); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer( Pointer.createConstant( handl ) ); pid = kernel.GetProcessId( handle ); } } catch ( Exception e ) { e.printStackTrace(); } return pid; } }
WinProcess { public static int getPID( Process proc ) { int pid = -1; try { if ( proc.getClass().getName().equals( "java.lang.Win32Process" ) || proc.getClass().getName() .equals( "java.lang.ProcessImpl" ) ) { Field f = proc.getClass().getDeclaredField( "handle" ); f.setAccessible( true ); long handl = f.getLong( proc ); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer( Pointer.createConstant( handl ) ); pid = kernel.GetProcessId( handle ); } } catch ( Exception e ) { e.printStackTrace(); } return pid; } WinProcess( int pid ); }
WinProcess { public static int getPID( Process proc ) { int pid = -1; try { if ( proc.getClass().getName().equals( "java.lang.Win32Process" ) || proc.getClass().getName() .equals( "java.lang.ProcessImpl" ) ) { Field f = proc.getClass().getDeclaredField( "handle" ); f.setAccessible( true ); long handl = f.getLong( proc ); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer( Pointer.createConstant( handl ) ); pid = kernel.GetProcessId( handle ); } } catch ( Exception e ) { e.printStackTrace(); } return pid; } WinProcess( int pid ); void terminate(); String killChildProcesses(); static int getPID( Process proc ); int getWinProcessPID(); }
WinProcess { public static int getPID( Process proc ) { int pid = -1; try { if ( proc.getClass().getName().equals( "java.lang.Win32Process" ) || proc.getClass().getName() .equals( "java.lang.ProcessImpl" ) ) { Field f = proc.getClass().getDeclaredField( "handle" ); f.setAccessible( true ); long handl = f.getLong( proc ); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer( Pointer.createConstant( handl ) ); pid = kernel.GetProcessId( handle ); } } catch ( Exception e ) { e.printStackTrace(); } return pid; } WinProcess( int pid ); void terminate(); String killChildProcesses(); static int getPID( Process proc ); int getWinProcessPID();  }