'***************************************
'* Define Variables for script *
'***************************************
Dim objRootLDAP
Dim strDNSDomain
Dim strArray()
Dim n
Dim objNet
'***************************************
'* Get local Domain Info *
'* Do Not Crash if there is no Domain *
'***************************************
On Error resume Next
if err.number = 0 Then
Set objNet = CreateObject("ADSystemInfo")
n = objNet.DomainShortName
end if
'***************************************
'* Function to Check local admins *
'***************************************
function memberOf(groupname)
On Error goto 0
On Error Resume Next
set oUser = GetObject("WinNT://127.0.0.1/" & varUserName & ",user")
' Enumerate Groups for the Use
If err.number = 0 Then
for each oGroup in oUser.Groups
if ucase(oGroup.Name) = ucase(groupName) then
memberOf = true
exit for
end if
next
Else
memberof = False
end if
set oUser = nothing
set oGroup = nothing
end function
'***************************************
'* Function to Check Domain admins *
'***************************************
function memberOfdomain(groupName)
On Error goto 0
On Error Resume Next
set oUser = GetObject("WinNT://" & n & "/" & varUserName & ",user")
If err.number = 0 Then
for each oGroup in oUser.Groups
if ucase(oGroup.Name) = ucase(groupName) then
memberOfdomain = true
exit for
end if
next
Else
memberofdomain = False
end if
set oUser = nothing
set oGroup = nothing
end function
'***************************************
'* Main Part of Script *
'***************************************
Dim ArgObj, varUserName, strCommand
Set ArgObj = WScript.Arguments
varUserName = ArgObj(0)
if memberOf("Administrators") then
strCommand = "cmd /c opcmsg.exe o=Admin_Logon a=Admin_Logon msg_t=""" & varUserName & " has logged in and is a member of the Local Administrators group. ," & varUsername & ",Local"""
runCommand(strCommand)
End If
if memberOfdomain("Domain Admins") then
strCommand = "cmd /c opcmsg.exe o=Admin_Logon a=Admin_Logon msg_t=""" & varUserName & " has logged in and is a member of the Domain Administrators group. ," & varUsername & ",Domain"""
runCommand(strCommand)
End if
sub runCommand(command)
set StdOut = WScript.StdOut
set objShell = CreateObject("WScript.Shell")
set objScriptExec = objShell.Exec (command)
end sub