【发布时间】:2014-04-08 19:09:09
【问题描述】:
我有一个情况。我正在使用调用 Powershell 脚本的批处理文件在远程桌面上安装网络打印机,但是在远程桌面上安装打印机后,Powershell 什么也不返回 - 所以我的批处理文件将无法继续......我必须手动点击输入两次以使其成为echo DONE 并运行其余脚本。知道为什么吗?
@echo off
Copy /Y "\\AddPrinter\AddPrinter.ps1" "C:\scripts"
powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1"
Echo DONE
Del /F /Q "C:\ntfs3\scripts\AddPrinter.ps1"
这是我的powershell脚本,我什至在脚本末尾加了exit,但是远程PC上的powershell只是不会退出.....所以它不会返回批处理
$PrinterPath = "\\server-01\Printer0101"
$net = new-Object -com WScript.Network
$net.AddWindowsPrinterConnection($PrinterPath)
exit
顺便说一句,我正在使用 psexec 来调用这个批处理文件,其中包含一个包含所有电脑名称的 txt 文件。
psexec @%1 -u admin -p xxxxxx -c -f "C:\AAA\AddPrinter.bat"
我做了一些研究,有人说需要使用call 和%1 > null 使Powershell 返回批处理。但它也不起作用。
Call powershell.exe -ExecutionPolicy Bypass -Command "C:\scripts\AddPrinter.ps1" %1 > null
我只能使用批处理命令安装打印机,但安装后,新打印机总是设置为默认打印机。但是如果使用powershell安装它,它不会改变远程桌面上的默认打印机。
rundll32 printui.dll PrintUIEntry /ga /n\\server-01\printer0101
请指教。
【问题讨论】:
-
也许你的 powershell 脚本需要时间来完成它的执行。能粘贴一下powershell文件的内容吗?
-
我粘贴了powershell脚本,只需15秒即可完成。
-
如果您从 PowerShell 提示符手动运行 PowerShell 脚本,它会提示输入吗?
-
不,它只是运行并完成。完全没有提示
-
它适用于我的批处理文件中的
Call。也许将-NoProfile开关添加到您的powershell.exe 行?您在哪个帐户下运行?
标签: windows batch-file powershell