5

Normally, after creating an executable as an alternate data stream, for instance:

type exec_this.bat > C:\blank.txt:exe.bat

one could simply say

start C:\blank.txt:exe.bat

to run the executable. In Windows 7, all I seem to get is "Access is denied." or "The system cannot find the file $WHATEVER_THE_FILE_IS."

How can I execute this batch file?

1
  • 1
    This seems like a bad idea. What's your use case?
    – uSlackr
    Commented May 16, 2011 at 21:48

2 Answers 2

1

The accepted answer only runs one line of the batch file at a time. This will interrupt any advanced logic in the batch file. But, if you use a temporary file you can do this in a one-liner:

cat < blank.txt:exe.bat > temp.bat & temp.bat

You can also execute a PowerShell script in an alternate data stream via a similar command: (Though I am sure there is a pure PowerShell way too.)

cat < blank.txt:exe.ps1 > temp.ps1 & powershell .\temp.ps1

Example

Create batch in the alternate data stream: notepad blank.txt:exe.bat

if 6==7 then goto pie 
echo apple 
goto end 
:pie 
echo pie 
:end 

Broken:

E:\broken>for /f "usebackq delims=φ" %i in (blank.txt:exe.bat) do %i

E:\broken>if 6==7 then goto pie
'if' is not recognized as an internal or external command,
operable program or batch file.

E:\broken>echo apple
apple

E:\broken>goto end

E:\broken>
The filename, directory name, or volume label syntax is incorrect.

E:\broken>echo pie
pie

E:\broken>
The filename, directory name, or volume label syntax is incorrect.

Better:

E:\better>cat < blank.txt:exe.bat > temp.bat & temp.bat

E:\better>if 6 == 7 then goto pie

E:\better>echo apple
apple

E:\better>goto end
5

Windows 7 silently removed the ability to execute anything from an ADS. However, from the DOS command line, there are other options. For a batch file, you can execute line by line:

for /f "usebackq delims=φ" %i in (blank.txt:exe.bat) do %i

(Keep in mind, this does not actually execute the batch file into its own process, it simply reads and executes each line from the file. The φ symbol is typed with alt code number 2541. You want the delimiter to be a character you wouldn't ever use in the code.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .