1
0

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 3 years have passed since last update.

Windowsコマンドをコンパイル環境なしでexeにする。

Posted at

以前の記事でなんとかExe化までに至ったが、cscでのコンパイルが必要になるのと
特定のpythonコマンドラッパーしか作れないといった点が気に食わなかった。

で今回C++でexeを作るexeを作った。

名前はmkexe.exe

”えぐぜ”だらけで何言ってるのかわけわからん。

今回のはWindowsコマンドプロンプトで実行できるものはexe化できる。

mkexe.exe の引数に覚えさせたいコマンドを渡せば、RenameMe.exeというexeが新しくできるので、
実行すると引数のコマンドを覚えてて、実行してくれる。
要するにこんな感じ、、

Example1.

mkexe.exe "echo foo bar"
.\RenameMe.exe # <-出来上がったファイルを実行
foo bar

Example2.

mkexe.exe "start http://example.com"
.\RenameMe.exe # <-出来上がったファイルを実行
## ⇒デフォルトブラウザが起動し、http://example.comにアクセスする。

Example3.

mkexe.exe "cd C:\temp" "echo hoge > hoge.txt" "notepad.exe hoge.txt"
.\RenameMe.exe # <-出来上がったファイルを実行
## ⇒C:\tempにhoge.txtのファイル名でhogeと書き込み、そのファイルをメモ帳で開く。

わからんが発想はこんな感じ、こんな強引でよいのか?

  • まずシステムコマンドを実行できるプログラムとして、a.exeを作った。

  • a.exeをひな型に、バイナリの中からシステムコマンド文字列部分を、引数入力されたコマンド文字列に
    置き換えて、新しいexeを作る。

  • 文字列を置き換えてるだけなので、コンパイル環境がなくても、、、という感じ

  • mkexe.exe単体で機能する。もちろん出力結果のRenameMe.exeも単体で機能する。

Windows10 64bit 環境でコンパイル済みのmkexe.exeを保存した。

恥ずいソース

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?