使用VC ++和WMI执行powershell [英] Execute powershell using VC++ with WMI

查看:406
本文介绍了使用VC ++和WMI执行powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   我正在尝试使用VC ++和WMI运行一个PowerShell脚本。

    I'm trying to run a powershell script using VC++ with WMI.

    powershell脚本将为交换cmdlet添加snapin,并将运行以下命令,

    The powershell script will add snapin for exchange cmdlets and will run the following commands,

1。 Suspend-storagegroupcopy

1. Suspend-storagegroupcopy

2。 Update-storagegroupcopy

2. Update-storagegroupcopy

3。 Resume-storagegroupcopy

3. Resume-storagegroupcopy

我正在使用wmi" win32_process" - > [建立"执行powershell的方法。

i'm using wmi "win32_process" -> "Create" method to execute the powershell.

但是我收到以下错误

警告:存储组复制'< servername \\ \\ storagegroupname>'仍然被暂停。如果需要,可以在Exchange命令行管理程序中使用

Resume-StorageGroupCopy cmdlet恢复复制。

Update-StorageGroupCopy:种子设置失败:数据库种子设置错误:进程失败获得必要的备份权限以继续操作。

在C:\ PSScript.ps1:37 char:33

+      ;&NBSP;&NBSP;&NBSP;&NBSP;使用Update-StorageGroupCopy&NBSP; <<<< -identity $ Host \ $ storename -DeleteExistingFiles -Confirm:$ False -Force



我有设置代理身份验证

QUOT&;的 CoSetProxyBlanket(wmiSvc,RPC_C_AUTHN_DEFAULT,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; RPC_C_AUTHZ_NONE,


&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; COLE_DEFAULT_PRINCIPAL,


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; RPC_C_AUTHN_LEVEL_CALL,


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;  RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE);
"

"CoSetProxyBlanket(wmiSvc, RPC_C_AUTHN_DEFAULT,
                       RPC_C_AUTHZ_NONE,
                       COLE_DEFAULT_PRINCIPAL,
                       RPC_C_AUTHN_LEVEL_CALL,
                       RPC_C_IMP_LEVEL_IMPERSONATE, 0,EOAC_NONE);
"

尽管级别为IMPERSONATE,但它给出访问错误。我需要提供哪些身份验证才能完成任务?

Eventhough the level is IMPERSONATE , it is giving access error. What authentication should I need to provide so that I can achieve the task?

我正在尝试在本地执行此PowerShell脚本而不是远程执行。

i'm trying to execute this powershell script locally not remotely.

谢谢

Inmar。

 

推荐答案

您可以尝试使用CoInitializeSecurity()。您可以为整个过程设置安全性,而不是代理。即使您使用的是CoSetProxyBlanket,Impersonate也应该有效。

You can try using CoInitializeSecurity(). You can set security for the entire process, instead of the proxy.Even if you are using CoSetProxyBlanket, Impersonate should work.

您可以共享PS(PSScript.ps1)吗?

Can you share the PS (PSScript.ps1)?

 此脚本之前是否有效,现在它失败了?

 Did this script work previously before and now it is failing?


这篇关于使用VC ++和WMI执行powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆