Slinger’s Thoughts

June 4, 2009

Adding printers from SharePoint

Filed under: Integration, SharePoint — Tags: — slinger @ 12:50 pm

Had an interesting case come up recently.  My manager wanted a way for our users to be able to easily add our network printers to their computers.  Apparently going to \\printerserver\printer01\ is too much of a challenge for our end users.  Initially you would think that it would be simple, and that you just create a list with a hyperlink column and add the UNC path to your printer for the link and away you go.  The problem with that is, when you click on the link, somehow a magical file:/// gets added so that your link now looks like file:///\\printerserver\printer01\ which is of course useless.  An associate of mine found an article online where the solution is to create a batch file that has the link.  This of course requires a user to choose to either “save” or “run” the file.  If they can’t figure out how to get there from the UNC path given to them, chances are they aren’t going to get the batch file right either.  There is hope however, and I have figured something out that so far works for us, and will hopefully work for you too.

This is actually several potential solutions combined into one that almost works flawlessly.  Each one had the right idea, the problem was getting them all hammered down into one solution.  First you are going to need a page that the users can access to add their printers.  Not too much of a big deal, any blank SharePoint page will work.  You could even park what we are about to add on an existing page if you so desired.  The first thing that you need to do is add the function that will enable this whole mess to work to begin with. Once you have a page created or in mind, go ahead and fire up your SharePoint designer, and open the page.

Near the top of the page (code view) you will notice a <script> tag.  Very small and unassuming.

<script>
   var navBarHelpOverrideKey = "wssmain";
</script>

We want to add another <script> tag immediately after this one.

<script type="text/vbscript">
function AddP(pName)
Set WshNetwork = CreateObject("Wscript.Network")
WshNetwork.AddWindowsPrinterConnection pName
end function
</script>

This little bit of scripting add the function to add printers using the Windows Scripting Host (from what I have read.)

The next thing I did was to create a table where I could describe the printers I wanted to give out users access to.  Nothing fancy, just a simple table. I won’t go into detail about how to create or format the table.

2009-06-04 13.18

You’ll notice that I also added some buttons to the table for our users to click.  The next part was kind of fun to figure out.  The button has an onClick action, but is also a link.  Don’t ask me why that is important, but somehow it is.  I would have thought that one instance or the other would suffice.

For simplicity’s sake, I will use the top printer as an example;

When you add a button to your page, it just needs to be a simple HTML Input button.  The code for the button will like like this:

<input name="Button1" type="button" value="Add">

Which is great, but it doesn’t actually do anything.  We need to make it a link and give it a function.

<a href="#" language="vbscript" onclick="AddP(‘\\cecprt\4e1′)"><input name="Button1" type="button" value="Add"></a>

You will notice that we make the button a link using some basic HTML, and added a VB function to the link.  The VB Function calls the script that we added earlier, and adds the printer with the UNC path \\cecprt\4e1\ .  Great! Problem is right now it won’t do a damn thing because of security settings in IE.  This is something that you may be able to get with your network/system administrator on.  If you add the page that hosts this table to the list of trusted sites in IE, then when you click on one of the “Add” buttons, you get a warning about a potentially unsafe ActiveX control running.

2009-06-04 13.32

I think this could be mitigated with the proper permissions as well.  Just to test however, if you click “Yes,” and wait about 20 seconds, the printer will be added to your computer.

There are other solutions out there, but they start running into problems when they try to do too much and ActiveX security limitations start popping up all over the place.  I just wanted to keep this as simple as possible.

Hope this helps someone out. 

The information for this article was gathered from the links below.
http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/9e752df8-b60f-47c3-b862-08b9e9d9a03e
http://blogs.msdn.com/mab/archive/2009/02/13/install-a-remote-printer-via-a-hyperlink-in-html.aspx

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.