Here's a script I use for sending  NET SEND to specific OU's in my domain.
First it asks "What is the messsage"..
then it will query the computers in the OU (see line
"/OU=IT,OU=CIRHC Computers,OU=SNHD Computers,DC=DOMAIN,DC=COM" _
)

What it does in a nutshell is first look at the status of the service "Messenger"
Whatever its state, (Auto, Manual or Disabled) it will "Auto" it, send the NET SEND, then change it back to its original state.

There is one (at least one) glaring weakness that maybe someone can fix and resubmit.
 It does this one at a time, across a big domain will take time, if you can send this to more than one at a time (asyncronous?) it will be much faster.
This also assumes your XP SP2 firewall is off I believe.

If it works for you, great, if not, well I tried.
Doug



dim namsrv,rnmd,strt,strComputer
'On Error Resume Next
dim messg : messg = inputbox("What is the message?")
Const ADS_SCOPE_SUBTREE = 2
Const ADS_CHASE_REFERRALS_SUBORDINATE = &H20

Set objRootDSE = GetObject("LDAP://RootDSE")

Set objDomain = GetObject("LDAP://rootDse")

objDC = objDomain.Get("dnsHostName")
'Wscript.Echo "Authenticating domain controller:" & objDC
strRootDomain = objRootDSE.Get("rootDomainNamingContext")
' Use ADO to search Active Directory for all computers.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open = "Active Directory Provider"
objCommand.ActiveConnection = objConnection
' Retrieve attributes.
strAttributes = "sAMAccountName,distinguishedName, operatingSystem"
strQuery = "<LDAP://" & objDC & _
        "/OU=IT,OU=CIRHC Computers,OU=SNHD Computers,DC=DOMAIN,DC=COM" _
  & ">;(ObjectCategory=computer);" & strAttributes & ";subtree"
  'msgbox strQuery
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Chase Referrals") = _
  ADS_CHASE_REFERRALS_SUBORDINATE

Set objRecordSet = objCommand.Execute
  objRecordSet.MoveFirst
Do Until objRecordSet.EOF

  strComputer = objRecordSet.Fields("sAMAccountName")
  ' Remove trailing "$".
  strComputer = Left(strComputer, Len(strComputer) - 1)
'msgbox strComputer
Set WshShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
           
getval(strComputer)
dim finalmode : finalmode = strt
dim finalrnmd : finalrnmd = rnmd
if strt <> "Auto" then
        manserv(strComputer)
        if rnmd <> "Running" then strtmode(strComputer)
end if  

WshShell.Run ("net send " & strComputer & " " & messg )
call endmode(strComputer,finalmode,finalrnmd)

    objRecordSet.MoveNext
Loop
Msgbox "Done"
           
           
sub getval(strComputer)
        Set colRunningServices = objWMIService.ExecQuery _
            ("Select * from Win32_Service")
        For Each objService in colRunningServices
                if objService.DisplayName = "Messenger" then
                        strt = objService.StartMode
                        rnmd = objService.State
                        namsrv = objService.DisplayName
                end if
        next
end sub

sub manserv(strComputer)
        Set colRunningServices = objWMIService.ExecQuery _
            ("Select * from Win32_Service")
For Each objService in colRunningServices
        if objService.DisplayName = "Messenger" then
        dim bob: bob = 0
        errReturnCode = objService.Change( , , , , "Automatic")
        do until bob = 1
                getval(strComputer)
                if strt = "Auto" then
                        bob = 1
                end if
        loop
        end if
next
end sub

sub strtmode(strComputer)
        Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='Messenger'")
        For each objService in colServiceList
            errReturn = objService.StartService()
                    bob = 0
            do until bob = 1
                        getval(strComputer)
                        if rnmd = "Running" then
                                bob = 1
                        end if
                loop
        next
end sub

sub stopmode(strComputer)
        Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='Messenger'")
For each objService in colServiceList
        errReturn = objService.StopService()
        bob = 0
        do until bob = 1
                getval(strComputer)
                if rnmd = "Stopped" then
                        bob = 1
                end if
        loop
        bob = 0
        errReturnCode = objService.Change( , , , , "Disabled")
        do until bob = 1
                getval(strComputer)
                if strt = "Disabled" then
                        bob = 1
                end if
        loop
next
end sub

sub manualmode(strComputer)
        Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='Messenger'")
For each objService in colServiceList
        errReturn = objService.StopService()
        bob = 0
        do until bob = 1
                getval(strComputer)
                if rnmd = "Stopped" then
                        bob = 1
                end if
        loop
        bob = 0
        errReturnCode = objService.Change( , , , , "Manual")
        do until bob = 1
                getval(strComputer)
                if strt = "Manual" then
                        bob = 1
                end if
        loop
next
end sub
function endmode(strComputer,finalmode,finalrnmd)
'msgbox strComputer & vbcrlf & finalmode & vbcrlf & finalrnmd
Set colServiceList = objWMIService.ExecQuery _
            ("Select * from Win32_Service where Name='Messenger'")
            if finalmode = "Disabled" then
                        For each objService in colServiceList
                                errReturn = objService.StopService()
                                bob = 0
                                do until bob = 1
                                        getval(strComputer)
                                        if rnmd = "Stopped" then
                                                bob = 1
                                        end if
                                        loop
                                                bob = 0
                                                errReturnCode = objService.Change( , , , , "Disabled")
                                        do until bob = 1
                                                getval(strComputer)
                                        if strt = "Disabled" then
                                                bob = 1
                                        end if
                                loop
                        next
                end if
            if finalmode = "Manual" then
            For each objService in colServiceList
                        bob = 0
                        errReturnCode = objService.Change( , , , , "Manual")
                        do until bob = 1
                                getval(strComputer)
                                if strt = "Manual" then
                                bob = 1
                                end if
                        loop
            next
            end if
               
end function





z <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]

04/25/2006 05:24 AM

Please respond to
ActiveDir@mail.activedir.org

To
ActiveDir@mail.activedir.org
cc
Subject
[ActiveDir] Notification system





Hi all!
Can anybody hepl me, I need to find some soft that could allow me to
notify my domain's users ... Smth like NET SEND, but it should have a
"client-server" architecture
List info   : http://www.activedir.org/List.aspx
List FAQ    : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/

Reply via email to