How to pass parameter to an exe (windows form application) from activex in web application?

2.3k views Asked by At

I have a windows form application. I had converted it to a set up and called its exe file from web application using activeX as follows:-

 var executableFullPath = "C:\\ScannerExeFile\\Scannerapplication.exe";

 var shellActiveXObject = new ActiveXObject("WScript.Shell");

 shellActiveXObject.Run(executableFullPath,1, false);

 shellActiveXObject = null;

Now i want to pass a string parameter to the windows form application.Can anyone help me?

2

There are 2 answers

0
Reshma Menon On BEST ANSWER

I got the answer.The code is below:-

var executableFullPath = "C:\\ScannerExeFile\\Scannerapplication.exe param1 param2 param3";

var shellActiveXObject = new ActiveXObject("WScript.Shell");

shellActiveXObject.Run(executableFullPath,1, false);

shellActiveXObject = null;

In windows application, you should edit the main function in Program.cs as

  static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        if(args!=null && args.Length>0)
        Application.Run(new Scanner(args));
        else
            Application.Run(new Scanner(args));
    }
}

In class, you should change the constructor as follows:-

public Scanner(string[] args)
        {
            Arguments = args;
            InitializeComponent();
        }

where Arguments is a string array

private string[] Arguments;
0
Orkun Bekar On

You need to use PARAM tag in ActiveX object like that:

<OBJECT  classid="clsid:959B7E21-6C0B-3BEC-BA2E-48DA2B6D83K5">                
            <PARAM NAME="Id" VALUE="2">
</OBJECT>