VBScript でコンピューター名/ユーザー名/IP アドレスを取得 [Windows/ASP/VBScript]
コンピューター名とユーザー名は、環境変数から取得。
IP アドレスを ipconfig.exe の出力から取ってきているのはいまいちな気もするけど、これが一番いいんだろうなぁ。
(下記スクリプトでは、IP アドレスが複数付与されることがあることを考慮してないので注意)
Option Explicit
Dim wsh, env, exe
Dim ipaddress, computername, username
Dim strLine, iColon
Set wsh = WScript.CreateObject("WScript.Shell")
computername = wsh.ExpandEnvironmentStrings("%COMPUTERNAME%")
username = wsh.ExpandEnvironmentStrings("%USERNAME%")
Set exe = wsh.Exec("ipconfig.exe")
Do Until exe.StdOut.AtEndOfStream
strLine = exe.StdOut.ReadLine
If InStr(strLine, "IP Address") <> 0 Then
iColon = Instr(strLine, ":")
ipaddress = Mid(strLine, iColon + 2)
ipaddress = Replace(ipaddress, vbCr, "")
End If
Loop
WScript.Echo computername
WScript.Echo username
WScript.Echo ipaddress
(参考)
http://www.atmarkit.co.jp/fwin2k/operation/wsh05/wsh05_03.html







good job!
by ヤッター! (2008-04-02 15:17)
とても参考になりました。
ありがとうございます!
by (´Д`) (2008-05-12 10:27)
http://slashdot.jp/~patagon/journal/443008
by NO NAME (2011-03-22 21:59)
参考になりました。
有難うございます~
by Neruneru (2012-01-11 14:52)