13

我有一个非常简单的 powershell 脚本(见下文)。我在我的个人资料中使用以下内容获得了 installutil 别名:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

在powershell中,我只是:

installutil assemplylocation.dll

这成功返回。(安装/提交都成功完成)。然而,当我检查注册表或在 powershell 中使用 get-pssnapin -registered 时,它不会显示我的程序集。前几天我做了这个,效果很好,但我似乎无法复制它......请指教。

using System;
using System.Management.Automation;
using System.ComponentModel;

namespace PSBook_2_1
{
    [RunInstaller(true)]
    public class PSBookChapter2MySnapIn : PSSnapIn
    {
        public PSBookChapter2MySnapIn()
            : base()
        { }

    // Name for the PowerShell snap-in.
    public override string Name
    {
        get
        {
            return "Wiley.PSProfessional.Chapter2";
        }
    }

    // Vendor information for the PowerShell snap-in.
    public override string Vendor
    {
        get
        {
            return "Wiley";
        }
    }

    // Description of the PowerShell snap-in
    public override string Description
    {
        get
        {
            return "This is a sample PowerShell snap-in";
        }
    }
}

// Code to implement cmdlet Write-Hi
[Cmdlet(VerbsCommunications.Write, "Hi")]
public class SayHi : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hi, World!");
    }
}

// Code to implement cmdlet Write-Hello
[Cmdlet(VerbsCommunications.Write, "Hello")]
public class SayHello : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hello, World!");
    }
}

}

4

7 回答 7

14

downatone 的回答让我走上了正轨,但我的问题恰恰相反。我的项目设置为任何 CPU,并且我在 Win7 x64 上,因此从我的代码启动然后使用 snapin 安装 dll 的 powershell 是 64 位的。但是我使用的安装命令指向 32 位 .net 运行时,即

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll

应该是什么时候

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll

注意框架路径中的 64。

于 2011-11-07T12:01:47.953 回答
11

原来问题是我有一个 32 位 cmdlet - 但只检查 64 位版本的 powershell ...

于 2009-03-12T14:17:50.793 回答
1

这里的关键点是记住 Visual Studio 2010 仍然是一个 32 位应用程序,这意味着当我使用命令提示符时,它默认为 InstallUtil 的 32 位变体。在这种情况下,注册表项因此写入 Wow64 位节点而不是 64 位注册表本身并不是很明显。

于 2011-06-30T20:20:02.733 回答
1

您是否以提升用户身份运行 installutil?它将信息写入注册表的受保护部分。如果您以非管理员身份在 Vista 上执行此操作,可能会产生奇怪的结果。

于 2009-02-18T06:22:11.417 回答
1

以管理员身份运行以运行ps

于 2009-07-08T07:35:07.003 回答
0

我必须使用 x86(32 位)版本的 PowerShell 来添加 Snapin。因为我发现它不像它应该的那样直接,这里有一个有用的链接如何打开 PowerShell 32bit:

http://technet.microsoft.com/en-us/library/hh847733.aspx

于 2013-12-16T23:43:40.037 回答
-1

遇到同样的问题 - 我试图使用命令

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll 

代替

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll 

在 OS win2k8 x64 上具有 64 位 cmdlet(项目配置。任何 CPU)。

于 2012-08-28T06:27:45.207 回答