如何获得一个正在运行的HTML Windows 8应用程序的名称(不是whwhost)
本文关键字:Windows whwhost 应用程序 HTML 不是 运行 何获得 一个 | 更新日期: 2023-09-27 18:17:37
我试图获得与给定ProcessID一起运行的Windows 8应用程序的名称。我可以得到wwahost,这是正在运行的进程的真实名称,但我想得到WWHOST实际运行的应用程序的名称。
我看到这个线程http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/c9665bf4-00e4-476c-badb-37126efd3f4b/与那个讨论,但没有具体的答案。
有什么想法吗?
你想调用GetApplicationUserModelId
提供的示例应用程序允许您传入PID并获取有关应用程序的信息。例如:
C:'src'GetAppInfo'Debug>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, ref cchLen, sbName))
{
sResult = sbName.ToString();
}
}
CloseHandle(ptrProcess);
}
}
看看在c#中从引用的DLL中获取执行程序集名称
您可以查看Assembly.GetEntryAssembly()或Assembly.GetExecutingAssembly(),例如
string exeAssemblyName = Assembly.GetEntryAssembly().GetName().Name;