Board logo

标题: [转载代码] [PowerShell每日技巧]保留指向进程的句柄(20140221) [打印本页]

作者: DAIC    时间: 2014-2-23 20:14     标题: [PowerShell每日技巧]保留指向进程的句柄(20140221)

When you launch an EXE file, PowerShell will happily start it, then continue and not care about it anymore:
PS C:\> notepad
PS C:\>


If you'd like to keep a handle to the process, for example to find out its process ID, or to be able to check back later how the process performs, or to kill it, use Start-Process and the –PassThru parameter. This returns a process object:
PS C:\> $process = Start-Process -FilePath notepad -PassThru
PS C:\> $process.Id
5936
PS C:\> 'You just launched process {0}.' -f $process.Id
You just launched process 5936.
PS C:\> 'CPU consumption in seconds so far: {0}.' -f $process.CPU
CPU consumption in seconds so far: 0.1092007.
PS C:\> $process.CloseMainWindow()
True
PS C:\>


http://powershell.com/cs/blogs/tips/archive/2014/02/21/keeping-a-handle-to-a-process.aspx
作者: PowerShell    时间: 2014-2-23 21:59

进程id=pid
窗口句柄 一般才简称句柄。
作者: DAIC    时间: 2014-2-24 08:56

回复 2# PowerShell


    由此可见,你没有理解英文原文的标题 Keeping a Handle to a Process
作者: DAIC    时间: 2014-2-24 08:57

回复 2# PowerShell


    不只是窗口句柄,文件句柄也简称句柄,句柄多了去了啊啊啊啊啊。
作者: PowerShell    时间: 2014-2-24 18:51

嗯,你说的对




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2