12
15

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.

バッチファイルを非表示のまま起動するためのVBScript

Last updated at Posted at 2015-12-17

筆者の備忘録として。
バッチファイルを実行する時に黒いコマンドプロンプト画面を表示しない方法を参考に、より汎用的に使用できるように改造してみた。

VBScript
Option Explicit

Const vbHide = 0 'ウィンドウを非表示

Function ArgsToString()
   Const DELIMITER = " "
   Dim ret
   Dim i
   Dim n

   ret = ""
   n = Wscript.Arguments.Count
   If n > 0 Then
     For i = 1 To n
       If i < n Then
         ret = ret & Wscript.Arguments(i - 1) & DELIMITER
       Else
         ret = ret & Wscript.Arguments(i - 1)
       End If
     Next
   End If
   ArgsToString = ret
End Function

Dim batPath
batPath = Replace(WScript.ScriptFullName,".vbs",".bat")

CreateObject("Wscript.Shell").run "cmd /c " & batPath & " " & ArgsToString(), vbHide

例えば、test.batを起動したい場合、test.batと同じフォルダに、上記内容をtest.vbsとして保存すれば、test.vbsを実行することで、test.batを非表示のまま起動することができる。
また、起動時に引数を渡すことも可能。

12
15
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
12
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?