1
1

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.

WScriptで色々取得してみる

Posted at

WScriptで色々な情報を取得して処理に使いたいことはよくある。どんな情報を取得できるか、試してみた。

test.js
var shell, network, special_folders, i;

network = new ActiveXObject("WScript.Network");
shell = new ActiveXObject("WScript.Shell");
special_folders = [
    "AllUsersDesktop",
    "AllUsersStartMenu",
    "AllUsersPrograms",
    "AllUsersStartup",
    "Desktop",
    "AppData",
    "PrintHood",
    "Templates",
    "Fonts",
    "NetHood",
    "Desktop",
    "StartMenu",
    "SendTo",
    "Recent",
    "Startup",
    "Favorites",
    "MyDocuments",
    "Programs"
];

WScript.echo("【ComputerName】");
WScript.echo(network.ComputerName);
WScript.echo();

WScript.echo("【UserDomain】");
WScript.echo(network.UserDomain);
WScript.echo();

WScript.echo("【UserName】");
WScript.echo(network.UserName);
WScript.echo();

WScript.echo("【CurrentDirectory】");
WScript.echo(shell.CurrentDirectory);
WScript.echo();

WScript.echo("~以下特殊フォルダ~");
WScript.echo();

for (i = 0; i < special_folders.length; i = i + 1) {
    WScript.echo("" + special_folders[i] + "");
    WScript.echo(shell.SpecialFolders(special_folders[i]));
    WScript.echo();
};

実行結果

cmd
C:\>cscript test.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

【ComputerName】
XXXX

【UserDomain】
YYYY

【UserName】
ZZZZ

【CurrentDirectory】
C:\

~以下特殊フォルダ~

【AllUsersDesktop】
C:\Users\Public\Desktop

【AllUsersStartMenu】
C:\ProgramData\Microsoft\Windows\Start Menu

【AllUsersPrograms】
C:\ProgramData\Microsoft\Windows\Start Menu\Programs

【AllUsersStartup】
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

【Desktop】
C:\Users\xxxx\Desktop

【AppData】
C:\Users\xxxx\AppData\Roaming

【PrintHood】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Printer Shortcuts

【Templates】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Templates

【Fonts】
C:\Windows\Fonts

【NetHood】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Network Shortcuts

【Desktop】
C:\Users\xxxx\Desktop

【StartMenu】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Start Menu

【SendTo】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\SendTo

【Recent】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Recent

【Startup】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

【Favorites】
C:\Users\xxxx\Favorites

【MyDocuments】
C:\Users\xxxx\Documents

【Programs】
C:\Users\xxxx\AppData\Roaming\Microsoft\Windows\Start Menu\Programs


C:\>

結構色々取得できそう。因みに今回は実験しませんが、環境変数や、レジストリにもアクセスできるようです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?