반응형
public static IntPtr GetHwndByExeFile(string exeFilePath)
{
    IntPtr windowHandle = IntPtr.Zero;
 
    FileInfo fi = new FileInfo(exeFilePath);
 
    string processName = fi.Name.Replace(fi.Extension, "");
 
    Process[] processList = Process.GetProcessesByName(processName);
 
    if (processList.IsNullOrEmpty())
    {
        return IntPtr.Zero;
    }
 
    foreach (Process process in processList)
    {
        if (process.MainModule.FileName.Equals(exeFilePath))
        {
            windowHandle = process.MainWindowHandle;
            break;
        }
    }
 
    return windowHandle;
}
반응형

+ Recent posts