Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Program code to run in a web page?

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
I have the following lines of code in a VB program I wrote:

Set net = CreateObject("WScript.Network")
strUNCPrinter = "\\testserv\prn1"
net.AddWindowsPrinterConnection strUNCPrintera

I would like to put this code snippet inot a web page to run from a local intranet site at my facility. So far just drawing blanks.

The goal is to have a link for a user to click on and it would execute the code ultimately installing a network printer on their workstation.

Can someone assist with this? Coming up empty on everything I have tried so far.

thx
 
Convert it to an Active Server Page (ASP)

It will be mostly the same... one difference is that you'd use Server.CreateObject instead of just CreateObject
 
ok....but how do you execute the command via a link?

something like "Click Here" then execute the script.

thx
 
HTML code:
<input type="button" value="Install Printer" id="printInstall">

ASP code:
Sub printInstall_onClick()
Set net = Server.CreateObject("WScript.Network")
strUNCPrinter = "\\testserv\prn1"
net.AddWindowsPrinterConnection strUNCPrintera
End Sub

Did not test out, but this should work for you.
 
I may have misunderstood the question... Is there a web server involved from which the user will request a page or do you just want a file that can itself be opened in a browser?
 
Sheco...not looking to actually open a file. If you type in the UNC in the address bar of IE, it will prompt you to install the printer if not already done so. That's what I'm trying to accomplish.

Country73...I tried your code but get an error saying server object required. Here is my coding...I believe I probably have it coded wrong as I am in unchartred territory here.

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Welcome to Adobe GoLive 6</title>
</head>

<body bgcolor="#ffffff">

<BODY>

<script language="VBScript">
<!--
Sub printInstall_onClick()
Set net = Server.CreateObject("WScript.Network")
strUNCPrinter = "\\<servername>\<prnname>"
net.AddWindowsPrinterConnection strUNCPrinter
End Sub
-->
</script>
</head>

<body>
<P>
<input type="button" value="Install Printer" id="printInstall">
</P>
</body>

</html>
 
Ok...I have something working now:

Sub printInstall_onClick()
Dim objNet
On Error Resume Next
Set objNet = CreateObject("WScript.NetWork")
Dim strInfo
strInfo = "\\<servername>\<printername>"
objNet.AddWindowsPrinterConnection(strInfo)

End Sub

I guess it did not like the "net"

Now...my question is....can this be done via a text link instead of a button?

 
Forget what I said about the ASP... you want to make the printer to the client using the web page, not the server providing it.

It sounds like now you just want the script to run on thte client when the page is loaded... so take it out of the function or call the function on the browser onLoad event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top