-1

There is a myFirst.asp in which there is a button, on click i want a specific jar to be run but using vbscript i am able to do so but as u know only IE support this vbscript functionality. I am looking a way i can run my jar at any platform using any browser. using asp or vbs or jquery by anyway it could happen. PLZ help Thanks in Advance.

myFirst.asp

 <script type="text/javascript">  
                            function runMyCommand(){
                                var wshshell = new ActiveXObject("shell.application");
                                wshshell.ShellExecute("cmd.exe", 'java -jar "C:\\Program Files\\MyServer\\bin\\mporter.jar" "C:\\license.file" ', "C:\\WINDOWS\\system32", "open", 1);
                                wshshell=null;

                            }
 </script>

  or can use this one 

  function runMyCommandASP() {
                                $.ajax({
                                    type: "POST",
                                    url: "managemporter_launch.asp/AnalyzeRequest",
                                    data: "{}",
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (msg) {
                                        Alert("you got it");
                                    }
                                });

    <INPUT type="button" size=200 value=" Run porter " runat="server" id=Button1 name=btnExport title="Launch porter" onClick="javascript:runMyCommandASP()">

and looking jar to run at position

 java -jar "C:\\Program Files\\MyServer\\bin\\mporter.jar" "C:\\license.file" 

using javascript or asp or vbs

Singh
  • 1
  • 2
  • If you're using asp then the VBScript is run on the server, so it doesn't matter which browser you're using. Are you just trying to embed a java applet, in which case you should find plenty of guides if you just use Google – John Nov 25 '14 at 13:21
  • Yes i am using ASP also fine that VBScript run on server but if i am using Set wshshell=CreateObject("WScript.Shell") wshshell.run "cmd.exe /c notepad ajay" it didn't work – Singh Nov 25 '14 at 13:27
  • So your working example is using client side vbs. Are you able to post your code, then someone who knows javascript might be able to suggest a cross browser alternative? – John Nov 25 '14 at 13:43
  • I don't think you'll be able to do that in anything other than IE. Whether you use js or vbs you'll need IE if you want to use an Active X object. `new ActiveXObject` in js is the same as `CreateObject` in vbs – John Nov 25 '14 at 19:49
  • Hi John, i am not looking to use ActiveXobject but looking for a way using anything but fulfill my task... and run over any browser any OS, ActiveXObject is not necessity. – Singh Nov 26 '14 at 05:47
  • See this question - http://stackoverflow.com/questions/877774/how-can-i-run-a-program-or-batch-file-on-the-client-side – John Nov 26 '14 at 12:36
  • could u plz help i want to run a .vbs file from .asp page where i recieve ajax request from runMyCommandASP() using Set wshshell=CreateObject("WScript.Shell") wshshell.run "cmd.exe /c cscript ""C:\inetpub\wwwroot\jarrS\res\include\createmport.vbs""", 1, true but this didn't work Is there any way i can run my this createmport.vbs or any other application at my .asp page – Singh Nov 26 '14 at 14:03

1 Answers1

0

For the reasons in this question in I don't think you can do this with client side code. As the link in my comment above explains, allowing webpages to control a user's machine would be a massive security hole which is why browsers prevent this.

I can't gurarantee this will work, but you may have a chance if you change this file into an .asp page. ASP is server side code so it bypasses limitations on what browsers are able to do directly

C:\inetpub\wwwroot\jarrS\res\include\createmport.vbs

This path implies that you have a local version on IIS on your machine. Try renaming your file with it an .asp extension and surround all the code in the page with <% %> You would then be able to execute script via its local url ie http://localhost/yoursitepath/createimport.asp. As its talking to a .jar file then you'll need to give your local website's IUSR account execute permission on the .jar

You could then execute the script with a simple html link or, presumably, with an ajax call - I'm no expert with ajax. The bottom line is that when you call the file it needs to be through a url so that the server executes it.

John
  • 4,658
  • 2
  • 14
  • 23