presents by IT Consulting 109

LogOn、LogOffのログ取得

概要

Windowsへのログオン(ログオフ)時に、ログオンアカウントとホスト名を取得して出力するスクリプトについて記載しています。
Windows CALの適切な管理等に役立つツールです。

 

手順

1.次のスクリプトを作成します。

■[LogOn.vbs] ログイン時の取得用スクリプト

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objFile = objFso.OpenTextFile("D:\LogOnOff\Logon.log", 8, True) '出力先のファイルパスを指定します

If Err.Number > 0 Then
  WScript.Echo "Open Error"
Else
  objFile.WriteLine "[LOGON ] " & Date & " " & Time & " " & objShell.ExpandEnvironmentStrings("%USERDOMAIN%\%USERNAME%") & " " & objShell.ExpandEnvironmentStrings("%CLIENTNAME%")
End If

objFile.Close
Set objFile = Nothing
Set objFso = Nothing
Set objShell = Nothing

■[LogOff.vbs] ログオフ時の取得スクリプト

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objFile = objFso.OpenTextFile("D:\LogOnOff\Logon.log", 8, True) '出力先ファイルパスを指定します

If Err.Number > 0 Then
  WScript.Echo "Open Error"
Else
  objFile.WriteLine "[LOGOFF] " & Date & " " & Time & " " & objShell.ExpandEnvironmentStrings("%USERDOMAIN%\%USERNAME%")
End If

objFile.Close
Set objFile = Nothing
Set objFso = Nothing
Set objShell = Nothing

 

ログオン、ログオフ時に実行されるように、グループポリシーにスクリプトを設定します。

 

2.ローカルグループポリシーを起動します。

[ gpedit.msc ] を起動します。

 

3.スクリプト構成を表示します。

[ ローカルコンピューターポリシー ] > [ ユーザー構成 ] > [ Windowsの設定 ] > [ スクリプト(ログオン/ログオフ) ]を表示します。

 

4.スクリプトを設定します。
作成したスクリプトをそれぞれに追加します。

 

5.確認
再起動を実行してログに出力されていることを確認します。

この記事を書いた人
名前:TRUE's。 千葉県育ち、神奈川県在住のIT系フリーエンジニア。 IT系のナレッジサイトを不定期で更新中。 フォトグラファー兼エンジニアとして日々勤しんでいる。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny