Help - Search - Members - Calendar
Full Version: VBscripting help
ieXbeta Board > Tech > Developer Center
dkreifus
I'm trying to develop an internal website so that when users click on a printer name, it installs that printer.
This is what I have so far, with google help. I don't know VBscript sadly...
CODE
<html>
<head>
</head>
<p><font face="Verdana">Printer connection...</font></p>
<script LANGUAGE="VBScript">
<!--
on error resume next
Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\Server\Printer"
msg="Do you want " & PrinterPath & " to be Default printer?"
answ=msgbox(msg,vbYesNoCancel,"Add Printer")
If answ=vbYes then
  WshNetwork.AddWindowsPrinterConnection PrinterPath
  WshNetwork.SetDefaultPrinter PrinterPath
elseif answ=vbNo then
  WshNetwork.AddWindowsPrinterConnection PrinterPath
end if
window.close()
-->
</SCRIPT>
</html>


I want to achieve a couple things here.
1. I would like this to just execute as link from a page, rather than just being the page itself.
2. If that can't be done, I'd like the window to auto close, rather than a prompt to close the window popping up.
3. Anyway to have the activeX warnings go away? I understand if it is in my internal network, it won't be a problem.

Thanks for the help. I haven't done web design in ages, and especially not anything dynamic or flashy.
DangerousDave86
CODE
<html>
<head>
</head>
<p><font face="Verdana"><a href="#" onclick="AddPrinter('\\\\RUFUS\\EPSON')">Printer connection...</a></font></p>
<script LANGUAGE="VBScript">
<!--
Function AddPrinter (PrinterPath)
on error resume next
Set WshNetwork = CreateObject("WScript.Network")
msg="Do you want " & PrinterPath & " to be Default printer?"
answ=msgbox(msg,vbYesNoCancel,"Add Printer")
If answ=vbYes then
  WshNetwork.AddWindowsPrinterConnection PrinterPath
  WshNetwork.SetDefaultPrinter PrinterPath
elseif answ=vbNo then
  WshNetwork.AddWindowsPrinterConnection PrinterPath
end if
End Function
-->
</SCRIPT>

</html>
The VBS works, but I can't test it actually adding a network printer here.
dkreifus
Looks good so far. I think the ActiveX prompts will just have to be set by local permissions.
Any reason that in VB you have to use \\\\ instead of just \\?
Taco Bell
The double backslash convention is fairly typical programming syntax for defining one in a string dk, as a single backslash is reserved for the code.
dkreifus
Thats what I figured, but I wanted to ask anyway.
I tested the code, and it works. Now i'm trying to implement a test for an existing printer before adding it. I'll post back with my results.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.