我必须将其转换为Powershell:
On Error Resume Next
strComputer = "."
Set WshShell = CreateObject("WScript.Shell")
Set oEnv = WshShell.Environment("Process")
sScriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1))
WshShell.run "MsiExec.exe /i " & Chr(34) & sScriptPath & "\Install.msi" & chr(34) & " Transforms=" & chr(34) & sScriptPath & "\Install.mst" & chr(34),0 , True
WScript.Quit(0)
我所知道的:
On Error Resume Next
是Powershell中的默认设置
Set WshShell = CreateObject("WScript.Shell")
是这样的
$WshShell = New-Object -ComObject Wscript.Shell -Strict
我可以这样做吗?
$oEnv = $WshShell.Environment("Process")
完整路径或当前脚本的WScrip.ScriptFullName是什么?
如何在Powershell中调用WshShell.run命令?
发布于 2016-07-29 18:22:37
在PowerShell中,您通常只需使用
$env:VARIABLE
而不是像这样复杂的东西
$oEnv = (New-Object -COM WScript.Shell).Environment('Process')
$oEnv.Item('VARIABLE')
如果需要专门从"User“、"Machine”或"Process“环境中获取变量,可以使用如下代码:
[Environment]::GetEnvironmentVariable('VARIABLE', 'User')
与WScript.ScriptFullName
等效的是$MyInvocation.MyCommand.Path
(或在较新版本中为$PSScriptRoot
)。
您可以使用call operator (&
)代替Run
方法。
https://stackoverflow.com/questions/38653989
复制相似问题