0

クライアントマシンにまだインストールされていない場合は、 ftpからソフトウェアをインストールする必要があるasp.net MVC4 Webアプリケーションを使用しています。インストール中に、次のようなデータをクライアント マシンのレジストリに書き込みます。

Test
 |__DefaultIcon
 |__Shell
      |__Open
           |__command

テストのどこに、レジストリに以下のようなものを書きます。ここに画像の説明を入力

このエントリは、ソフトウェアをインストールした後にのみ発生します。そのため、次に誰かがソフトウェアをダウンロードしようとしたときに、ソフトウェアを自動的に初期化できます。マシンには既にソフトウェアがあります。以下のコードを使用してソフトウェアを初期化するには:

 <script type="text/javascript">
            function LaunchURLScript() {
                var url = "Test:";

                // Creates an object which can read files from the server
                var reader = new XMLHttpRequest();
                // Opens the file and specifies the method (get)
                // Asynchronous is true

                   reader.open('GET', url, true);

                //check each time the ready state changes
                //to see if the object is ready



                reader.onreadystatechange = checkReadyState;

                function checkReadyState() {


                    if (reader.readyState === 4) {



                        //check to see whether request for the file failed or succeeded
                        if ((reader.status == 200) || (reader.status == 0)) {

                            //page exists -- redirect to the checked
                            //checked for page
                            // document.location.href = url;

                            window.open(url);
                            self.focus();
                        }
                        else {
                            alert("456");
                            //does nothing and quits the function
                            //if the url does not exist
                            return;

                        }

                    }//end of if (reader.readyState === 4)

                }
                // end of checkReadyState()

                // Sends the request for the file data to the server
                // Use null for "get" mode
                try{
                    reader.send(null);
                }

                catch (err) {
                    alert(err.message);
                } 
            }

        </script>

しかし問題は、window.open(url) は、url が存在しない場合でも実行されることです。これは、ソフトウェアがインストールされていないことを意味します。window.open(url) を呼び出す前に、url が存在するかどうかを確認してください。

4

0 に答える 0