首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未使用安装工具注册C# Powershell管理单元

未使用安装工具注册C# Powershell管理单元
EN

Stack Overflow用户
提问于 2009-02-17 20:28:28
回答 7查看 8.9K关注 0票数 13

我有一个非常简单的powershell脚本(见下文)。我已经在我的配置文件中使用以下内容为installutil添加了别名:

代码语言:javascript
复制
set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

在powershell中,我只是:

代码语言:javascript
复制
installutil assemplylocation.dll

这将成功返回。(Install/Commit both成功完成)。然而,当我检查注册表时,或者在powershell中使用get-pssnapin -registered时,它没有显示我的程序集。前几天我这样做了,它工作得很好,但我似乎无法复制它……请给我建议。

代码语言:javascript
复制
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!");
    }
}

}

EN

回答 7

Stack Overflow用户

发布于 2011-11-07 20:01:48

唐纳通的回答让我走上了正确的道路,但我的问题恰恰相反。我的项目设置为任何CPU,并且我在Win7 x64上,所以从我的代码启动的powershell是64位的,然后安装带有管理单元的动态链接库。但是,我使用的安装命令指向32位.net运行时,即

代码语言:javascript
复制
C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll

当它应该是的时候

代码语言:javascript
复制
C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll

请注意Framework路径中的64。

票数 14
EN

Stack Overflow用户

发布于 2009-03-12 14:17:51

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

票数 11
EN

Stack Overflow用户

发布于 2009-02-18 06:22:11

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/558577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档