9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTAで超簡単なデスクトップアプリを作ってみる

Last updated at Posted at 2019-08-20

はじめに

Windows環境であれば、何もインストールしないでHTMLベースのデスクトップアプリが作れます。私、凄く気に入っていてかなり愛用し続けていますが、とってもマイナーな様子…

「HTMLは書いたことあるけど、アプリ作るのって…難しいんじゃね?」
という方に一回これを実行してみて欲しいです!

スクリプト

test.hta
<!doctype html>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta charset="utf-8">
<title>秘密のアプリ</title>
<ul>
    <li><a id="notepad" href="#">メモ帳を起動する</a>
    <li><a href="https://qiita.com/sozaiya/items/475211daf85bbb208635">IEでsozaiyaさんの記事を表示する</a>
    <li><a id="shutdown" href="#">今すぐシャットダウンする</a>
</ul>
<script>
    var data = {
        shell: new ActiveXObject('wscript.shell')
    };
    document.getElementById("notepad").addEventListener("click", function () {
        data.shell.exec("notepad");
    }, false);
    document.getElementById("shutdown").addEventListener("click", function () {
        if (window.confirm("本当にシャットダウンしますか?")) {
            data.shell.exec("cmd /c shutdown -s -t 0");
        }
    }, false);
</script>

上記ファイルを作成したらダブルクリックで実行します。

解説

メモ帳を開いたり、シャットダウンしてみたりと、あまり実用的ではないですが、応用すれば色んなことできるかも?と感じてもらえたら嬉しいです(^^)

9
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?