正确的CMD执行代码

时间:2018-03-21 20:35:13

标签: powershell cmd

在PowerShell脚本下面查找正确的CMD命令。

$wshshell = New-Object -ComObject WScript.Shell
$lnk = $wshshell.CreateShortcut("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\"+"\Internet Explorer.lnk")
$lnk.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
$lnk.Save()

试过:

powershell.exe -Command $wshshell = New-Object -ComObject WScript.Shell $lnk = $wshshell.CreateShortcut("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\"+"\Internet Explorer.lnk") $lnk.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe" $lnk.Save()
At line:1 char:81
+ ... ect -ComObject WScript.Shell $lnk = $wshshell.CreateShortcut(C:\Progr ...
+                                                                  ~
Missing ')' in method call.
At line:1 char:145
+ ... \Accessories"+\Internet Explorer.lnk) $lnk.TargetPath = C:\Program Fi ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

1 个答案:

答案 0 :(得分:0)

powershell.exe $wshshell = New-Object -ComObject WScript.Shell; $lnk = 
$wshshell.CreateShortcut('C:\ProgramData\Microsoft\Windows\Start 
Menu\Programs\Accessories\'+'\Internet Explorer.lnk'); $lnk.TargetPath = 
'C:\Program Files\Internet Explorer\iexplore.exe'; "$lnk.Save()"

分号完成了这项工作

相关问题