6
7

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.

Windows ホスト名から文字を抜きとるバッチ

Posted at

ホスト名で処理を分岐させたい時に使うバッチです。
命名規約としてホスト名に設置場所や種類、何号機などを入れておくと運用バッチが作成し易くなります。

例)
APサーバ ⇒ APS001
DBサーバ ⇒ DBS001
ADサーバ ⇒ ADS001

下記バッチはホスト名を変数に入れ、指定の文字数を抜きだすものになります。
インストール作業のバッチや、定期処理のバッチ等に役に立つと思います。

mojitor.cmd
@echo off

rem ホスト名によって分岐するバッチ

rem ホスト名を変数につめる
set strHost=%COMPUTERNAME%

rem テキストは「&」でつなげましょう
echo "ホスト名は%strHost%です"


rem 先頭から3文字を取る
set strSyurui=%strHost:~0,3%

echo "種類は%strSyurui%です"

pause
6
7
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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?