【发布时间】:2017-12-04 17:22:55
【问题描述】:
我曾经找到一个脚本,如果我使用多个壁纸,可以轻松更改我的壁纸。
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys("^ ")
WshShell.SendKeys("+{F10}")
WshShell.SendKeys("n")
WshShell.SendKeys("{ENTER}")
但是我需要一个单独的链接来调用脚本。 现在我想知道我是否可以将这些多行代码作为参数直接传递给powershell.exe。
我确实读到我可以使用; 对齐多行并尝试构建单行,但是它没有运行......或者它确实运行了,没有反馈,没有任何变化。如果我将命令行粘贴到正在运行的 powershell 实例中,它就会退出。
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -Command "set WshShell = WScript.CreateObject('WScript.Shell'); WshShell.SendKeys('^ '); WshShell.SendKeys('+{F10}'); WshShell.SendKeys('n'); WshShell.SendKeys('{ENTER}')"
我基本上只是把它们串联起来,用单引号代替双引号来转义特殊字符,那为什么它不能作为单独的脚本呢?
【问题讨论】:
-
如果要从 powershell.exe 命令行执行脚本,请使用
-File参数。 (您必须在 powershell.exe 命令行最后指定-File。) -
那是 vbscript.. 不是 powershell
-
我请尊敬的先生参考已经发布的评论,它指的是 powershell.exe 命令行(仅此而已)。
标签: powershell command-line vbscript arguments