使用vbYesNo遇到if then语句的问题

时间:2014-06-18 15:47:01

标签: if-statement printing vbscript

我正在尝试创建一个脚本,询问用户是否要将网络打印机设置为默认值。我的问题是,无论他们选择什么(是或否),它都将其设置为默认值,它总是在其他地方回显我的echo语句。有人能告诉我我做错了吗?

`' Printers.vbs - Windows登录脚本。

   printername = "DCPTTEAM462W"
   server = "DCDEPLOY03"

   Dim objectNetwork, printer
   printer = "\\DCPRINT03\DCPTTEAM462W"

   Msgbox printername & " will now install on your computer.",0, "Add printer" & printername  


   intRespnseY = Msgbox("Would you like " & printername & " to be set as your default printer", vbYesNo, "Set as Default")


   If intResponseY = vbNo Then

   Set objNetwork = CreateObject("WScript.Network")
   objNetwork.AddWindowsPrinterConnection printer
   WScript.Echo "DCPTTEAM462W was added as a printer."

   Else

   Set objNetwork = CreateObject("WScript.Network")
   objNetwork.AddWindowsPrinterConnection printer
   objNetwork.SetDefaultPrinter printer
   WScript.Echo "DCPTTEAM462W has been set as your default printer."

   End If

`

2 个答案:

答案 0 :(得分:0)

使用

Option Explicit

避免像:

这样的错误
intRespnseY = Msgbox("...")
If intResponseY = vbNo Then

(标记缺失的" o")

答案 1 :(得分:0)

你有一个错字:

intRespnseY = Msgbox(....

应该是

intResponseY = Msgbox(....