Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
4.8 KiB

  1. package Win32::Process;
  2. require Exporter;
  3. require DynaLoader;
  4. @ISA = qw(Exporter DynaLoader);
  5. $VERSION = '0.09';
  6. # Items to export into callers namespace by default. Note: do not export
  7. # names by default without a very good reason. Use EXPORT_OK instead.
  8. # Do not simply export all your public functions/methods/constants.
  9. @EXPORT = qw(
  10. CREATE_DEFAULT_ERROR_MODE
  11. CREATE_NEW_CONSOLE
  12. CREATE_NEW_PROCESS_GROUP
  13. CREATE_NO_WINDOW
  14. CREATE_SEPARATE_WOW_VDM
  15. CREATE_SUSPENDED
  16. CREATE_UNICODE_ENVIRONMENT
  17. DEBUG_ONLY_THIS_PROCESS
  18. DEBUG_PROCESS
  19. DETACHED_PROCESS
  20. HIGH_PRIORITY_CLASS
  21. IDLE_PRIORITY_CLASS
  22. INFINITE
  23. NORMAL_PRIORITY_CLASS
  24. REALTIME_PRIORITY_CLASS
  25. THREAD_PRIORITY_ABOVE_NORMAL
  26. THREAD_PRIORITY_BELOW_NORMAL
  27. THREAD_PRIORITY_ERROR_RETURN
  28. THREAD_PRIORITY_HIGHEST
  29. THREAD_PRIORITY_IDLE
  30. THREAD_PRIORITY_LOWEST
  31. THREAD_PRIORITY_NORMAL
  32. THREAD_PRIORITY_TIME_CRITICAL
  33. );
  34. sub AUTOLOAD {
  35. # This AUTOLOAD is used to 'autoload' constants from the constant()
  36. # XS function.
  37. my($constname);
  38. ($constname = $AUTOLOAD) =~ s/.*:://;
  39. my $val = constant($constname);
  40. if ($! != 0) {
  41. my ($pack,$file,$line) = caller;
  42. die "Your vendor has not defined Win32::Process macro $constname, used at $file line $line.";
  43. }
  44. eval "sub $AUTOLOAD { $val }";
  45. goto &$AUTOLOAD;
  46. } # end AUTOLOAD
  47. bootstrap Win32::Process;
  48. 1;
  49. __END__
  50. =head1 NAME
  51. Win32::Process - Create and manipulate processes.
  52. =head1 SYNOPSIS
  53. use Win32::Process;
  54. use Win32;
  55. sub ErrorReport{
  56. print Win32::FormatMessage( Win32::GetLastError() );
  57. }
  58. Win32::Process::Create($ProcessObj,
  59. "D:\\winnt35\\system32\\notepad.exe",
  60. "notepad temp.txt",
  61. 0,
  62. NORMAL_PRIORITY_CLASS,
  63. ".")|| die ErrorReport();
  64. $ProcessObj->Suspend();
  65. $ProcessObj->Resume();
  66. $ProcessObj->Wait(INFINITE);
  67. =head1 DESCRIPTION
  68. This module provides access to the process control functions in the
  69. Win32 API.
  70. =head1 METHODS
  71. =over 8
  72. =item Win32::Process::Create($obj,$appname,$cmdline,$iflags,$cflags,$curdir)
  73. Creates a new process.
  74. Args:
  75. $obj container for process object
  76. $appname full path name of executable module
  77. $cmdline command line args
  78. $iflags flag: inherit calling processes handles or not
  79. $cflags flags for creation (see exported vars below)
  80. $curdir working dir of new process
  81. Returns non-zero on success, 0 on failure.
  82. =item Win32::Process::Open($obj,$pid,$iflags)
  83. Creates a handle Perl can use to an existing process as identified by $pid.
  84. The $iflags is the inherit flag that is passed to OpenProcess. Currently
  85. Win32::Process objects created using Win32::Process::Open cannot Suspend
  86. or Resume the process. All other calls should work.
  87. Win32::Process::Open returns non-zero on success, 0 on failure.
  88. =item Win32::Process::KillProcess($pid, $exitcode)
  89. Terminates any process identified by $pid. $exitcode will be set to
  90. the exit code of the process.
  91. =item $ProcessObj->Suspend()
  92. Suspend the process associated with the $ProcessObj.
  93. =item $ProcessObj->Resume()
  94. Resume a suspended process.
  95. =item $ProcessObj->Kill( $exitcode )
  96. Kill the associated process, have it terminate with exit code $ExitCode.
  97. =item $ProcessObj->GetPriorityClass($class)
  98. Get the priority class of the process.
  99. =item $ProcessObj->SetPriorityClass( $class )
  100. Set the priority class of the process (see exported values below for
  101. options).
  102. =item $ProcessObj->GetProcessAffinitymask( $processAffinityMask, $systemAffinitymask)
  103. Get the process affinity mask. This is a bitvector in which each bit
  104. represents the processors that a process is allowed to run on.
  105. =item $ProcessObj->SetProcessAffinitymask( $processAffinityMask )
  106. Set the process affinity mask. Only available on Windows NT.
  107. =item $ProcessObj->GetExitCode( $exitcode )
  108. Retrieve the exitcode of the process.
  109. =item $ProcessObj->Wait($timeout)
  110. Wait for the process to die. $timeout should be specified in milliseconds.
  111. To wait forever, specify the constant C<INFINITE>.
  112. =item $ProcessObj->GetProcessID()
  113. Returns the Process ID.
  114. =back
  115. =head1 EXPORTS
  116. The following constants are exported by default.
  117. CREATE_DEFAULT_ERROR_MODE
  118. CREATE_NEW_CONSOLE
  119. CREATE_NEW_PROCESS_GROUP
  120. CREATE_NO_WINDOW
  121. CREATE_SEPARATE_WOW_VDM
  122. CREATE_SUSPENDED
  123. CREATE_UNICODE_ENVIRONMENT
  124. DEBUG_ONLY_THIS_PROCESS
  125. DEBUG_PROCESS
  126. DETACHED_PROCESS
  127. HIGH_PRIORITY_CLASS
  128. IDLE_PRIORITY_CLASS
  129. INFINITE
  130. NORMAL_PRIORITY_CLASS
  131. REALTIME_PRIORITY_CLASS
  132. THREAD_PRIORITY_ABOVE_NORMAL
  133. THREAD_PRIORITY_BELOW_NORMAL
  134. THREAD_PRIORITY_ERROR_RETURN
  135. THREAD_PRIORITY_HIGHEST
  136. THREAD_PRIORITY_IDLE
  137. THREAD_PRIORITY_LOWEST
  138. THREAD_PRIORITY_NORMAL
  139. THREAD_PRIORITY_TIME_CRITICAL
  140. =cut
  141. # Local Variables:
  142. # tmtrack-file-task: "Win32::Process"
  143. # End: