Script Example: Net Send Replacement [MSG]

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Script Example: Net Send Replacement [MSG]

Post by CyberCitizen » Mon Dec 10, 2012 3:24 am

Hi Guys,

Thought I would post here as I couldn't post in the scripts / tips section.

I work in IT in a hospital and am constantly trying to contact staff / users of a computer to perform work for them. Problem is hospital has poor mobile phone coverage and trying to get them on a desk phone can be a real pain.

I have tried sending emails etc, but they get some many emails it makes it really hard to make contact.

I remember the old Net Send days, although now blocked / disabled since XP SP2. I do remember there is the msg command, although it was really only for terminal services to message individual users, it can be used to message users on an individual machine providing they have the registry key enabled.

Now you still need to have admin access to the remote machine to enable the registry key, in my situation I need to run it with my admin account.

Here is what it looks like: YouTube Video Link
Image

Now I am sure there can be some additional checks added to make it 100% reliable, it was written quickly for my purpose, however now that I think about it, it could be useful for others, so feel free to have a look.

Code: Select all

// COMPILE_OPTS|C:\Temp\MJ\MSGUtility.exe|M:\Icons\e_mail.ico|CONSOLE=0|INCLUDES=1| /HIDE /NOSYSTRAY /LOGFILE=\dev\nul
Let>APP_TITLE=MSG Utility v1.1
Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>RP_ADMIN=1

Dialog>MSGUtility
object MSGUtility: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'MSG Utility'
  ClientHeight = 298
  ClientWidth = 466
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'Courier New'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 16
  object msLabel1: TLabel
    Left = 8
    Top = 48
    Width = 56
    Height = 16
    Caption = 'Message'
    Transparent = True
  end
  object msLabel2: TLabel
    Left = 8
    Top = 216
    Width = 32
    Height = 16
    Caption = 'From'
    Transparent = True
  end
  object msLabel3: TLabel
    Left = 16
    Top = 267
    Width = 248
    Height = 16
    Caption = 'Created By Michael Allen '#169' 2012'
    Transparent = True
  end
  object msLabel5: TLabel
    Left = 8
    Top = 8
    Width = 144
    Height = 16
    Caption = 'Enter Machine Name'
    Transparent = True
  end
  object MachineNumber: TEdit
    Left = 16
    Top = 24
    Width = 433
    Height = 24
    TabOrder = 0
  end
  object Message: tMSMemo
    Left = 16
    Top = 64
    Width = 433
    Height = 145
    ScrollBars = ssVertical
    TabOrder = 1
  end
  object From: TEdit
    Left = 16
    Top = 232
    Width = 433
    Height = 24
    TabOrder = 2
  end
  object msButton1: tMSButton
    Left = 272
    Top = 264
    Width = 91
    Height = 25
    Caption = 'SEND'
    Default = True
    DoubleBuffered = True
    ParentDoubleBuffered = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object msButton2: tMSButton
    Left = 368
    Top = 264
    Width = 83
    Height = 25
    Caption = 'CLOSE'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>MSGUtility

SetDialogProperty>MSGUtility,,Caption,%APP_TITLE%

Label>Start

AddDialogHandler>MSGUtility,msButton2,OnClick,GoEXIT
AddDialogHandler>MSGUtility,msButton1,OnClick,SendMSG
Show>MSGUtility,result

If>result=2,Exit

SRT>SendMSG
GetDialogProperty>MSGUtility,MachineNumber,Text,DNUM
GetDialogProperty>MSGUtility,Message,Text,DMSG
GetDialogProperty>MSGUtility,From,Text,DFROM
  If>{(%DNUM%="") OR (%DMSG%="") OR (%DFROM%="")}
    MessageModal>Please ensure you have completed all the required fields!%CRLF%· Machine%CRLF%· Message%CRLF%· From
  Else
    SetDialogProperty>MSGUtility,msButton1,Caption,PLEASE
    SetDialogProperty>MSGUtility,msButton2,Caption,WAIT
    SetDialogProperty>MSGUtility,msButton1,Enabled,False
    SetDialogProperty>MSGUtility,msButton2,Enabled,False
    
    DeleteFile>%TEMP_DIR%MSGUtility.txt
    WriteLn>%TEMP_DIR%MSGUtility.txt,,%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    
    Let>RP_WAIT=1
    Let>RP_WINDOWMODE=0
    Let>RP_DISPLAYERROR=0
    Run>cmd /c REG ADD "\\%DNUM%\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "AllowRemoteRPC" /t REG_DWORD /D 1 /F > "%TEMP_DIR%AllowRemoteRPC.txt"
    Run>cmd /c MSG /V /TIME:86400 /SERVER:%DNUM% * <"%TEMP_DIR%MSGUtility.txt" >"%TEMP_DIR%MSGResponse.txt"
    Run>cmd /c REG ADD "\\%DNUM%\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "AllowRemoteRPC" /t REG_DWORD /D 0 /F > "%TEMP_DIR%AllowRemoteRPC.txt"
    ReadFile>%TEMP_DIR%MSGResponse.txt,MSGSentResults
    DeleteFile>%TEMP_DIR%MSGUtility.txt
    DeleteFile>%TEMP_DIR%AllowRemoteRPC.txt
    DeleteFile>%TEMP_DIR%MSGResponse.txt
    StringReplace>%MSGSentResults%,86400,24hr's,MSGSentResults
    //MDL>MESSAGE SENT%CRLF%==========================%CRLF%TO: %DNUM%%CRLF%%CRLF%MESSAGE%CRLF%%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    MDL>%MSGSentResults%%CRLF%==========================%CRLF%TO: %DNUM%%CRLF%%CRLF%MESSAGE%CRLF%%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    SetDialogProperty>MSGUtility,msButton1,Caption,SEND
    SetDialogProperty>MSGUtility,msButton2,Caption,CLOSE
    SetDialogProperty>MSGUtility,msButton1,Enabled,True
    SetDialogProperty>MSGUtility,msButton2,Enabled,True
  EndIf
END>SendMSG

SRT>GoEXIT
  CloseDialog>MSGUtility
END>GoEXIT

Label>Exit
Last edited by CyberCitizen on Tue May 28, 2013 3:50 am, edited 1 time in total.
FIREFIGHTER

User avatar
Marcus Tettmar
Site Admin
Posts: 7394
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Dec 12, 2012 4:13 pm

Many thanks for the tip and example code. I have moved your post to Scripts 'n Tips.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Fri Dec 28, 2012 4:12 pm

Very neatly done.

I have made a few edits to this to do it how I like this kind of thing to be done.

It does actually add some extra code but rather than having a message flashing up telling you about the empty fields it will simply not enable the Send button until the fields are filled.

The warning exists in the memo field until the memo field is first clicked.

I am not in any way saying my way is better (in fact it probably isn't), I just though that you may be interested to see an alternative angle on it. :-)

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
// COMPILE_OPTS|C:\Temp\MJ\MSGUtility.exe|M:\Icons\e_mail.ico|CONSOLE=0|INCLUDES=1| /HIDE /NOSYSTRAY /LOGFILE=\dev\nul
Let>APP_TITLE=MSG Utility v1.1
Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>RP_ADMIN=1

Dialog>MSGUtility
object MSGUtility: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'MSG Utility'
  ClientHeight = 298
  ClientWidth = 466
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'Courier New'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 16
  object msLabel1: TLabel
    Left = 8
    Top = 48
    Width = 56
    Height = 16
    Caption = 'Message'
    Transparent = True
  end
  object msLabel2: TLabel
    Left = 8
    Top = 216
    Width = 32
    Height = 16
    Caption = 'From'
    Transparent = True
  end
  object msLabel3: TLabel
    Left = 16
    Top = 267
    Width = 248
    Height = 16
    Caption = 'Created By Michael Allen '#169' 2012'
    Transparent = True
  end
  object msLabel5: TLabel
    Left = 8
    Top = 8
    Width = 144
    Height = 16
    Caption = 'Enter Machine Name'
    Transparent = True
  end
  object MachineNumber: TEdit
    Left = 16
    Top = 24
    Width = 433
    Height = 24
    TabOrder = 0
  end
  object Message: tMSMemo
    Left = 16
    Top = 64
    Width = 433
    Height = 145
    ScrollBars = ssVertical
    TabOrder = 1
  end
  object From: TEdit
    Left = 16
    Top = 232
    Width = 433
    Height = 24
    TabOrder = 2
  end
  object msButton1: tMSButton
    Left = 272
    Top = 264
    Width = 91
    Height = 25
    Caption = 'SEND'
    Default = True
    DoubleBuffered = True
    ParentDoubleBuffered = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object msButton2: tMSButton
    Left = 368
    Top = 264
    Width = 83
    Height = 25
    Caption = 'CLOSE'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>MSGUtility

SetDialogProperty>MSGUtility,,Caption,%APP_TITLE%

//NEW//
Let>SeenIt=0
SetDialogProperty>MSGUtility,msButton1,Enabled,False
SetDialogProperty>MSGUtility,Message,Text,Please ensure you have completed all the required fields!%CRLF%· Machine Name%CRLF%· Message%CRLF%· From
//NEW//

Label>Start

AddDialogHandler>,msButton2,OnClick,GoEXIT
AddDialogHandler>MSGUtility,msButton1,OnClick,SendMSG

//NEW//
AddDialogHandler>MSGUtility,MachineNumber,OnChange,Active
AddDialogHandler>MSGUtility,Message,OnChange,Active
AddDialogHandler>MSGUtility,From,OnChange,Active
AddDialogHandler>MSGUtility,Message,OnEnter,Remove
//NEW//

Show>MSGUtility,result

If>result=2,Exit

SetDialogProperty>MSGUtility,,Caption,%APP_TITLE%

//NEW//
SRT>Remove
  If>SeenIt=0
    SetDialogProperty>MSGUtility,Message,Text,
    Let>SeenIt=1
  ENDIF
END>Remove

SRT>Active
  GetDialogProperty>MSGUtility,MachineNumber,Text,DNUM
  GetDialogProperty>MSGUtility,Message,Text,DMSG
  GetDialogProperty>MSGUtility,From,Text,DFROM
  If>{(%DNUM%="") OR (%DMSG%="") OR (%DFROM%="")}
    SetDialogProperty>MSGUtility,msButton1,Enabled,False
  ELSE
    SetDialogProperty>MSGUtility,msButton1,Enabled,True
  ENDIF
END>Active
//NEW//

SRT>SendMSG
    SetDialogProperty>MSGUtility,msButton1,Caption,PLEASE
    SetDialogProperty>MSGUtility,msButton2,Caption,WAIT
    SetDialogProperty>MSGUtility,msButton1,Enabled,False
    SetDialogProperty>MSGUtility,msButton2,Enabled,False
    
    DeleteFile>%TEMP_DIR%MSGUtility.txt
    WriteLn>%TEMP_DIR%MSGUtility.txt,,%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    
    Let>RP_WAIT=1
    Let>RP_WINDOWMODE=0
    Let>RP_DISPLAYERROR=0
    Run>cmd /c REG ADD "\\%DNUM%\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "AllowRemoteRPC" /t REG_DWORD /D 1 /F > "%TEMP_DIR%AllowRemoteRPC.txt"
    Run>cmd /c MSG /V /TIME:86400 /SERVER:%DNUM% * <"%TEMP_DIR%MSGUtility.txt" >"%TEMP_DIR%MSGResponse.txt"
    Run>cmd /c REG ADD "\\%DNUM%\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "AllowRemoteRPC" /t REG_DWORD /D 0 /F > "%TEMP_DIR%AllowRemoteRPC.txt"
    ReadFile>%TEMP_DIR%MSGResponse.txt,MSGSentResults
    DeleteFile>%TEMP_DIR%MSGUtility.txt
    DeleteFile>%TEMP_DIR%AllowRemoteRPC.txt
    DeleteFile>%TEMP_DIR%MSGResponse.txt
    StringReplace>%MSGSentResults%,86400,24hr's,MSGSentResults
    //MDL>MESSAGE SENT%CRLF%==========================%CRLF%TO: %DNUM%%CRLF%%CRLF%MESSAGE%CRLF%%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    MDL>%MSGSentResults%%CRLF%==========================%CRLF%TO: %DNUM%%CRLF%%CRLF%MESSAGE%CRLF%%DMSG%%CRLF%--%CRLF%From: %DFROM% - %USER_NAME%
    SetDialogProperty>MSGUtility,msButton1,Caption,SEND
    SetDialogProperty>MSGUtility,msButton2,Caption,CLOSE
    SetDialogProperty>MSGUtility,msButton1,Enabled,True
    SetDialogProperty>MSGUtility,msButton2,Enabled,True
END>SendMSG

SRT>GoEXIT
  CloseDialog>MSGUtility
END>GoEXIT

Label>Exit
Phil Pendlebury - Linktree

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Sat Dec 29, 2012 12:53 am

Thanks Phil,

I like that idea, will have a play when I get back to work. Thanks for the suggestion.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts