简体   繁体   中英

Getting the type (x64 or x86) of a running process in vb.net macro code

I'm writing a macro to automate the process of attaching to the IIS worker process (w3wp.exe, Windows Server 2k8) from Visual Studio. The trouble is that I often two app pools running at any given time, one in x64 mode and one in x86 mode. This means there are two processes called w3wp.exe running at any given time, and the only way to distinguish between them is the mode they are running in. When I use the "Attach to Process" dialog, there is a "Type" column that shows that information so I know which w3wp.exe to attach to, but I can't figure out how to get that information in my macro.

Based on information here, I was able to come up with the following:

Function AttachToProcess(ByVal processName As String) As Boolean

  Dim proc As EnvDTE.Process
  Dim attached As Boolean
  For Each proc In DTE.Debugger.LocalProcesses
      If proc.Name = "w3wp.exe" Then
          proc.Attach()
          attached = True
      End If
  Next

  Return attached
End Function

But half the time this just grabs the wrong process. I need a second if statement to check the mode/type of the process. I've spelunked through the classes using quickwatch as best I can, but just cannot figure out where the information is. Can anyone help? Thanks!

There's not enough info in the Process class to let you find out. You can only get the ProcessID for the process. From there, you'd have to P/Invoke OpenProcess() to get the process handle, then IsWow64Process() to find out if it is a 32-bit process. CloseHandle() to close the process handle. Not actually sure if P/Invoke is possible in a macro. Visit pinvoke.net to get the declarations you'll need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM