Advertisement
jcunews

VbsMsg.vbs

Oct 7th, 2019 (edited)
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'VbsMsg v1.0.1. https://pastebin.com/u/jcunews
  2. '
  3. 'Simple file based LAN messaging alternative for msg.exe.
  4. '
  5. 'This script requires that all participating computers have shared documents
  6. 'enabled and are using this script.
  7. '
  8. 'Usage: VbsMsg [/n:{x}] [/stop] [message]
  9. '
  10. '/n:{x}   Specify destination computer name or IP address to send message to.
  11. '/stop    Stop the message monitor.
  12. 'message  Message to send.
  13. '
  14. 'When sending a message if either computer name or message is not specified,
  15. 'the user will be prompted to input the missing information.
  16. '
  17. 'Unless the "/stop" switch is specified, the message monitor will be run in the
  18. 'background automatically if needed. If the "/stop" switch is specified when
  19. 'sending a message, the message monitor will be stopped if it's already running.
  20. '
  21. 'Run "net view" to get a list of computer names in the network.
  22. '
  23. 'It is recommended to use WSCRIPT to run the script if it's started to run the
  24. 'message monitor, so that no console window will be shown.
  25.  
  26. set ev = createobject("wscript.shell").environment("PROCESS")
  27. set fs = createobject("scripting.filesystemobject")
  28. close = wscript.arguments.named.exists("stop")
  29. computer = wscript.arguments.named("n")
  30. if wscript.arguments.unnamed.length > 0 then
  31.   msg = wscript.arguments.unnamed(0)
  32. else
  33.   msg = ""
  34. end if
  35. if not ((computer = "") and (msg = "")) then
  36.   if computer = "" then
  37.     wscript.stdout.write _
  38.       "Enter a computer name to send message to (leave blank to cancel): "
  39.     computer = trim(wscript.stdin.readline)
  40.     if computer = "" then wscript.quit
  41.   end if
  42.   if msg = "" then
  43.     wscript.stdout.write "Enter message to send (leave blank to cancel): "
  44.     msg = trim(wscript.stdin.readline)
  45.     if msg = "" then wscript.quit
  46.   end if
  47. end if
  48. if (computer = "..") or (instr(computer, "\") > 0) then
  49.   wscript.echo "Invalid computer name."
  50.   wscript.quit 1
  51. end if
  52. if computer = "." then computer = "localhost"
  53. dirXP = "C:\\Document and Settings\\All Users\\Documents"
  54. dirVista = "C:\\Users\\Public\\Documents"
  55. set lockfile = nothing
  56. if fs.folderexists(dirVista) then
  57.   dir = dirVista
  58. elseif fs.folderexists(dirXP) then
  59.   dir = dirXP
  60. else
  61.   wscript.echo "Can not find shared documents folder."
  62.   wscript.quit 1
  63. end if
  64. lockfn = dir & "\vbsmsg.lock"
  65. stopfn = dir & "\vbsmsg.stop"
  66. inpfn = dir & "\vbsmsg.msg"
  67. source = ev("COMPUTERNAME")
  68. on error resume next
  69. if msg <> "" then
  70.   outdir = "\\" & computer & "\Users\Public\Documents\"
  71.   if not fs.folderexists(outdir) then
  72.     outdir = "\\" & computer & "\SharedDocuments\"
  73.   end if
  74.   if fs.folderexists(outdir) then
  75.     if not fs.fileexists(outdir & "vbsmsg.lock") then
  76.       wscript.echo "Destination computer is not listening to any message."
  77.       wscript.quit 1
  78.     end if
  79.     set f = fs.opentextfile(outdir & "vbsmsg.msg", 8, true, -1)
  80.     if err.number = 0 then
  81.       f.writeline source & chrw(&Hfffd) & now & chrw(&Hfffd) & msg
  82.       f.close
  83.     else
  84.       wscript.echo "VbsMsg is already in the process of stopping."
  85.     end if
  86.   else
  87.   end if
  88. end if
  89. err.clear
  90. set lockfile = fs.createtextfile(lockfn, true)
  91. if close then
  92.   if err.number = 0 then
  93.     lockfile.close
  94.     fs.deletefile lockfn
  95.     if msg = "" then
  96.       wscript.echo "VbsMsg is not yet running."
  97.       wscript.quit 1
  98.     end if
  99.   else
  100.     if not fs.fileexists(stopfn) then
  101.       set f = fs.createtextfile(stopfn, true)
  102.       f.close
  103.       do while fs.fileexists(stopfn)
  104.         wscript.sleep 100
  105.       loop
  106.     else
  107.       wscript.echo "VbsMsg is already in the process of stopping."
  108.     end if
  109.   end if
  110. elseif err.number = 0 then
  111.   do while true
  112.     if fs.fileexists(inpfn) then
  113.       set f = fs.opentextfile(inpfn, 1, false, -1)
  114.       for each s in split(f.readall, vbcrlf)
  115.         if s <> "" then
  116.           z = split(s, chrw(&Hfffd))
  117.           msgbox "Message from " & z(0) & vbcrlf & z(1) & vbcrlf & vbcrlf & _
  118.             z(2), 64, "VbsMsg"
  119.         end if
  120.       next
  121.       f.close
  122.       fs.deletefile inpfn
  123.     end if
  124.     if fs.fileexists(stopfn) then
  125.       fs.deletefile stopfn
  126.       exit do
  127.     end if
  128.     wscript.sleep 100
  129.   loop
  130.   lockfile.close
  131.   fs.deletefile lockfn
  132. elseif msg = "" then
  133.   wscript.echo "VbsMsg is already running."
  134. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement