0

ボタンがクリックされたときにプリンターのインストールを開始する VBScript を少し含むページがあります。スクリプトが正常に完了すると、アラートが表示されます。

現在、別のボタン クリック イベントを追加しようとしています (おそらく jQuery を使用)。これは、プリンターのインストールが開始されたことをユーザーに通知します (ボタン クリック時)。これは、プリンターのインストールに 20 秒から 1 分かかる場合があるためです。

次のコードを実装すると、jQuery コード ブロック内からオブジェクトが期待されているというエラーが表示されます

   <script type="text/vbscript">
        function AddP(pName)
            Set WshNetwork = CreateObject("Wscript.Network")
            WshNetwork.AddWindowsPrinterConnection pName
            MsgBox "Printer Added"
        end function
   </script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready( function (){ 

            $("#btn").click( function(){

                 alert("Printer Install Started");

            });

         });
    </script>

 <td><a href="#" language="vbscript" onclick="AddP('\\PrinterName')"><input id="btn" name="Button1" type="button" value="Add"></a></td>
4

3 に答える 3

1

エラー チェックとプロンプトを追加する場合は、デフォルトで設定します。これは、スクリプトを作成する最初の本当のショットなので、覚えておいてください。

<script type="text/vbscript">
function AddP(pName)

Shortname = split(pName, "\")

    If MsgBox("Click YES to install  " &ShortName(3),VBYesNo, "Printer Utility") = vbYes Then

        MsgBox "Installing Printer " &ShortName(3) &vbCrLf &vbCrLf &"This may take a few moments"


        Set WshNetwork = CreateObject("Wscript.Network")

        On Error Resume Next
        WshNetwork.AddWindowsPrinterConnection pName
            If Err.Number <> 0 Then

            MsgBox "Printer is not available for install." &vbCrLF &"Please contact Tech Support for assistance"
                Else If MsgBox ("Would you Like  " &ShortName(3) &" to be your Default Printer?" ,vbyesno, "Printer Utility")  = vbYes Then

                WshNetwork.SetDefaultPrinter pName
                MSgBox ShortName(3) &"  Installed and Set as Default",0,"Printer Utility"
                Else MSgBox ShortName(3) &"  Installed",0,"Printer Utility"

                End if

            End If

        On Error GoTo 0
     Else Msgbox "Printer Install Cancelled"
    End if
end function

< /スクリプト>

于 2013-05-10T21:59:01.140 に答える
0

If you want to give the user some indication something is happening while the printer is being added you could change the button state.

<script type="text/vbscript">
   function AddP(pName)
       Dim allButton1s
       Set allButton1s = document.getElementsByName("Button1")
       allButton1s(0).value = "Please wait..."
       Set WshNetwork = CreateObject("Wscript.Network")
       WshNetwork.AddWindowsPrinterConnection pName
       MsgBox "Printer Added"
       allButton1s(0).value = "Add"
   end function
</script>
于 2012-11-28T23:51:19.223 に答える
0

プリンターのインストールを開始する前にアラートを表示したい場合は、その前に別の MsgBox 行を追加します。

<script type="text/vbscript">
   function AddP(pName)
       MsgBox "Printer Install Started"
       Set WshNetwork = CreateObject("Wscript.Network")
       WshNetwork.AddWindowsPrinterConnection pName
       MsgBox "Printer Added"
   end function
</script>

注: プリンターのインストールは、ユーザーが [印刷のインストールが開始されました] アラートで [OK] をクリックするまで開始されません。それを回避したい場合は、代わりにボタンの状態変更の回答を使用してください。

于 2012-11-28T23:52:48.737 に答える