Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'VbsMsg v1.0.1. https://pastebin.com/u/jcunews
- '
- 'Simple file based LAN messaging alternative for msg.exe.
- '
- 'This script requires that all participating computers have shared documents
- 'enabled and are using this script.
- '
- 'Usage: VbsMsg [/n:{x}] [/stop] [message]
- '
- '/n:{x} Specify destination computer name or IP address to send message to.
- '/stop Stop the message monitor.
- 'message Message to send.
- '
- 'When sending a message if either computer name or message is not specified,
- 'the user will be prompted to input the missing information.
- '
- 'Unless the "/stop" switch is specified, the message monitor will be run in the
- 'background automatically if needed. If the "/stop" switch is specified when
- 'sending a message, the message monitor will be stopped if it's already running.
- '
- 'Run "net view" to get a list of computer names in the network.
- '
- 'It is recommended to use WSCRIPT to run the script if it's started to run the
- 'message monitor, so that no console window will be shown.
- set ev = createobject("wscript.shell").environment("PROCESS")
- set fs = createobject("scripting.filesystemobject")
- close = wscript.arguments.named.exists("stop")
- computer = wscript.arguments.named("n")
- if wscript.arguments.unnamed.length > 0 then
- msg = wscript.arguments.unnamed(0)
- else
- msg = ""
- end if
- if not ((computer = "") and (msg = "")) then
- if computer = "" then
- wscript.stdout.write _
- "Enter a computer name to send message to (leave blank to cancel): "
- computer = trim(wscript.stdin.readline)
- if computer = "" then wscript.quit
- end if
- if msg = "" then
- wscript.stdout.write "Enter message to send (leave blank to cancel): "
- msg = trim(wscript.stdin.readline)
- if msg = "" then wscript.quit
- end if
- end if
- if (computer = "..") or (instr(computer, "\") > 0) then
- wscript.echo "Invalid computer name."
- wscript.quit 1
- end if
- if computer = "." then computer = "localhost"
- dirXP = "C:\\Document and Settings\\All Users\\Documents"
- dirVista = "C:\\Users\\Public\\Documents"
- set lockfile = nothing
- if fs.folderexists(dirVista) then
- dir = dirVista
- elseif fs.folderexists(dirXP) then
- dir = dirXP
- else
- wscript.echo "Can not find shared documents folder."
- wscript.quit 1
- end if
- lockfn = dir & "\vbsmsg.lock"
- stopfn = dir & "\vbsmsg.stop"
- inpfn = dir & "\vbsmsg.msg"
- source = ev("COMPUTERNAME")
- on error resume next
- if msg <> "" then
- outdir = "\\" & computer & "\Users\Public\Documents\"
- if not fs.folderexists(outdir) then
- outdir = "\\" & computer & "\SharedDocuments\"
- end if
- if fs.folderexists(outdir) then
- if not fs.fileexists(outdir & "vbsmsg.lock") then
- wscript.echo "Destination computer is not listening to any message."
- wscript.quit 1
- end if
- set f = fs.opentextfile(outdir & "vbsmsg.msg", 8, true, -1)
- if err.number = 0 then
- f.writeline source & chrw(&Hfffd) & now & chrw(&Hfffd) & msg
- f.close
- else
- wscript.echo "VbsMsg is already in the process of stopping."
- end if
- else
- end if
- end if
- err.clear
- set lockfile = fs.createtextfile(lockfn, true)
- if close then
- if err.number = 0 then
- lockfile.close
- fs.deletefile lockfn
- if msg = "" then
- wscript.echo "VbsMsg is not yet running."
- wscript.quit 1
- end if
- else
- if not fs.fileexists(stopfn) then
- set f = fs.createtextfile(stopfn, true)
- f.close
- do while fs.fileexists(stopfn)
- wscript.sleep 100
- loop
- else
- wscript.echo "VbsMsg is already in the process of stopping."
- end if
- end if
- elseif err.number = 0 then
- do while true
- if fs.fileexists(inpfn) then
- set f = fs.opentextfile(inpfn, 1, false, -1)
- for each s in split(f.readall, vbcrlf)
- if s <> "" then
- z = split(s, chrw(&Hfffd))
- msgbox "Message from " & z(0) & vbcrlf & z(1) & vbcrlf & vbcrlf & _
- z(2), 64, "VbsMsg"
- end if
- next
- f.close
- fs.deletefile inpfn
- end if
- if fs.fileexists(stopfn) then
- fs.deletefile stopfn
- exit do
- end if
- wscript.sleep 100
- loop
- lockfile.close
- fs.deletefile lockfn
- elseif msg = "" then
- wscript.echo "VbsMsg is already running."
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement