加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何获取正在运行的HTML Windows 8应用程序(不是WWHOST)的

发布时间:2020-12-15 21:52:00 所属栏目:百科 来源:网络整理
导读:我正在尝试获取使用给定ProcessID运行的 Windows 8应用程序的名称. 我可以访问wwahost,这是正在运行的进程的真实名称,但我想获取WWHOST实际运行的应用程序的名称. 我在讨论中看到了这个帖子http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldev
我正在尝试获取使用给定ProcessID运行的 Windows 8应用程序的名称.
我可以访问wwahost,这是正在运行的进程的真实名称,但我想获取WWHOST实际运行的应用程序的名称.

我在讨论中看到了这个帖子http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/c9665bf4-00e4-476c-badb-37126efd3f4b/,但没有具体的答案.

有任何想法吗 ?

解决方法

你想拨打 GetApplicationUserModelId

提供的示例应用程序允许您传入PID并获取有关应用程序的信息.例如:

C:srcGetAppInfoDebug>GetAppInfo.exe 7400
Process 7400 (handle=00000044)
Microsoft.BingWeather_8wekyb3d8bbwe!App

要移植到C#,

const int QueryLimitedInformation = 0x1000;
   const int ERROR_INSUFFICIENT_BUFFER = 0x7a;
   const int ERROR_SUCCESS = 0x0;

   [DllImport("kernel32.dll")]
   internal static extern IntPtr OpenProcess(int dwDesiredAccess,bool bInheritHandle,int dwProcessId);

   [DllImport("kernel32.dll")]
   static extern bool CloseHandle(IntPtr hHandle);

    [DllImport("kernel32.dll")]
    internal static extern Int32 GetApplicationUserModelId(
        IntPtr hProcess,ref UInt32 AppModelIDLength,[MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbAppUserModelID);

然后,您的代码应如下所示:

if (sProcessName.ToLower().Contains("wwahost") 
            && ((Environment.OSVersion.Version.Major == 6) && (Environment.OSVersion.Version.Minor > 1)))
            {
                IntPtr ptrProcess = OpenProcess(QueryLimitedInformation,false,iPID);
                if (IntPtr.Zero != ptrProcess)
                {
                    uint cchLen = 130; // Currently APPLICATION_USER_MODEL_ID_MAX_LENGTH = 130
                    StringBuilder sbName = new StringBuilder((int)cchLen);
                    Int32 lResult = GetApplicationUserModelId(ptrProcess,ref cchLen,sbName);
                    if (ERROR_SUCCESS == lResult)
                    {
                        sResult = sbName.ToString();
                    }
                    else if (ERROR_INSUFFICIENT_BUFFER == lResult)
                    {
                        sbName = new StringBuilder((int)cchLen);
                        if (ERROR_SUCCESS == GetApplicationUserModelId(ptrProcess,sbName))
                        {
                            sResult = sbName.ToString();
                        }
                    }
                    CloseHandle(ptrProcess);
                }
            }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读