Get parameters value from .exe files using ASP.NET C# | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

Get parameters value from .exe files using ASP.NET C#

Tuesday

                                                                                    In one of my project my clients requirements is scanning a document from local scanner and directly upload into the server through web application. But there is no direct method to access local machine from sever code in dot net, so we need some other solutions to access local .exe (to activate scanner) file from server.

Finally Google answering me "ActiveX0bject". Yes we can run .exe file from server by using ActiveX shell command. Here is the sample code to run client's side .exe file from server  by using JavaScript and ActiveX0bject.

Enable ActiveX controls in IE for run .exe files from local :
                                Before  we enable ActiveX in IE settings with the following simple steps, 
Step -1:  Open IE -->Tools --> Internet Options

Step -2:  Go to security tab choose your zone (Internet (OR) Local)  then click custom Level button

Step-3:  Just set "The Initialize and script ActiveX controls not marked as safe" as "Prompt"

          



 And the following JavaScript code is for run .exe (In my case "ImageScanner.exe")file with parameter session id, display order  and user id.

JavaScript Code 

function runScaningApp(sessId, disorder, userId){

var shell=new ActiveX0bject("WScript.shell");

var res = shell.run('"ImageScanner.exe" "'+ sessId +'" "'+ disorder+'" "'+ userId+'", '1', true);

 if (res == "0"){
   alert ("Your success message");
 }
 else{
   alert ("Sorry! Some error occurred");
 }
}

Finally the following c# code for accessing the .exe's param value. Use this code in your .exe's  .cs file 

public class scanner :system.Windows.Forms.Form, IMessageFilter{

private string sessionId;
private string disorder;
private string userId;

 public Scanner (string[args){
  sessionId = args [0];
  disorder= args [1];
  userId = args [2];
 }
}

0 comments:

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets