Skip to content Skip to sidebar Skip to footer

Unterminated String Constant-mshta:javascript

Recently I was trying to get a quick alert box from javascript using mshta but I noticed something strange and I have no ideea what the problem is. This is,in a way,what I was tryi

Solution 1:

I'll start off with the version of the command that I got to work, and I'll explain why it works:

mshta "javascript:alert('The file was stored here:\x22C:\\folder_with_space_ _.txt');"

The first and perhaps most important point is that we are passing a single argument to mshta.exe (the JavaScript command to execute), so we should surround that entire argument in double quotes. This prevents the space from being treated as an argument delimiter.

The second point is that there doesn't seem to be a way to have double quotes inside the actual JavaScript commands. According to the question Escaping Double Quotes in Batch Script, there is no standard for escaping double quotes inside double quotes for cmd. Apparently, mshta.exe doesn't honor "" or \" (or at least, I couldn't get them to work). I suggest following Teemu's suggestion in the comments and use single quotes only for string delimiter in the JavaScript code. If, inside a string, you want to include a double quote character, use the hex literal \x22.


Post a Comment for "Unterminated String Constant-mshta:javascript"