冰楓論壇

標題: [C#] 取得執行檔的執行實體名稱 [打印本頁]

作者: whitefox    時間: 2023-6-25 23:32
標題: [C#] 取得執行檔的執行實體名稱
這個例子使用反射方法達成
  1. string sExeFile = @"C:\Windows\notepad.exe";

  2. Assembly assebly = Assembly.LoadFrom(sExeFile);

  3. Module module = assebly.ManifestModule;
  4. Type[] types = module.GetTypes();

  5. Type tpForm = typeof(Form);

  6. foreach (Type type in types)
  7. {
  8.     if (type.IsSubclassOf(tpForm))
  9.     {                  
  10.         MessageBox.Show(type.FullName);
  11.     }
  12. }
複製代碼





歡迎光臨 冰楓論壇 (https://bingfong.com/) Powered by 冰楓