GetUpdateServer在AdminProxy类未找到

问题描述 投票:0回答:1
$servername='DC1'
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($servername,$False)

这是我试图运行PowerShell命令。但是,让一个例外,因为 -

    Exception calling "GetUpdateServer" with "2" argument(s): "The type initializer for 
'Microsoft.UpdateServices.Internal.Constants' threw an exception."
At line:3 char:1
+ $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : TypeInitializationException

当我试图refrencing的Microsoft.UpdateServices.Administration.dll并试图利用GetUpdateServer方法,我无法找到AdminProxy类中的方法。这是代码 - 线

    using Microsoft.UpdateServices.Administration;
using Microsoft.UpdateServices;
using System.Runtime.InteropServices;
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[GuidAttribute("6391AFBB-45A8-4107-A154-F27DB8F03049")]
public sealed class AdminProxy
{

}

namespace WindowsApplication2
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IUpdateServer obj;
            obj = AdminProxy.GetUpdateServer();


        }
    }
c# windows powershell windows-update
1个回答
0
投票

由于用户在boeprox的评论中指出的,你需要运行PowerShell控制台为管理员。

© www.soinside.com 2019 - 2024. All rights reserved.