I have created a VBScript function that allows users to install a network printer by clicking a button. This works great, but there is no feedback after clicking the button. I'm trying to add an alert after the button is clicked, but I'm having trouble with the syntax.

Here is the functioning onClick function for installing a printer:

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

<td><a href="#" language="vbscript" onclick="AddP('\\PrinterName')"><input name="Button1" type="button" value="Add"></a></td>
share|improve this question
feedback

3 Answers

up vote 0 down vote accepted

Just add this line after your WshNetwork.AddWindowsPrinterConnection line

MsgBox "Printer Added"
share|improve this answer
This was exactly what I was looking for – JWSTL Nov 24 '12 at 16:59
feedback

Simplest solution: Add a colon to your declaration which acts as a statement separator. This will allow you to call an additional function.

<a href="#" language="vbscript" onclick="AddP('\\PrinterName': msgbox 'Printer added')">

share|improve this answer
feedback

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>
share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.