读书人

怎么使用process.start(程序)打开程序

发布时间: 2012-03-18 13:55:39 作者: rapoo

如何使用process.start(程序)打开程序并返回程序的句柄
我使用process.start(程序),返回的Pid不对,使用getProcessByName(aa.ProcessName),查看到的Id,也不对,, Public aa As New Process
Public RunfilenName As String
Dim hwnd As IntPtr
aa.StartInfo.FileName = RunfilenName
aa.Start()
hwnd = aa.Id

Dim i As Int16 = 0
Do While 0 = hwnd And i < 500
Thread.Sleep(10)
hwnd = aa.Id
i += 1
Loop

'--------------------------------

Dim Myprocess() As Process = Process.GetProcessesByName(aa.ProcessName)


'----------------------------------
但是直接使用下面程序段就能正常列取进程的正常Id了,

ps = Process.GetProcesses()
With main.ListView1
For Each p In ps
Dim lvi As ListViewItem = New ListViewItem()
.Items.Add(p.ProcessName + " " + p.Id.ToString() + " " + p.BasePriority.ToString() + " " + Str(p.WorkingSet64 / 1000000.0))

Next
End With

如何处理

[解决办法]

VB.NET code
Public Class Form1    Public aa As New Process    Public RunfilenName As String = "D:\1.exe"    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim hwnd As IntPtr        aa.StartInfo.FileName = RunfilenName        aa.Start()        hwnd = aa.Id        'Dim i As Int16 = 0        'Do While 0 = hwnd And i < 500        '    System.Threading.Thread.Sleep(10)        '    hwnd = aa.Id        '    i += 1        'Loop        Me.Text = hwnd.ToString        MsgBox(hwnd.ToString)        '能取出值的。是你上面的代有。都不知道你上面的代用做什麽。    End SubEnd Class
[解决办法]
你试下
dim p as Process=Process.start("文件")
dim pid=p.id

读书人网 >VB Dotnet

热点推荐