title: How to use Win32 API to get HANDLE of a process for an application in Windows
body: <p>I am using Java Native Access (JNA) to use Win32 API (kernel32.dll) to set an application's priroty and affinity. the application name ( part of the name string) is known, I need to find out the HANDLE to the process for the application. Once I know the HANDLE of the process, I can use Win32 API SetPriorityClass and SetProcessAffinityMask to modify the application priority and CPU affinity. </p>
  
  <p>Both SetPriorityClass and SetProcessAffinityMask need the HANDLE of the process as input.</p>
  
  <p>More info. I have a Java application that calls a VM container to start a VM instance with a name "Mylinux". the VM instace of "Mylinux" will be running as applicaiton in Windows, but VM container appended additional string to form the application name, i.e. "Mylinux(snapshot3)..." as application name showing in the Windows task manager. I want the Java app to use JNA (interface to Win32 API) to modify the application's priority and CPU affinity.</p>
  
  <p>I need to know WIN32 API that can return a HANDLE of the process for a given application name ( part of application, not the whole string).</p>
  
  <p>Thanks
  John</p>