1
A
回答
3
您必須使用CreateProcess()函數來運行命令行,如「fullPathToRegasm/somekeys文件名」。
主要問題是檢測regasm位置 - 使用GetCORSystemDirectory()函數。首先使用LoadLibrary()加載mscoree.dll,然後調用GetProcAddress()來定位GetCORSystemDirectory()函數,然後調用該函數。
這將爲您帶來.NET安裝的根源。 regasm通常位於任何給定機器上安裝根目錄的相同子路徑中,因此您可以安全地將檢測到的根與子路徑組合起來,這將是一個有效的regasm位置。
0
由於NET是並排安裝,因此您的系統中可能會有regasm.exe
的多個版本,並且類似地,某些版本只是更新,因此您可能會從某些位置找不到您期望找到的版本。
我花了幾個小時尋找做到這一點的最好辦法,因爲也有一些atempts以獲得正確的點(registry,unmanaged code,Environment等)對NET version這greatly varies。而且每個Windows版本都帶有his own NET版本。
以上都不是我的口味系統穩定足夠,所以我找到了我自己的方式:只搜索所有可用regasm.exe
文件,並檢查哪些是最新版本。就如此容易。
這可能是一個意見問題,但如果你覺得我的答案可以有更高的成功,豎起大拇指!
// Scan for ALL regasm.exe available.
string netdir = Environment.GetEnvironmentVariable("WINDIR") + "\\Microsoft.NET\\";
string[] filelist = System.IO.Directory.GetFiles(netdir, "regasm.exe", System.IO.SearchOption.AllDirectories);
// Find the NEWEST regasm.exe available.
string newestFilePath = string.Empty;
FileVersionInfo currFileVersion = null;
FileVersionInfo newestFileVersion = null;
foreach (string currFilePath in filelist) {
currFileVersion = FileVersionInfo.GetVersionInfo(currFilePath);
if (newestFileVersion == null) {
newestFilePath = currFilePath;
newestFileVersion = currFileVersion;
} else if ((currFileVersion.FileMajorPart >= newestFileVersion.FileMajorPart) &&
(currFileVersion.FileMinorPart >= newestFileVersion.FileMinorPart) &&
(currFileVersion.FileBuildPart >= newestFileVersion.FileBuildPart) &&
(currFileVersion.FilePrivatePart > newestFileVersion.FilePrivatePart)) {
newestFilePath = currFilePath;
newestFileVersion = currFileVersion;
}
}
相關問題
- 1. 如何從C++程序運行regasm.exe(.NET 4)
- 2. 如何從VIM運行C程序?
- 3. 從m.file運行C++程序
- 4. 從C++程序運行python程序?
- 5. 運行perl程序從C++程序
- 6. 如何從C++程序運行另一個程序
- 7. 如何從Visual Studio命令提示符以外的命令行運行regasm.exe?
- 8. 在.net上運行regasm.exe com類
- 9. 如何從命令行運行程序?
- 10. 運行C#程序
- 11. C#運行程序
- 12. 如何使用unordered_map運行C++程序
- 13. 如何從C++程序執行c#exe
- 14. 從Linux下的C程序運行多個C程序
- 15. 從C#運行安裝程序#
- 16. 從C++程序運行Java方法
- 17. 運行.net應用程序從c + +
- 18. 從Eclipse IDE運行C++應用程序
- 19. 從bootloader程序運行c代碼
- 20. 從c#應用程序運行powershell
- 21. 運行從C#應用程序
- 22. 從Django Framework運行C++程序
- 23. 如何從node.js程序運行Excel VBA?
- 24. 如何從字符串運行程序?
- 25. 如何從終端運行clojure程序
- 26. 如何從SQL運行程序?
- 27. 如何從cmd運行程序
- 28. 你如何從Java運行R程序?
- 29. 如何從.Net程序運行Import-PSSession
- 30. 如何從USB運行程序?
你可以給我示例代碼片段plzzzz – Cute 2009-06-09 06:00:02