Пример #1
0
        public static AppInfo Create(IntPtr hWnd)
        {
            var process = GetProcessFromHandle(hWnd);

            if (process == null)
            {
                return(emptyAppInfo);
            }

            var appInfo = new AppInfo();

            try
            {
                if (process.MainModule.FileVersionInfo.CompanyName != null &&
                    process.MainModule.FileVersionInfo.CompanyName.ToLower().Contains("microsoft"))
                {
                    appInfo.Version  = process.MainModule.FileVersionInfo.ProductVersion ?? "";
                    appInfo.Company  = process.MainModule.FileVersionInfo.CompanyName ?? "";
                    appInfo.FileName = process.MainModule.FileVersionInfo.FileName ?? "";
                    if (string.IsNullOrEmpty(process.MainModule.FileVersionInfo.FileDescription))
                    {
                        appInfo.Name        = process.MainModule.FileVersionInfo.ProductName ?? "";
                        appInfo.Description = process.MainModule.FileVersionInfo.FileDescription ?? "";
                    }
                    else
                    {
                        appInfo.Name        = process.MainModule.FileVersionInfo.FileDescription ?? "";
                        appInfo.Description = process.MainModule.FileVersionInfo.ProductName ?? "";
                    }

                    appInfo.FullName = process.ProcessName ?? "";
                }
                else
                {
                    appInfo.Version     = process.MainModule.FileVersionInfo.ProductVersion ?? "";
                    appInfo.Company     = process.MainModule.FileVersionInfo.CompanyName ?? "";
                    appInfo.FileName    = process.MainModule.FileVersionInfo.FileName ?? "";
                    appInfo.Name        = process.MainModule.FileVersionInfo.ProductName ?? "";
                    appInfo.Description = process.MainModule.FileVersionInfo.FileDescription ?? "";
                    appInfo.FullName    = process.ProcessName ?? "";
                }
            }
            catch (InvalidOperationException)
            {
                return(emptyAppInfo);
            }
            catch (Exception)
            {
                try
                {
                    appInfo.Version     = "";
                    appInfo.Company     = "";
                    appInfo.FileName    = "";
                    appInfo.Name        = process.ProcessName;
                    appInfo.Description = "";
                    appInfo.FullName    = "";
                }
                catch (Exception)
                {
                    return(emptyAppInfo);
                }
            }

            return(appInfo);
        }
Пример #2
0
 public static LogInfo Create(AppInfo _appInfo, String _windowTitle)
 {
     return(new LogInfo(_appInfo, _windowTitle));
 }
Пример #3
0
 public static Aplication ToAplication(AppInfo appInfo)
 {
     return(new Aplication(appInfo.Name, appInfo.FileName, appInfo.Version,
                           appInfo.Description, appInfo.Company, appInfo.FullName));
 }