【问题标题】:Problems writing a WSUS-Program in AutoIt using Powershell使用 Powershell 在 AutoIt 中编写 WSUS 程序的问题
【发布时间】:2015-04-23 07:59:37
【问题描述】:

我是 WSUS、Powershell 和 AutoIt 的新手。我正在编写一个程序,只需单击几下即可批准多个更新(而不是每次更新和组单击 5 次)。因此,我有一个 Powershell 脚本,可以搜索所有计算机组和可用更新。

脚本本身可以正常工作,我只是在 AutoIt 中调用它们时遇到问题(我已经发现,我必须导入模块 UpdateServices 但我无法使其正常工作)。

这是我的 AutoIt 程序的一部分:

$sComSend = '-ExecutionPolicy ByPass import-module UpdateServices; ' & $sScript & '\Search_Updates.ps1 -FilePath ' & $sUpdateOutput
ShellExecuteWait("powershell.exe", $sComSend)

但这不起作用。另一个尝试是这样的:

$sComSend = 'powershell.exe import-module UpdateServices; "-ExecutionPolicy ByPass ' & $sScript & '\Search_Updates.ps1 -FilePath ' & $sUpdateOutput & '"'
RunWait(@ComSpec & " /c " & $sComSend, "", @SW_SHOW , $stdout_child)

但这也没有用。老实说,在第二个中,我什至不知道这些参数中的大部分到底是什么意思。 有人看到我的错误吗?

谢谢:-)

【问题讨论】:

    标签: windows powershell autoit shellexecute


    【解决方案1】:

    我建议它保持简单。

    创建一个名为“myStuff.ps1”的新 powershell 文件,并在其中放入:

    param([string]$FilePath)
    
    Import-Module UpdateServices
    
    Write-Host "FilePath = $FilePath"
    

    完成后,调用它:

    $fileLocation = "C:\myAbsolutePath\myStuff.ps1"
    $arguments = '-FilePath "C:\Testing one two three"'
    
    $commandLine = '-WindowStyle Normal -NoExit -NoLogo -NoProfile -Command & "' & $fileLocation & '" ' & $arguments
    
    Run($commandLine, @SystemDir, @SW_SHOW , $stdout_child)
    

    【讨论】:

    • 谢谢!但这也不起作用(希望不是因为我用 RunWait 替换了 Run)。我什至不确定我想要的是否可行
    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 2017-04-30
    • 2012-06-13
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多