Share via


WMI 用の Active Server ページの作成

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

以下の手順では、WMI を ASP で使用する方法を説明します。

WMI を ASP で使用するには

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

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

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

  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>