perl进程操作
2015-10-10 09:30
351 查看
#!/user/local/bin/perl/
use Win32::Process;
use Win32;
##创建记事本进程并打开文件temp.txt
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
Win32::Process::Create($ProcessObj,
"C:\\WINDOWS\\system32\\notepad.exe",
"notepad temp.txt",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
$pid = $ProcessObj->GetProcessID();
print("pidnotepad:\t $pid \n");
use Win32::OLE;
$machine= shift || Win32::NodeName();
##下面枚举机器中正在运行的所有进程信息
#$class = "WinMgmts:{impersonationLevel=impersonate}!//$machine";
#$wmi = Win32::OLE->GetObject($class);
$wmi = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2');##两种方法都可以的
$plist = $wmi->InstancesOf("Win32_Process");
$~ = PROC_LIST;
write;
$~ = PROC_INF;
$n = 0;
foreach $Proc (Win32::OLE::in( $plist )){
write;
$n++;
}
print " ===========================\n";
print " -> Processes number : $n <-\n";
print " ===========================";
# -----------------------------------------------------------------------------
format PROC_LIST =
@||| @|||||||||||||||| @||||||
"PID", "Process Name", " Memory"
---- ----------------- --------
.
format PROC_INF =
@||| @<<<<<<<<<<<<<<<< @|||||||
$Proc->{'ProcessID'},$Proc->{'Name'}, $Proc->{'PeakWorkingSetSize'}
use Win32::Process;
use Win32;
##创建记事本进程并打开文件temp.txt
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
Win32::Process::Create($ProcessObj,
"C:\\WINDOWS\\system32\\notepad.exe",
"notepad temp.txt",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
$pid = $ProcessObj->GetProcessID();
print("pidnotepad:\t $pid \n");
use Win32::OLE;
$machine= shift || Win32::NodeName();
##下面枚举机器中正在运行的所有进程信息
#$class = "WinMgmts:{impersonationLevel=impersonate}!//$machine";
#$wmi = Win32::OLE->GetObject($class);
$wmi = Win32::OLE->GetObject('winmgmts:\\\\.\\root\\cimv2');##两种方法都可以的
$plist = $wmi->InstancesOf("Win32_Process");
$~ = PROC_LIST;
write;
$~ = PROC_INF;
$n = 0;
foreach $Proc (Win32::OLE::in( $plist )){
write;
$n++;
}
print " ===========================\n";
print " -> Processes number : $n <-\n";
print " ===========================";
# -----------------------------------------------------------------------------
format PROC_LIST =
@||| @|||||||||||||||| @||||||
"PID", "Process Name", " Memory"
---- ----------------- --------
.
format PROC_INF =
@||| @<<<<<<<<<<<<<<<< @|||||||
$Proc->{'ProcessID'},$Proc->{'Name'}, $Proc->{'PeakWorkingSetSize'}
相关文章推荐
- chm是什么格式文件?怎么打开
- Android:录像
- 快捷键
- 为命名空间起别名
- play framework实现多文件上传
- MyCAT 日志文件描述
- perl从键盘输入多行的结束符
- android 线程池
- js调用跨域
- Photoshop图象切片保存为网页HTML(DIV+CSS布局)的方法
- SharePoint 要一个多行文本类型字段为特殊类型的链接
- Certificates does not conform to algorithm constraints 异常的解决方法
- 怎么恢复win10回收站清空的文件 恢复win10清空回收站的文件方法
- Ubuntu 上最好的图标主题
- 数字字符串解码为字母
- TD-SCDMA系统终端协议栈PDCP子层的研究
- 安卓中通知(Notification)的基本使用方法
- 聊聊css水平垂直居中那些事
- liunx文章库
- c# wince textbox 选择全部内容