WSUS に登録されているコンピュータ名をメッセージ ボックスに出力するサンプル コード
Try Dim server As IUpdateServer Dim computers As ComputerTargetCollection server = AdminProxy.GetUpdateServer computers = server.GetComputerTargets For Each computer As IComputerTarget In computers MessageBox.Show(computer.FullDomainName, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) Next Catch ex As Exception MessageBox.Show(ex.ToString, "error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
try - Catch で GC の手続きをするのは王道ですよね。
まず変数を定義し、
server = AdminProxy.GetUpdateServer computers = server.GetComputerTargets
ここで参照先サーバーを指定。このやり方では、ローカルの WSUS サーバーが自動的に指定されます。
computers 変数には、GetComputerTargets によって、server 変数にて参照するサーバーの管理対象コンピュータのコレクションが指定されます。
for each でコレクションに対してループさせ、computer 変数にコンピュータ名をストリーム式に投入。順次 MessageBox にて出力します。
コンピュータの台数が増えるととても人間では処理しきれなくなるので注意。
こんな感じで API いじれます。サンプルコードを見ながら、1 日頑張ってみた成果でした。