The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<HTML>
<HEAD>
<TITLE>Win32API::Process - Perl extension for handling the processes
                    using the plain Win32 API</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:prantl@host.sk">
</HEAD>

<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<FONT SIZE=+1><STRONG><P CLASS=block>&nbsp;Win32API::Process - Perl extension for handling the processes                    using the plain Win32 API</P></STRONG></FONT>
</TD></TR>
</TABLE>

<A NAME="__index__"></A>
<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#name">NAME</A></LI>
	<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
	<LI><A HREF="#description">DESCRIPTION</A></LI>
	<UL>

		<LI><A HREF="#exports">EXPORTS</A></LI>
		<LI><A HREF="#constants">CONSTANTS</A></LI>
		<LI><A HREF="#functions">FUNCTIONS</A></LI>
	</UL>

	<LI><A HREF="#author">AUTHOR</A></LI>
	<LI><A HREF="#copyright">COPYRIGHT</A></LI>
	<LI><A HREF="#see also">SEE ALSO</A></LI>
</UL>
<!-- INDEX END -->

<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Win32API::Process - Perl extension for handling the processes
                    using the plain Win32 API</P>
<P>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
  use Win32API::Process ':All';</PRE>
<PRE>
  # --- opens handle to the current process
  my $handle = OpenProcess(PROCESS_ALL_ACCESS, 0, $$);
  CloseProcess($handle);</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>The <EM>Process</EM> functions exposes the part of Win32 API handling the processes.</P>
<P>It contains just process opening an terminating functionality
in the meanwhile. It is supposed to be used
with the <CODE>Win32API::ProcessStatus</CODE> module or modules that need handles
to processes on their interfaces.</P>
<P>(Note that much of the following documentation refers to the behavior
of the underlying Win32 API calls which may vary in its current and future
versions without any changes to this module. Therefore you should check the
Win32 API documentation in MSDN directly when needed.)</P>
<P>
<H2><A NAME="exports">EXPORTS</A></H2>
<P>Nothing is exported by default. The following tags can be used to have sets
of symbols exported:</P>
<DL>
<DT><STRONG><A NAME="item_%3AFunc">:Func</A></STRONG><BR>
<DD>
The basic function names: CloseProcess GetLastProcessError OpenProcess
SetLastProcessError TerminateProcess.
<P></P></DL>
<P>
<H2><A NAME="constants">CONSTANTS</A></H2>
<P>The constants described here and exported by this module are used only
in its structures and functions. See the module <CODE>Win32API::Const</CODE>
for the common Win32 constants.</P>
<P><CODE>PROCESS_</CODE> constants are used as flags in the process handlingopening functions.</P>
<DL>
<DT><STRONG><A NAME="item_PROCESS_ALL_ACCESS">PROCESS_ALL_ACCESS</A></STRONG><BR>
<DD>
Specifies all possible access flags for the process object.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_CREATE_PROCESS">PROCESS_CREATE_PROCESS</A></STRONG><BR>
<DD>
Used internally.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_CREATE_THREAD">PROCESS_CREATE_THREAD</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>CreateRemoteThread</CODE> function
to create a thread in the process.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_DUP_HANDLE">PROCESS_DUP_HANDLE</A></STRONG><BR>
<DD>
Enables using the process handle as either the source or target process
in the <CODE>DuplicateHandle</CODE> function to duplicate a handle.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_QUERY_INFORMATION">PROCESS_QUERY_INFORMATION</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>GetExitCodeProcess</CODE>
and <CODE>GetPriorityClass</CODE> functions to read information from the process object.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_SET_QUOTA">PROCESS_SET_QUOTA</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>AssignProcessToJobObject</CODE>
and <CODE>SetProcessWorkingSetSize</CODE> functions to set memory limits.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_SET_INFORMATION">PROCESS_SET_INFORMATION</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>SetPriorityClass</CODE> function
to set the priority class of the process.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_TERMINATE">PROCESS_TERMINATE</A></STRONG><BR>
<DD>
Enables using the process handle in the <A HREF="#item_TerminateProcess"><CODE>TerminateProcess</CODE></A> function
to terminate the process.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_VM_OPERATION">PROCESS_VM_OPERATION</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>VirtualProtectEx</CODE>
and <CODE>WriteProcessMemory</CODE> functions to modify the virtual memory
of the process.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_VM_READ">PROCESS_VM_READ</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>ReadProcessMemory</CODE> function
to read from the virtual memory of the process.
<P></P>
<DT><STRONG><A NAME="item_PROCESS_VM_WRITE">PROCESS_VM_WRITE</A></STRONG><BR>
<DD>
Enables using the process handle in the <CODE>WriteProcessMemory</CODE> function
to write to the virtual memory of the process.
<P></P>
<DT><STRONG><A NAME="item_STANDARD_RIGHTS_REQUIRED">STANDARD_RIGHTS_REQUIRED</A></STRONG><BR>
<DD>
Combines <CODE>DELETE</CODE>, <CODE>READ_CONTROL</CODE>, <CODE>WRITE_DAC</CODE>, and <CODE>WRITE_OWNER</CODE> access.
<P></P>
<DT><STRONG><A NAME="item_SYNCHRONIZE">SYNCHRONIZE</A></STRONG><BR>
<DD>
Windows NT/2000/XP: Enables using the process handle in any of the wait
functions to wait for the process to terminate.
<P></P></DL>
<P>
<H2><A NAME="functions">FUNCTIONS</A></H2>
<P><EM>Process</EM> functions return either a boolean status of the function's
result or a handle to a process. To retrieve an extended information
about the error if it occurs use the <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A> function.
If no error happens <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A> still returns the last occured
error code (successful calls do not modify the last stored error code).
You can set or reset the internally stored error code explicitely
by the function <A HREF="#item_SetLastProcessError"><CODE>SetLastProcessError</CODE></A>.</P>
<P>To use something more convenient than numbers for comparisons of return
values and error codes see the module <CODE>Win32API::Const</CODE>.</P>
<DL>
<DT><STRONG><A NAME="item_CloseProcess"><CODE>CloseProcess($hProcess)</CODE></A></STRONG><BR>
<DD>
Closes an open process handle.
<DL>
<DT><STRONG><A NAME="item_hProcess_%5BIN%5D">hProcess [IN]</A></STRONG><BR>
<DD>
Handle to the open process.
<P></P>
<DT><STRONG><A NAME="item_%5BRETVAL%5D">[RETVAL]</A></STRONG><BR>
<DD>
If the function succeeds, the return value is nonzero. If the function fails,
the return value is zero. To get extended error information, call
<A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A>.
<P>Windows NT/2000/XP: Closing an invalid handle raises an exception
when the application is running under a debugger. This includes closing
a handle twice, for example.</P>
<P></P></DL>
<P>It invalidates the specified process handle, decrements the object's
handle count, and performs object retention checks. After the last handle
to an object is closed, the object is removed from the system.</P>
<DT><STRONG><A NAME="item_GetLastProcessError"><CODE>GetLastProcessError()</CODE></A></STRONG><BR>
<DD>
Retrieves the last-error code value of the <EM>Process</EM> functions.
The last-error code is stored if a function fails and remembered until
another function calls when it is overwritten by the new error code.
Successful calls do not modify this internally stored last-error code value.
<DL>
<DT><STRONG>[RETVAL]</STRONG><BR>
<DD>
The return value is the last-error code value. Functions set this value
by calling the <A HREF="#item_SetLastProcessError"><CODE>SetLastProcessError</CODE></A> function if they fail.
<P></P></DL>
<P>To obtain an error string for system error codes, use
the <CODE>FormatMessage</CODE> function. For a complete list of error codes, see
the System Error Codes section in MSDN. There are pre-defined constants
for the Win32 system error codes in the module &lt;Win32API::Const&gt;.</P>
<P>You should call the <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A> function immediately when
a function's return value indicates that such a call will return useful data.
A subsequent call to another <EM>Process</EM> function could fail as well
and <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A> would return its error code instead
of the former one.</P>
<P>Function failure is typically indicated by a return value such as zero,
undefined, or –1 (0xffffffff).</P>
<P>Error codes returned are 32-bit values with the most significant bit set
to 1 (bit 31 is the most significant bit). Zero code is <CODE>ERROR_SUCCESS</CODE>.</P>
<DT><STRONG><A NAME="item_OpenProcess">OpenProcess($dwDesiredAccess, $bInheritHandle, $dwProcessId)</A></STRONG><BR>
<DD>
Takes a snapshot of the processes and the heaps, modules, and threads used
by the processes.
<DL>
<DT><STRONG><A NAME="item_dwDesiredAccess_%5BIN%5D">dwDesiredAccess [IN]</A></STRONG><BR>
<DD>
Specifies the access to the process object. For operating systems that support
security checking, this access is checked against any security descriptor
for the target process. The values available are listed in the description of
<CODE>PROCESS__</CODE> constants.
<P></P>
<DT><STRONG><A NAME="item_bInheritHandle_%5BIN%5D">bInheritHandle [IN]</A></STRONG><BR>
<DD>
Specifies whether the returned handle can be inherited by a new process
created by the current process. If TRUE, the handle is inheritable.
<P></P>
<DT><STRONG><A NAME="item_dwProcessId_%5BIN%5D">dwProcessId [IN]</A></STRONG><BR>
<DD>
Specifies the identifier of the process to open.
<P></P>
<DT><STRONG>[RETVAL]</STRONG><BR>
<DD>
If the function succeeds, the return value is an open handle to the specified
process. If the function fails, the return value is NULL. To get extended
error information, call <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A>.
<P></P></DL>
<P>The handle returned by the <A HREF="#item_OpenProcess"><CODE>OpenProcess</CODE></A> function can be used in any function
that requires a handle to a process, such as the wait functions, provided
the appropriate access rights were requested.</P>
<P>When you are finished with the handle, be sure to close it using
the <A HREF="#item_CloseProcess"><CODE>CloseProcess</CODE></A> or <CODE>CloseHandle</CODE> function.</P>
<DT><STRONG><A NAME="item_SetLastProcessError"><CODE>SetLastProcessError($dwError)</CODE></A></STRONG><BR>
<DD>
Sets the last-error code value of the <EM>Process</EM> functions.
<DL>
<DT><STRONG><A NAME="item_dwError_%5BIN%5D">dwError [IN]</A></STRONG><BR>
<DD>
Specifies the last-error code.
<P></P></DL>
<P>Error codes returned are 32-bit values with the most significant bit set
to 1 (bit 31 is the most significant bit). Zero code is <CODE>ERROR_SUCCESS</CODE>.</P>
<P>Applications can retrieve the value saved by this function by using
the <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A> function. The use of <A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A>
is optional; an application can call it to find out the specific reason
for a function failure.</P>
<DT><STRONG><A NAME="item_TerminateProcess">TerminateProcess($hProcess, $uExitCode)</A></STRONG><BR>
<DD>
Terminates the specified process and all of its threads.
<DL>
<DT><STRONG>hProcess [IN]</STRONG><BR>
<DD>
Handle to the process to terminate.
<P></P>
<DT><STRONG><A NAME="item_uExitCode_%5BIN%5D">uExitCode [IN]</A></STRONG><BR>
<DD>
Specifies the exit code for the process and for all threads terminated
as a result of this call. Use the <CODE>GetExitCodeProcess</CODE> function to retrieve
the process's exit value. Use the <CODE>GetExitCodeThread</CODE> function to retrieve
a thread's exit value.
<P></P>
<DT><STRONG>[RETVAL]</STRONG><BR>
<DD>
If the function succeeds, the return value is nonzero. If the function fails,
the return value is zero. To get extended error information, call
<A HREF="#item_GetLastProcessError"><CODE>GetLastProcessError</CODE></A>.
<P></P></DL>
<P>The <A HREF="#item_TerminateProcess"><CODE>TerminateProcess</CODE></A> function is used to unconditionally cause a process
to exit. Use it only in extreme circumstances. The state of global data
maintained by dynamic-link libraries (DLLs) may be compromised if
<A HREF="#item_TerminateProcess"><CODE>TerminateProcess</CODE></A> is used rather than <CODE>ExitProcess</CODE>.</P>
<P><A HREF="#item_TerminateProcess"><CODE>TerminateProcess</CODE></A> causes all threads within a process to terminate,
and causes a process to exit, but DLLs attached to the process are
not notified that the process is terminating.</P>
<P>Terminating a process causes the following:</P>
<P>All of the object handles opened by the process are closed.</P>
<P>All of the threads in the process terminate their execution.</P>
<P>The state of the process object becomes signaled, satisfying any threads
that had been waiting for the process to terminate.</P>
<P>The states of all threads of the process become signaled, satisfying
any threads that had been waiting for the threads to terminate.</P>
<P>The termination status of the process changes from <CODE>STILL_ACTIVE</CODE> to the exit
value of the process.</P>
<P>Terminating a process does not cause child processes to be terminated.</P>
<P>Terminating a process does not necessarily remove the process object
from the system. A process object is deleted when the last handle
to the process is closed.</P>
<P>Terminating a process does not generate notifications for <CODE>WH_CBT</CODE> hook
procedures.</P>
</DL>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Ferdinand Prantl &lt;<EM><A HREF="mailto:prantl@host.sk">prantl@host.sk</A></EM>&gt;</P>
<P>See <EM><A HREF="http://prantl.host.sk/perl/modules/Win32API/Process">http://prantl.host.sk/perl/modules/Win32API/Process</A></EM>
for the most recent version.</P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright (c) 2002, Ferdinand Prantl. All rights reserved.</P>
<P>Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear
in supporting documentation. Author makes no representations
about the suitability of this software for any purpose.  It is
provided ``as is'' without express or implied warranty.</P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="ProcessStatus.html">the Win32API::ProcessStatus manpage</A>, <A HREF="../Win32/Process.html">the Win32::Process manpage</A>, <A HREF="../Win32/Job.html">the Win32::Job manpage</A>
and <A HREF="Const.html">the Win32API::Const manpage</A>.</P>

<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<FONT SIZE=+1><STRONG><P CLASS=block>&nbsp;Win32API::Process - Perl extension for handling the processes                    using the plain Win32 API</P></STRONG></FONT>
</TD></TR>
</TABLE>
</BODY>

</HTML>