首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎么使用process.start(程序)打开程序并返回程序的句柄

2012-03-18 
如何使用process.start(程序)打开程序并返回程序的句柄我使用process.start(程序),返回的Pid不对,使用getP

如何使用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

热点排行