Launching an executable from a website?

前端 未结 11 698
小鲜肉
小鲜肉 2020-12-29 16:45

We\'re developing a site that will only run on the intranet, and computers with access to this intranet will have this executable installed. We can\'t have any \"Would you

相关标签:
11条回答
  • 2020-12-29 17:02

    Been there done that. MIME types (accepted answer at the moment I add this) requires a lot of configuring on client and server.This is quite a bit of work, and you end up with temporary files etc.

    Our solution was to add our own "Custom URL Protocol Handler". Basically, add URL type x-our-intranet and make your corporate app the URL handler for it. Now any link will start your corporate app, passing "x-our-intrenet:foo" as a command-line argument. All it takes is a client-side registry entry, similar to the MIME types.

    0 讨论(0)
  • 2020-12-29 17:06

    If you want to run application that you already have on the computer, you can do it via registering to the registry and them call it in HTML like you send email (mailto).

    So, you just need to create registry:

    using Microsoft.Win32;
    using System;
    using System.IO;
    using System.Linq;
    
    namespace WMConsole
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Listening..");
    
                //Gets the current location where the file is downloaded
                var loc = System.Reflection.Assembly.GetExecutingAssembly().Location;
                if (!Directory.Exists(@"D:\Console\"))
                {
                    System.IO.Directory.CreateDirectory(@"D:\Console\");
                }
                //Creates the Downloaded file in the specified folder
                if (!File.Exists(@"D:\Console\" + loc.Split('\\').Last()))
                {
                    File.Move(loc, @"D:\Console\" + loc.Split('\\').Last());
                }
                var KeyTest = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true);
                RegistryKey key = KeyTest.CreateSubKey("alert");
                key.SetValue("URL Protocol", "wnPing");
                key.CreateSubKey(@"shell\open\command").SetValue("", @"D:\Console\WMConsole.exe %1");
            }        
        }
    }
    

    And then you can call it in HTML via:

    <a href="alert:wmPing">Click to trigger</a>
    

    Here is the full article about it: https://www.codeproject.com/Articles/1168356/Run-an-EXE-from-Web-Application

    0 讨论(0)
  • 2020-12-29 17:07

    This is an old article about web deployment of executables. I know this is possible using Internet Explorer (because of our fragmented development team we still have to support some of this). I don't know about the firefox implications.

    0 讨论(0)
  • 2020-12-29 17:11

    I recommend you take a look at Adobe Flex / Air, it is designed with this model in mind and the inherent security barn door that it opens.

    0 讨论(0)
  • 2020-12-29 17:12

    Try this JavaScript:

    function executeCommands(inputparms)
    {
    // Instantiate the Shell object and invoke its execute method.
    
    var oShell = new ActiveXObject("Shell.Application");
    
    var commandtoRun = "c:\windows\Notepad.exe";
    
    // Invoke the execute method. 
    oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1"); 
    }
    

    You will have to set the browser security settings accordingly, and this would work only in IE.

    0 讨论(0)
  • 2020-12-29 17:14

    We're developing a site that will only run on the intranet, and computers with access to this intranet will have this executable installed.

    Does this mean the EXE is already installed on the desktop? You just want to launch it from the website?

    If so, you can associate the EXE with a MIME Content Type and when the user clicks it, it will launch.

    Pick a Content Type and a file extension, for your EXE name, for instance:

    CauseChaos.exe
    Associated with .chaos file extenstion
    Content Type will be: application/chaos
    

    Associate the file extension with your EXE via the EXE install. I show it here, using InnoSetup

    [Registry]
    Root: HKCR; Subkey: .chaos; ValueType: string; ValueData: CauseChaos; Flags: uninsdeletekey
    Root: HKCR; Subkey: CauseChaos; ValueType: string; ValueData: CauseChaos Tool; Flags: uninsdeletekey 
    Root: HKCR; Subkey: CauseChaos\DefaultIcon; ValueType: string; ValueData: {app}\CauseChaos.exe,0; Flags: uninsdeletekey
    Root: HKCR; Subkey: CauseChaos\shell\open\command; ValueType: string; ValueData: "{app}\CauseChaos.exe ""%1"""; Flags: uninsdeletekey

    Associate the MIME content type with the file extension, through the EXE install.

    [Registry] (continued...)
    Root: HKCR; Subkey: HKCR\Mime\Database\Content Type\application/chaos; ValueType: string; ValueName: Extension; ValueData: .chaos; Flags: uninsdeletevalue
    0 讨论(0)
提交回复
热议问题