VBScript: onClick=addPrint('\\PrintServer\hp color LaserJet 2550 PCL6')

Hi guys.

I have a website with this vbscript: onClick=addPrint('\\PrintServer\hp color LaserJet 2550 PCL6'). I get an error when I try to add that printer and it is because of the spaces in the printer-name.
This command works: onClick=addPrint('\\PrintServer\hp colorLaserJet2550PCL6')

How do I solve this with the spaces?
LVL 2
BilletkontoretAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RobSampsonConnect With a Mentor Commented:
Hi, I have tested this, and it works:
<input type="button" name="AddPrinter" value="AddPrinter" onClick="addPrint('\\PrintServer\hp color LaserJet 2550 PCL6')">

with this script:
<script language="vbscript">
Sub addPrint(strPrintShare)
   Response.Write "About to add printer: " & strPrintShare
   'MsgBox strPrintShare
End Sub
</script>

That outputs the full printer share.  I would suggest that in your addPrint procedure, you output the parameters passed to it so you can see what it's doing.

Regards,

Rob.
0
 
BilletkontoretAuthor Commented:
I can make this work if I run the html-file on my own pc, but everytime I execute it on a webserver(apache) I get an error: object required 'response'.
I have added the site to my list of trusted sites in IE7.
0
 
RobSampsonCommented:
You won't really need the response, but try
Document.Write "About to add printer: " & strPrintShare

or
Document.Body.InnerHTML = Document.Body.InnerHTML & "<BR>About to add printer: " & strPrintShare

Regards,

Rob.
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
BilletkontoretAuthor Commented:
Where should I insert this Rob?
0
 
RobSampsonCommented:
Sorry, replace
Response.Write "About to add printer: " & strPrintShare

from the code I posted with
Document.Write "About to add printer: " & strPrintShare

or
Document.Body.InnerHTML = Document.Body.InnerHTML & "<BR>About to add printer: " & strPrintShare

Regards,

Rob.
0
 
BilletkontoretAuthor Commented:
Hi Rob.

I have this script now:

Sub addPrint(strPrintShare)
Document.Write "About to add printer: " & strPrintShare
' MsgBox strPrintShare
End Sub
</script>

<input type="button" name="AddPrinter" value="AddPrinter" onClick="addPrint('\\\\omada\\RBU')">

When I click the AddPrinter button, I get a new page with this message: About to add printer: \\omada\RBU. But the printer doesn't get added.

If I write the printer-name like this in the script: ="addPrint('\\omada\RBU')"  - the new page says: About to add printer: \omadaRBU. And still no printer is added.

What is wrong here?
0
 
BilletkontoretAuthor Commented:
Hi Rob. I got this solved now.
This one did it: <input type="button" name="AddPrinter" value="AddPrinter" onClick="addPrint('\\\\PrintServer\\hp color LaserJet 2550 PCL6')">

Note the double up on \'es
0
 
RobSampsonCommented:
Ah, it seems that the script is removing the slashes, try this sub:
Sub addPrint(strPrintShare)
Document.Write "About to add printer: " & Replace(strPrintShare, "\", "\\")
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection Replace(strPrintShare, "\", "\\")
' MsgBox strPrintShare
End Sub



Regards,

Rob.
0
All Courses

From novice to tech pro — start learning today.