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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.