WMI 用の Active Server ページの作成

Microsoft Active Server Pages (ASP) では、サーバー側スクリプトとクライアント側スクリプトの両方を含めることで、動的な Web ページを作成できます。 ASP ページは、ほとんどの作業がサーバーで行われるため、クライアント HTML ページよりもはるかに高速になる可能性があります。 ASP ページを使用して、Windows Management Instrumentation (WMI) がインストールされていない他のコンピューターにリモート コンピューターに関する情報を表示することもできます。

次の手順では、ASP で WMI を使用する方法について説明します。

ASP で WMI を使用するには

  1. WMI を使用する ASP ページ (.asp) を作成し、Web サーバーからアクセスできるディレクトリに配置します。

    WMI 用の ASP スクリプトは、VBScript を含む複数のスクリプト言語で開発できます。 WMI を使用する他のスクリプトを作成する場合と同じように、ASP ページの WMI スクリプト部分を作成できます。1 つの重要な制限があります。ASP ページ内で非同期 WMI メソッドを使用することはできません。 また、GetObject または CreateObject への呼び出しは、サーバー側のコードに含まれている必要があることにも注意してください。 詳細については、「WMI用スクリプト API」を参照してください。

  2. インターネット インフォメーション サービス (IIS) の認証構成を設定します。 詳細については、「WMI ASP スクリプト用の IIS 5 以降の構成」を参照してください。

  3. 匿名アクセスを無効にし、ASP ファイルの Windows 統合認証を有効にします。 ASP ページに対してこれらの設定を構成するには、コントロール パネル管理ツール フォルダーにある IIS スナップインを使用します。

WMI ASP ページの例

次の例では、Active Server ページ (ASP) 内の Windows Management Instrumentation (WMI) を使用して、このスクリプトの実行元サーバーの IP アドレスと既定の IP ゲートウェイ設定を表示します。

<%@ LANGUAGE="VBSCRIPT"%>
<HTML>
<HEAD>
<TITLE>WMI ASP Example:
    Read Default Gateway and IP Address information </TITLE>
</HEAD>

<BODY>

<%
On Error Resume Next
set IPConfigSet = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!root\cimv2").ExecQuery" _
    & "("SELECT IPAddress, DefaultIPGateway "" _ 
    & " FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
%>

<%If Err <> 0 Then %>
    <%if err.number = -2147217405 then%>
        <p>Error 0x80041003: Access Denied: 
           Check permissions and file security for this ASP file.</p>
    <%else%>
        <p>Error description: <%=Err.description%> 
           error number <%=Err.number%></p>
    <%end if%>

<%end if %>

<%for each IPConfig in IPConfigSet%>

    <%if Not IsNull(IPConfig.IPAddress) then %>
        <%for i=LBound(IPConfig.IPAddress) 
            to UBound(IPConfig.IPAddress)%>
            <p>IP Address: <%=IPConfig.IPAddress(i)%></p>
        <%next%>
    <%end if%>
    

    <%if Not IsNull(IPConfig.DefaultIPGateway) then %>
        <%for i=LBound(IPConfig.DefaultIPGateway) 
            to UBound(IPConfig.DefaultIPGateway)%>
            <p>Default IP Gateway: 
                <%=IPConfig.DefaultIPGateway(i)%></p>
        <%next%>
    <%end if%>
<%next%>

<%If Err <> 0 Then %>
    <p>error description: <%=Err.description%> 
       error number <%=Err.number%></p>
<%end if %>

</BODY>
</HTML>