Win32 确定进程 ID [英] Win32 determine process ID

查看:66
本文介绍了Win32 确定进程 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Win32 .NET 中创建一个进程,我可以为操作系统确定应用程序将获得哪个 PID 吗?

I want to create a process in Win32 .NET can I determine FOR the OS which PID the application will get ?

更新:

1) 我问它是因为我有一个问题,我有 2 个 .NET 应用程序(相同的应用程序),我让每个应用程序都获得了参数 ID,我想使用脚本(使用参数)来决定这是一个并得到它的PID2) 我想从外部而不是从 .NET 进程中了解它.我需要一个脚本

1) I am asking it because I have a problem in which I have 2 .NET application (the same ones) that I have each one of them got parameter ID and I want using a script (using the parameter) to decide which is the one and get it's PID 2) I want to know it from out side not from the .NET Process. I need for a script

推荐答案

您永远无法确定进程将获得什么 PID.您只能在启动进程后确定进程获得的 PID.

You can never determine what PID a process will get. You can only determine what PID a process did get after you start the process.

在 .Net 中,您可以执行以下操作

In .Net you can do the following

var newProcess = Process.Start(someExeFile);
var id = newProcess.Id

在 Win32 中,CreateProcess 函数将返回一个 PROCESS_INFORMATION 结构作为函数的输出参数.它具有新的 PID 作为其成员之一 (dwProcessId)

In Win32 the CreateProcess function will return an PROCESS_INFORMATION struct as an out parameter of the function. It has the new PID as one of it's members (dwProcessId)

这篇关于Win32 确定进程 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆