[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to create a list of shared printers in JavaScript

Posted on 2007-08-08
12
Medium Priority
?
2,938 Views
Last Modified: 2011-09-20
How can I create a list of shared printers in JavaScript from a remote client?

I tried changing following code to create a list of files from a directory of a remote client but without success.

Code:
var fso = new ActiveXObject("scripting.filesystemobject");
//var myFolder = fso.GetFolder("\\\\<remote PC>\\C$");
var myFolder = fso.GetFolder("\\\\127.0.0.1\\C$");
var myEnum = new Enumerator(myFolder.Files);
           
var names = new Array();
for(var i = 0; !myEnum.atEnd(); i++)
{
      names[i] = myEnum.item();
      myEnum.moveNext();
      alert("File: " + names[i].Name);
}

0
Comment
11 Comments
 
LVL 15

Expert Comment

by:OMC2000
ID: 19655381
We use Meadco ScriptX licensed version for printing control. It has method printing.EnumPrinters, which we use for the similar task
you can check details here
http://www.meadroid.com/scriptx/docs/printdoc.htm#EnumPrinters

This functionality is not free...
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19655424
What type of page is this?  If it is in an intranet then browser security may allow this but some security settings might need to be adjusted.  You would also need to use IE since you are trying to use an ActiveX object.

If this is an Internet page then you can't do this with Javascript or any clientside script.  The browser won't let you for obvious security reasons.  You could make an object or applet but even that would probably need to be signed and/or trusted.

Let me know if you need more info about this or have a question.  I didn't look at the code closely because I am afraid you are trying this on an Internet page and it just won't work.

bol
0
 
LVL 3

Author Comment

by:joachim.claeys@teleatlas.com
ID: 19655497
I'm using IE on our internal network (intranet)

The above code does work on remote clients  (but it's only for listing files).
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:VincentPuglia
ID: 19655546
0
 
LVL 3

Author Comment

by:joachim.claeys@teleatlas.com
ID: 19660494

I checked: http://www.tek-tips.com/viewthread.cfm?qid=1383515&page=1
but it's all in vbscript I need jscript.
0
 
LVL 3

Author Comment

by:joachim.claeys@teleatlas.com
ID: 19661031
I created another jscript to list installed printers.

If I could only let this list the printers from a remote client!

Code:
var network = new ActiveXObject("WScript.Network");
var oPrinters = network.EnumPrinterConnections();

for (x=0 ; x < oPrinters.count() ; x++)
{
      WScript.Echo ("Printer (" + x + "): " + oPrinters.item(x));
}
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 19661430
<script language="JScript">

         var WshNetwork = WScript.CreateObject("WScript.Network");

         var oDrives = WshNetwork.EnumNetworkDrives();

         var oPrinters = WshNetwork.EnumPrinterConnections();

         WScript.Echo("Network drive mappings:");

         for(i = 0; i < oDrives.length; i += 2) {

            WScript.Echo("Drive " + oDrives.Item(i) + " = " + oDrives.Item(i + 1));

         }

         WScript.Echo();

         WScript.Echo("Network printer mappings:");

         for(i = 0; i < oPrinters.length; i += 2) {

            WScript.Echo("Port " + oPrinters.Item(i) + " = " + oPrinters.Item(i + 1));

         }

      </script>
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 19661437
0
 
LVL 3

Author Comment

by:joachim.claeys@teleatlas.com
ID: 19661478
The last source I posted is based on:
http://msdn2.microsoft.com/en-us/library/zhds6k80.aspx

But this only shows the local shares I want to see the shares from a remote client.

0
 
LVL 3

Author Comment

by:joachim.claeys@teleatlas.com
ID: 19668576
I created a workaround via analyzing the output of a dos command "net view":

<script language="JScript">
      var server="10.1.254.222";
      var shell = new ActiveXObject("wscript.shell");
      var result = shell.Exec("net view \\\\" + server).StdOut.ReadAll();
      var line = new Array();
      line = result.split("\n");

      for (x=0; x < line.length ; x++)
      {
            var foundpos = line[x].toLowerCase().indexOf("print  ");
            if (foundpos > 0)
            {
                  var printer = line[x].substr(0,foundpos);
                  // trim
                  var re = /^\s*(\S*(\s+\S+)*)\s*$/
                  printer =  printer.replace(re, "$1");
                  alert("printer(" + x + "): " + printer);
            }
      }
</script>
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20210762
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question