0

I am trying to activate a .vbs "WshShell.Popup" via a batch file which contains a line break but I am failing using the following code:

echo set WshShell = WScript.CreateObject("WScript.Shell") > %tmp%\tmp.vbs
echo WScript.Quit (WshShell.Popup("first line here" & Chr(13) & Chr(13) &  "second line here" & Chr(13) & Chr(13) & "third line here" ,20 ,"ALERT! System Compromised!",0+48)) >> %tmp%\tmp.vbs
cscript /nologo %tmp%\tmp.vbs >NUL
del %tmp%\tmp.vbs

Any help would be appreciated, thanks

DaE
  • 189
  • 1
  • 4
  • 14
  • I have a feeling its something to do with the quotation marks and the way its parsing but not sure how to resolve – DaE Mar 28 '14 at 17:18
  • Try `Chr(13) & Chr(10)`. Chr(13) is carriage return, Chr(10) is line-feed. – Dave Mason Mar 28 '14 at 17:20
  • Thanks but no luck. When I look at the temp .vbs file (tmp.vbs) the only line of code in there is: set WshShell = WScript.CreateObject("WScript.Shell") – DaE Mar 28 '14 at 17:48
  • 1
    You need to escape the `&` characters this way: `("first line here" ^& Chr(13) ^& Chr(10) ^& ...` – Aacini Mar 29 '14 at 08:37
  • Escaping the & character worked. Thank you for your help – DaE Mar 31 '14 at 22:31

2 Answers2

1

Just use a VBScript/Batch file hybrid. More details on that -> Here

wscriptpopup.bat

::' VBS/Batch Hybrid
::' --- Batch portion ---------
rem^ &@echo off
rem^ &call :'sub
rem^ &exit /b

:'sub
rem^ &echo begin batch
rem^ &cscript //nologo //e:vbscript "%~f0"
rem^ &echo end batch
rem^ &exit /b

'----- VBS portion -----
Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Quit (WshShell.Popup("first line here" & vbcrlf &  "second line here" & vbcrlf & "third line here" ,20 ,"ALERT! System Compromised!",0+48))
'wscript.quit(0)
Community
  • 1
  • 1
Rich
  • 4,134
  • 3
  • 26
  • 45
  • Thanks for this. Is there anyway I can do it without having a separate batch file. Ideally I would like to run only one batch file. – DaE Mar 28 '14 at 18:00
  • Just copy and paste the code into your batch file where ever you need it to execute and your good to go, it doesn't need to be independent. That's why there is the "begin batch" "end batch", etc. it's built for being expanded into. – Rich Mar 28 '14 at 18:02
1

You may also use a Batch-JScript hybrid script that allows a somewhat simpler solution than VBS:

@if (@CodeSection == @Batch) @then

@echo off
echo Calling the popup:
cscript //nologo //e:jscript "%~f0"
exit /b

@end

// JScript section

var WshShell = WScript.CreateObject("WScript.Shell"), crlf = String.fromCharCode(13,10)
WScript.Quit (WshShell.Popup("first line here" + crlf + "second line here" + crlf + "third line here" ,20 ,"ALERT! System Compromised!",0+48))

In this case the Batch section don't needs any additional characters; just insert an @end line to separate Batch and JScript sections. If the VBS section is small, its translation to JScript is almost immediate, as you can see.

Aacini
  • 65,180
  • 12
  • 72
  • 108