windows - 在 GAC 中注册 DLL(CMD 或 PowerShell)

标签 windows powershell dll gac

我正在尝试在 GAC 中注册一个 .DLL。 目前我无法证明它已添加到程序集中。

使用命令

C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll"

提示告诉我程序集已添加到缓存中。

检查时

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -l file.dll

它说程序集中有 0 个元素。

通过 Powershell 命令,我尝试像这样添加 DLL:

PS C:\WINDOWS\system32> Add-Type -AssemblyName "System.EnterpriseServices"

PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish

PS C:\WINDOWS\system32> $publish.GacInstall("file.dll")

我做错了什么?如何将 .DLL 添加到 GAC?最好的方法(对我来说)是使用 Powershell 来做到这一点。

最佳答案

请记住以管理员身份运行 PowerShell,否则这将不起作用。

$dllpath = c:\path\yourdll.dll
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            
$publish.GacInstall($dllpath)

在此之后您可能需要重新启动任何相关服务或程序,例如:

if (Get-Service "YourService" -ErrorAction SilentlyContinue)
    {
        Stop-Service -Name 'YourService' 
        Start-Service -Name 'YourService' 

    }

或者只是重新启动计算机。

关于windows - 在 GAC 中注册 DLL(CMD 或 PowerShell),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45593418/

相关文章:

c++ - 无法编译访问另一个 dll 的 dll

c++ - 在不加载 DLL 的情况下使用函数?

C 控制台 API 窗口

windows - vue awesome swiper 在 Windows 上安装失败

c++ - 手动创建PE

powershell - 在 powershell 脚本中捕获批处理文件的输出

windows - 使用批处理脚本检查环境中是否存在 JAVA_HOME

powershell - 如何为我的租户授予我的应用程序对 AAD Graph API 的完全访问权限?

Powershell CREDSSP 和 TLS 1.2

c++ - 使用 C++ 在 DLL 中进行子类化