Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling vbscript function from html button

Tags:

html

vbscript

Don't be surprised if what I'm doing is completely wrong or if the solution is obvious.

<script type="text/vbscript">
    Function AddPrinter()
        Set objNetwork = CreateObject("WScript.Network")
        objNetwork.AddWindowsPrinterConnection "\\a2031slhsfile1\2031CAT-T113-HP4014dn"
        objNetwork.SetDefaultPrinter "\\a2031slhsfile1\2031CAT-T113-HP4014dn"
        MsgBox "The printer was added and set as the default printer."
    End Function
</script>

I added the above vbscript to an HTML document in the head section and one of the buttons has the following property:

onclick="AddPrinter()"

I didn't find much about this when searching on Google for an hour. What I did find didn't work. How does it know whether you're calling the function from javascript or vbscript or whatever anyway?

I get this error:

SCRIPT429: ActiveX component can't create object: 'WScript.Network'
like image 506
Baga Jr. Avatar asked May 25 '26 03:05

Baga Jr.


1 Answers

Your Internet Explorer security settings prevent the creation of the ActiveX control. You need to allow "initialize and script ActiveX controls not marked as safe for scripting".

like image 91
Ansgar Wiechers Avatar answered May 26 '26 16:05

Ansgar Wiechers