com.jniwrapper.win32.process
Class Process

java.lang.Object
  extended by com.jniwrapper.Parameter
      extended by com.jniwrapper.Pointer.Void
          extended by com.jniwrapper.win32.Handle
              extended by com.jniwrapper.win32.process.Process
All Implemented Interfaces:
com.jniwrapper.AutoDeleteParameter, com.jniwrapper.IntegerParameter, com.jniwrapper.PointerParameter
Direct Known Subclasses:
CurrentProcess

public class Process
extends Handle
implements com.jniwrapper.AutoDeleteParameter

Process class represents a process and provides various information about it.

NOTE: Every created or opened process should be closed using the close() method.


Nested Class Summary
static class Process.PriorityClass
          PrioriryClass class is enumeration of priorities for a system process.
protected static class Process.ProcessResource
          This class responds for destroying a native resource when the instance is collected by garbage-collector.
 
Field Summary
 
Fields inherited from class com.jniwrapper.win32.Handle
INFINITE_TIMEOUT, INVALID_HANDLE_VALUE, STATUS_ABANDONED_WAIT_0, STATUS_TIMEOUT, STATUS_WAIT_0
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
Process(java.lang.String commandLine)
          Creates a new process and its primary thread.
Process(java.lang.String applicationName, java.lang.String commandLine, ProcessOptions options, java.lang.String currentDirectory, StartupInfo startupInfo)
          Creates a new process and its primary thread.
Process(java.lang.String applicationName, java.lang.String commandLine, SecurityAttributes processAttributes, SecurityAttributes threadAttributes, boolean inheritHandles, ProcessOptions options, ProcessVariables environment, java.lang.String currentDirectory, StartupInfo startupInfo)
          Creates a new process and its primary thread.
Process(java.lang.String userName, java.lang.String domain, java.lang.String password, boolean logonWithProfile, java.lang.String applicationName, java.lang.String commandLine, ProcessOptions options, ProcessVariables environment, java.lang.String currentDirectory, StartupInfo startupInfo)
          Creates a new process and its primary thread.
 
Method Summary
 void close()
          Closes the opened process safely and all associated handles.
 long getAffinityMask()
          Returns the process affinity mask for the specified process and the system affinity mask for the system.
static java.util.List getApplicationWindows()
           
 long getExitCode()
          Returns the termination status of the process.
 long getGdiObjectsCount()
          Returns the count of GDI objects.
 long getHandleCount()
          Returns the number of open handles that belong to the specified process.
 IOCounters getIOCounters()
          Returns accounting information for all I/O operations performed by the specified process.
 java.lang.String getModuleFileName(Handle module)
          Gets the file name of the specified module attached to the process.
 java.util.List getModules()
          Gets the list of handles of the modules attached to the process.
 boolean getPriorityBoost()
          Returns the priority boost control state of the process.
 Process.PriorityClass getPriorityClass()
          Returns the priority class for the specified process.
static java.util.List getProcesses()
          Gets a list of all running processes.
static java.util.List getProcesses(ProcessSecurityOptions processSecurityOptions)
          Gets a list of all running processes with the specified ProcessSecurityOptions.
 java.lang.String getProcessFileName()
          Returns the name of the executable file for this process.
 long getProcessID()
          Returns the identifier of the process.
static long getProcessID(Process process)
          Returns the identifier of the process.
 java.lang.String getProcessImageFileName()
          Returns the name of the executable file for this process.
 ProcessMemoryCounters getProcessMemoryCounters()
          Returns information about the memory usage of this process.
 void getProcessTimes(FileTime creationTime, FileTime exitTime, FileTime kernelTime, FileTime userTime)
          Returns timing information about the specified process.
 long getSystemAffinityMask()
          Returns the system affinity mask for the system.
 Handle getThread()
          Returns a Handle to the primary thread of the process.
 long getThreadID()
          Returns the identifier of the thread.
static long getThreadID(Handle thread)
          Returns the identifier of the thread.
static long getThreadProcessID(Handle thread)
          Returns the process identifier of the process associated with a specified thread.
 long getUSERObjectsCount()
          Returns the count of USER objects.
 long getVersion()
          Returns the major and minor version numbers of the system on which the specified process expects to run.
static long getVersion(long processID)
          Returns the major and minor version numbers of the system on which the specified process expects to run.
 void getWorkingSetSize(com.jniwrapper.UInt32 minimumWorkingSetSize, com.jniwrapper.UInt32 maximumWorkingSetSize)
          Returns the minimum and maximum working set sizes of the specified process.
 boolean isAutoDelete()
           
static Process openProcess(ProcessSecurityOptions desiredAccess, boolean inheritHandle, long processID)
          Opens an existing process object.
protected  void registerResource()
          Registers process handle to be garbage-collected automatically.
 void setAffinityMask(long affinityMask)
          Sets a processor affinity mask for the threads of the process.
 void setAutoDelete(boolean autoDelete)
           
 void setPriorityBoost(boolean enable)
          Enables or disables the ability of the system to temporarily boost the priority of the threads of the process.
 void setPriorityClass(Process.PriorityClass prioriryClass)
          Sets the priority class for the specified process.
 void setWorkingSetSize(long minSize, long maxSize)
          Sets the minimum and maximum working set sizes for the specified process.
 void terminate(long exitCode)
          Terminates the process and all of its threads.
 long waitFor()
          Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
 long waitFor(long timeout)
          Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
 
Methods inherited from class com.jniwrapper.win32.Handle
clone, closeHandle, equals, waitFor, waitFor
 
Methods inherited from class com.jniwrapper.Pointer.Void
asFunction, asFunction, asTypedPointer, castTo, castTo, getDebugInfo, getLength, getValue, hashCode, isNull, read, setValue, toString, write
 
Methods inherited from class com.jniwrapper.Parameter
, a, a, acceptIOPerformer, asReturnValue, b, dataBufferAssigned, getAlignedLength, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, indent, pop, push, read, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Process

public Process(java.lang.String commandLine)
Creates a new process and its primary thread.

Parameters:
commandLine - Can be null; specifies the command line to execute.

Process

public Process(java.lang.String applicationName,
               java.lang.String commandLine,
               ProcessOptions options,
               java.lang.String currentDirectory,
               StartupInfo startupInfo)
Creates a new process and its primary thread.

Parameters:
applicationName - Can be null; specifies the module to execute in which case the executable name must be in the white space-delimited string pointed to by CommandLine.
commandLine - Can be null; specifies the command line to execute.
options - Options that control the priority class and the creation of the process.
currentDirectory - Can be null; specifies the current drive and directory for the new process.

Process

public Process(java.lang.String applicationName,
               java.lang.String commandLine,
               SecurityAttributes processAttributes,
               SecurityAttributes threadAttributes,
               boolean inheritHandles,
               ProcessOptions options,
               ProcessVariables environment,
               java.lang.String currentDirectory,
               StartupInfo startupInfo)
Creates a new process and its primary thread.

Parameters:
applicationName - Can be null; specifies the module to execute in which case the executable name must be in the white space-delimited string pointed to by CommandLine.
commandLine - Can be null; specifies the command line to execute.
processAttributes - Can be null; determines whether the returned handle can be inherited by child processes.
threadAttributes - Can be null; determines whether the returned handle can be inherited by child processes.
inheritHandles - If this parameter is true, each inheritable handle in the calling process is inherited by the new process. If the parameter is false, the handles are not inherited.
options - Options that control the priority class and the creation of the process.
environment - Can be null; environment block for the new process; If this parameter is null, the new process uses the environment of the calling process.
currentDirectory - Can be null; specifies the current drive and directory for the new process.
startupInfo - Specifies the window station, desktop, standard handles, and appearance of the main window for the new process.

Process

public Process(java.lang.String userName,
               java.lang.String domain,
               java.lang.String password,
               boolean logonWithProfile,
               java.lang.String applicationName,
               java.lang.String commandLine,
               ProcessOptions options,
               ProcessVariables environment,
               java.lang.String currentDirectory,
               StartupInfo startupInfo)
Creates a new process and its primary thread. The new process then runs the specified executable file in the security context of the specified credentials (user, domain, and password).

Parameters:
userName - Specifies the name of the user.
domain - Can be null; specifies the name of the domain or server whose account database contains the lpUsername account.
password - Specifies the clear-text password for the lpUsername account.
logonWithProfile - Specifies the way to logon. True specifies logon with profile, false - logon with net credentials only.
applicationName - Can be null; specifies the module to execute in which case the executable name must be in the white space-delimited string pointed to by CommandLine.
commandLine - Can be null; specifies the command line to execute.
options - Options that control the priority class and the creation of the process.
environment - Can be null; environment block for the new process; If this parameter is null, the new process uses the environment of the calling process.
currentDirectory - Can be null; specifies the current drive and directory for the new process.
startupInfo - Specifies the window station, desktop, standard handles, and appearance of the main window for the new process.
Method Detail

openProcess

public static Process openProcess(ProcessSecurityOptions desiredAccess,
                                  boolean inheritHandle,
                                  long processID)
Opens an existing process object.

Parameters:
desiredAccess - Access rights to the process object.
inheritHandle - If this parameter is true, the handle is inheritable. Otherwise the handle cannot be inherited.
processID - ID of the process to open.
Returns:
the opened process.

registerResource

protected void registerResource()
Registers process handle to be garbage-collected automatically.


getProcessID

public static long getProcessID(Process process)
Returns the identifier of the process.

IMPORTANT NOTE: This function is available in WinXP (since SP1) and WinServer 2003 only.

Returns:
process ID.

getExitCode

public long getExitCode()
Returns the termination status of the process.

Returns:
termination status of the process.

setAutoDelete

public void setAutoDelete(boolean autoDelete)
Specified by:
setAutoDelete in interface com.jniwrapper.AutoDeleteParameter

isAutoDelete

public boolean isAutoDelete()
Specified by:
isAutoDelete in interface com.jniwrapper.AutoDeleteParameter

getPriorityClass

public Process.PriorityClass getPriorityClass()
Returns the priority class for the specified process.

Returns:
the priority class for the specified process.

setPriorityClass

public void setPriorityClass(Process.PriorityClass prioriryClass)
Sets the priority class for the specified process.

Parameters:
prioriryClass - Priority class for the process

getGdiObjectsCount

public long getGdiObjectsCount()
Returns the count of GDI objects.

Returns:
the count of GDI objects.

getUSERObjectsCount

public long getUSERObjectsCount()
Returns the count of USER objects.

Returns:
the count of GDI objects.

getHandleCount

public long getHandleCount()
Returns the number of open handles that belong to the specified process.

Returns:
number of open handles that belong to the specified process.

getIOCounters

public IOCounters getIOCounters()
Returns accounting information for all I/O operations performed by the specified process.

Returns:
accounting information.

getProcessTimes

public void getProcessTimes(FileTime creationTime,
                            FileTime exitTime,
                            FileTime kernelTime,
                            FileTime userTime)
Returns timing information about the specified process.

Parameters:
creationTime - [out] the creation time of the process.
exitTime - [out] the exit time of the process.
kernelTime - [out] the amount of time that the process has executed in kernel mode.
userTime - [out] the amount of time that the process has executed in user mode.

setPriorityBoost

public void setPriorityBoost(boolean enable)
Enables or disables the ability of the system to temporarily boost the priority of the threads of the process.

Parameters:
enable - If this parameter is true, dynamic boosting is enabled. If the parameter is false, dynamic boosting is disabled.

getPriorityBoost

public boolean getPriorityBoost()
Returns the priority boost control state of the process.

Returns:
true indicates that dynamic boosting is enabled; false otherwise.

terminate

public void terminate(long exitCode)
Terminates the process and all of its threads.

Parameters:
exitCode - the process exit code.

getVersion

public long getVersion()
Returns the major and minor version numbers of the system on which the specified process expects to run. The high word of the return value contains the major version number. The low word of the return value contains the minor version number.

Returns:
version of the system on which the process expects to run.

getVersion

public static long getVersion(long processID)
Returns the major and minor version numbers of the system on which the specified process expects to run. The high word of the return value contains the major version number. The low word of the return value contains the minor version number.

Parameters:
processID - identifier of the process.
Returns:
version of the system on which the process expects to run.

getWorkingSetSize

public void getWorkingSetSize(com.jniwrapper.UInt32 minimumWorkingSetSize,
                              com.jniwrapper.UInt32 maximumWorkingSetSize)
Returns the minimum and maximum working set sizes of the specified process.

The "Working Set" of a process is a set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. The minimum and maximum working set sizes affect the virtual memory paging behavior of a process.

Parameters:
minimumWorkingSetSize - [out] Minimum working set size for the process, in bytes.
maximumWorkingSetSize - [out] Maximum working set size for the process, in bytes.

setWorkingSetSize

public void setWorkingSetSize(long minSize,
                              long maxSize)
Sets the minimum and maximum working set sizes for the specified process.

The "Working Set" of a process is a set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. The minimum and maximum working set sizes affect the virtual memory paging behavior of a process.

Parameters:
minSize - Minimum working set size for the process, in bytes.
maxSize - Maximum working set size for the process, in bytes.

getAffinityMask

public long getAffinityMask()
Returns the process affinity mask for the specified process and the system affinity mask for the system.

A process affinity mask is a bit vector in which each bit represents the processors that a process is allowed to run on.

Returns:
the process affinity mask.

getSystemAffinityMask

public long getSystemAffinityMask()
Returns the system affinity mask for the system.

A system affinity mask is a bit vector in which each bit represents the processors that are configured into a system.

Returns:
the the system affinity mask.

setAffinityMask

public void setAffinityMask(long affinityMask)
Sets a processor affinity mask for the threads of the process.

Parameters:
affinityMask - Affinity mask for the threads of the process.

getThreadProcessID

public static long getThreadProcessID(Handle thread)
Returns the process identifier of the process associated with a specified thread.

Parameters:
thread - Handle of the thread.
Returns:
a process ID.

getThreadID

public static long getThreadID(Handle thread)
Returns the identifier of the thread.

Parameters:
thread - Handle to the thread.
Returns:
a thread ID.

waitFor

public long waitFor(long timeout)
Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Parameters:
timeout - Time-out interval, in milliseconds.
Returns:
exit code of the process.

waitFor

public long waitFor()
Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Returns:
process Exit Code

getThreadID

public long getThreadID()
Returns the identifier of the thread.

Returns:
thread identifier

getProcessID

public long getProcessID()
Returns the identifier of the process.

Returns:
process ID.

getThread

public Handle getThread()
Returns a Handle to the primary thread of the process.

Returns:
a Handle to the primary thread of the process.

close

public void close()
Closes the opened process safely and all associated handles.


getProcessMemoryCounters

public ProcessMemoryCounters getProcessMemoryCounters()
Returns information about the memory usage of this process.

Returns:
information about the memory usage of this process.

getProcessImageFileName

public java.lang.String getProcessImageFileName()
Returns the name of the executable file for this process. NOTE: Requires Windows XP operation system or higher. For lower versions of operation systems use getProcessFileName() method.

Returns:
the name of the executable file for this process.

getProcessFileName

public java.lang.String getProcessFileName()
Returns the name of the executable file for this process. NOTE: Use this method for versions of operation system lower than Windows XP otherwise it is recommended to use getProcessImageFileName() method.

Returns:
the name of the executable file for this process.

getProcesses

public static java.util.List getProcesses()
Gets a list of all running processes. Each process is represented by Process class instance.

Returns:
an array of Process class instances.

getProcesses

public static java.util.List getProcesses(ProcessSecurityOptions processSecurityOptions)
Gets a list of all running processes with the specified ProcessSecurityOptions. Each process is represented by Process class instance.

Parameters:
processSecurityOptions - security options for all the processes of the list.
Returns:
an array of Process class instances.

getModules

public java.util.List getModules()
Gets the list of handles of the modules attached to the process.

Returns:
the list of handles of the modules.

getModuleFileName

public java.lang.String getModuleFileName(Handle module)
Gets the file name of the specified module attached to the process.

Parameters:
module - is the handle of the module attached to the process.
Returns:
the file name of the module.

getApplicationWindows

public static java.util.List getApplicationWindows()