Wednesday, January 2, 2013

NET SEND Replacement using msg.exe

Some our employees utilized the old Netware 'SEND' command to provide instant alerts to others in their office.  They used this is a quick "I NEED HELP ASAP !!!" Button. As we transition to Windows 7,  this no longer works, as well as Microsoft no longer supports the NET SEND command either.  Their are paid alternatives you can buy, but a little utility called MSG.EXE, which is designed to send Terminal Server messages to others mostly on the same workstation/server can be used.

Credit goes to Pedro Lima for most of the script (pedrofln.blogspot.com/).  I changed it up a little to send custom messages by way of command line argument and also send originator info (full name) of the message information and added a 15min display time.  This is so the same script can be used for multiple messages, multiple people, and multiple office locations for deployment in SCCM.

I thought this requires local administrator permissions on the destination workstation,  but in my testing it works without it,  ymmv...

oh and one more thing, this registry key must be present for this to work:  (Copy this into a reg file)


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server]
"AllowRemoteRPC"=dword:00000001


__________________________________________________________

' alert.vbs

' Script to send messages to network computers, like ancient net send

' Version 1.1a

' Version Release Date : 12/20/2012 (org 8/26/2011)

' Version Improvements : Script processing does not show various command prompt windows

' and progress messages are shown during processing, with no CPU stress.

' Edit: added command line arguments for custom messages, and user origination information

' By Pedro Lima (pedrofln.blogspot.com) (edited by Corey Sines 12-20-2012)

' ------------------------------------------------------------




If WScript.Arguments.count = empty Then

Call Usage()

Else

If WScript.Arguments.Count <> 1 Then

Call Usage()

End If

End If




On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Dim objShell, objSA, objArquivoTexto, objProcessEnv

Dim strContent, strCommand, strComputers, strMessage, strComputerss, strCall

Dim intCounter, intLines, intResponse

Dim objArgs, wshShell, userID, fullName




Set objShell = CreateObject("WScript.Shell")

Set objProcessEnv = objShell.Environment("Process")




Set objArgs = WScript.Arguments







userID = Ucase(objShell.ExpandEnvironmentStrings("%USERNAME%"))

fullName = Ucase(objShell.ExpandEnvironmentStrings("%FULLNAME%"))

strMessage = objArgs.Item(0)




strComputers = "computerlist.txt"




If instr(strComputers,":") then ' File above is not in the same folder as the script being called.

'Useful if you want to have a common network location to share a common list of Computers for an

' office, or organization.



' Routine to read a file containing a list of computers

Set objSA = CreateObject("Scripting.FileSystemObject")

Const ForReading = 1

intLines = 0

Set objArquivoTexto = objSA.OpenTextFile(strComputers, ForReading)

If Err.Number <> 0 then

Wscript.echo "The file specified does not exist. Try again with a correct path to the file. Exiting."

Wscript.Quit

End If

strContent = ObjArquivoTexto.ReadAll

intLines = Conta(strContent, chr(13), false)

Redim strComputerss(intLines+1)



For intCounter = 1 to intLines

strCall = GetLine(strContent, intCounter)

strComputerss(intCounter) = strCall

Set objShell = WScript.CreateObject( "WScript.Shell" )

strCommand = objShell.Run("cmd /c msg * /time:900 /server:" & strComputerss(intCounter) & " " & chr(34) & fullName & " says: " & strMessage & chr(34),0,True)

Set objShell = Nothing

Next

Wscript.Quit

End If




wscript.quit




'----------------------------------------------------------------------------------------------------------------

' Functions

'----------------------------------------------------------------------------------------------------------------




Function GetLine(strbuffer, Line)




Dim intEnd, strData, StrLine, IntLine




StrLine = StrBuffer

intEnd = InStr(strLine, Chr(13)) ' Get the initial position of ASCII 13 code (ENTER)

IntLine = 0

Do

IntLine = IntLine + 1

If intEnd > 0 Then

If IntLine = Line Then

strLine = Left(strLine, intEnd-1)

intEnd = InStr(strLine, Chr(13))

Else

StrLine = Mid(StrLine,IntEnd+2)

intEnd = InStr(strLine, Chr(13))

End If

Else

strLine = strLine

End If

Loop While IntLine < Line




GetLine = strLine




End Function




'--------------------------------------------------------------------------------------------------------------------




Function Conta(strText, strFind, fCaseSensitive)

Dim intCount, intPos, intMode



If Len(strFind) > 0 Then

' Configures the comparison mode.

If fCaseSensitive Then

intMode = vbBinaryCompare

Else

intMode = vbTextCompare

End If

intPos = 1

Do

intPos = InStr(intPos, strText, strFind, intMode)

If intPos > 0 Then

intCount = intCount + 1

intPos = intPos + Len(strFind)

End If

Loop While intPos > 0

Else

intCount = 0

End If

Conta = intCount+1

End Function

'-------------------------------------------------------------------------------------------------

Sub Usage()

WScript.Echo "Usage:" & vbNewLine &_

"wscript alert.vbs " & chr(34) & "message" & chr(34) & vbNewLine &_

"Note: Quotes are only necessary if there are spaces."

WScript.Echo "Example:" & vbNewLine &_

"wscript alert.vbs " & chr(34) & " Help there is someone threatening at my desk!" & chr(34)





WScript.Quit(0)

End Sub

1 comment:

  1. Free tool LanSend http://lizardsystems.com/lansend/ is replacement for msg.exe.

    ReplyDelete