Hi ,

I am new to c# , I want to know how to develop ActiveXControls in c# ,Can you let me know some samples if you have.

My Requirement is : to run an Exe which is residing on the Client machine .

I.e in the web page i will ask the user to select the exe path (in to a text box),
and on click of a button in webpage i want to run the exe which is on client machine(path will be in the text box)

can you tell me how to achieve this ,(Is it require activeX .. etc)

Dani AI

Generated

As asked, the short answer is: a plain web page cannot (and should not) start arbitrary EXE files on a visitor's PC. was correct to flag the security issue, and 's ActiveX approach only worked for legacy Internet Explorer and is not a viable cross‑browser solution today. (blogs.windows.com)

Practical, supported approaches (all require a small program installed on the client and explicit user consent):

  • Register a custom URL protocol (myapp://...). The native app registers a key under HKCR (or HKCU\Software\Classes) and receives the full URI when invoked from a page. This is simple to deploy for controlled environments; the native app must validate inputs before doing anything with filenames/paths. Example register code (C#):

    using Microsoft.Win32;
    
    void RegisterProtocol(string name, string exePath)
    {
        using var key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Classes\" + name);
        key.SetValue("", "URL:" + name + " Protocol");
        key.SetValue("URL Protocol", "");
        using var cmd = key.CreateSubKey(@"shell\\open\\command");
        cmd.SetValue("", $"\"{exePath}\" \"%1\"");
    }

    The OS launches the app when a page links to myapp://.... (learn.microsoft.com)

  • Use a browser extension + Native Messaging (extension ↔ installed native host). This is the most robust, secure option when two‑way JSON messaging is needed. The extension starts communication and the native host runs the requested action after validating it. (developer.chrome.com)

  • Run a localhost helper (local HTTP/WebSocket server). The page calls http://localhost:port (server must send appropriate CORS headers and require a local token) — useful for richer protocols but exposes additional attack surface; require auth/whitelisting. (developer.mozilla.org)

  • ClickOnce / DirectInvoke can still be used on Windows in some scenarios (Edge supports it on Windows) for deploying or launching signed apps from a site. It is platform/installer specific. (learn.microsoft.com)

Summary: do not try to bypass browser protections. Pick a helper pattern (custom protocol or native messaging), sign the installer, validate every argument server‑ and client‑side, and deploy the helper via normal installation methods or enterprise policy.

Recommended Answers

All 4 Replies

Hi,
I think it is not possible for security reason.

Hi <
Thank you for your reply,
If i know the location of exe on client machine then also is it not possible to start executing that exe on click of a button from webpage (using any javascript .. or any thing .)?

with regards and thanks,
santhosh k r

If you know the location of exe on client machine then also it is not possible. I think if such script in your webpage it may be blocked by browser.

I am not exact. but this is should not be possible, because any website can run exes in any computer, and can make harm to that computer.

If you know the location of exe on client machine then also it is not possible. I think if such script in your webpage it may be blocked by browser.

I am not exact. but this is should not be possible, because any website can run exes in any computer, and can make harm to that computer.

--------

Hi,

I had similar requirement,we can do that using javascript ,but the browser should have active x scripting enabled.

If that is fine you can use

<script language="JavaScript" type="text/javascript">  
         obj= new ActiveXObject( "WScript.Shell" )  
         function RunExe()   
         {  
            obj.Run("notepad.exe") ;  
        }  
      
    </script>

for more info check this link
http://www.dotnetspider.com/resources/19547-Run-exe-file-Java-Script.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.