4

I suppose this is a strange question . but I'm curious.This is what I've tried so far: I've exported and compare values from [HKEY_CLASSES_ROOT\batfile] ,[HKEY_CLASSES_ROOT\cmdfile],[HKEY_CLASSES_ROOT\.bat],[HKEY_CLASSES_ROOT\.cmd] . The only differences I've noticed were in HKEY_CLASSES_ROOT\*\FrienflyTypeName which suppose is not crucial for their execution.So I've created an registry values with same data for desired extension(I'm trying to create .scjs file extension ):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.scjs]
@="scjsfile"
#this says that the file will contains text
[HKEY_CLASSES_ROOT\.scjs\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\scjsfile]
@="Windows Batch File"
"EditFlags"=hex:30,04,00,00
"FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
  32,00,5c,00,61,00,63,00,70,00,70,00,61,00,67,00,65,00,2e,00,64,00,6c,00,6c,\
  00,2c,00,2d,00,36,00,30,00,30,00,32,00,00,00

[HKEY_CLASSES_ROOT\scjsfile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,69,00,6d,00,\
  61,00,67,00,65,00,72,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,36,\
  00,38,00,00,00

[HKEY_CLASSES_ROOT\scjsfile\shell]

[HKEY_CLASSES_ROOT\scjsfile\shell\edit]

[HKEY_CLASSES_ROOT\scjsfile\shell\edit\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

  #copied from batfile from HKEY_CLASSES_ROOT .Same as cmdfile reg values
[HKEY_CLASSES_ROOT\scjsfile\shell\open]
"EditFlags"=hex:00,00,00,00

[HKEY_CLASSES_ROOT\scjsfile\shell\open\command]
@="\"%1\" %*"

[HKEY_CLASSES_ROOT\scjsfile\shell\print]

[HKEY_CLASSES_ROOT\scjsfile\shell\print\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,2f,00,70,00,20,\
  00,25,00,31,00,00,00

[HKEY_CLASSES_ROOT\scjsfile\shell\runas]
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\scjsfile\shell\runas\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6d,00,\
  64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,43,00,20,00,22,00,25,00,31,00,22,\
  00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\scjsfile\shell\runasuser]
@="@shell32.dll,-50944"
"Extended"=""
"SuppressionPolicyEx"="{F211AA05-D4DF-4370-A2A0-9F19C09756A7}"

[HKEY_CLASSES_ROOT\scjsfile\shell\runasuser\command]
"DelegateExecute"="{ea72d00e-4960-42fa-ba92-7792a7944c1d}"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx]

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\ContextMenuHandlers]
@="Compatibility"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\ContextMenuHandlers\Compatibility]
@="{1d27f844-3a1f-4410-85ac-14651078412d}"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\ContextMenuHandlers\OpenGLShExt]
@="{E97DEC16-A50D-49bb-AE24-CF682282E08D}"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\PropertySheetHandlers\ShimLayer Property Page]
@="{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}"

[HKEY_CLASSES_ROOT\scjsfile\ShellEx\{8895b1c6-b41f-4c1c-a562-0d564250836f}]
@="{1531d583-8375-4d3f-b5fb-d23bbd169f22}"

Also I've added the value (.SCJS) to the PATEXT variable -> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.SCJS

but when I run the file I get : test.scjs is not valid Win32 application.Access is denied.

So it is even possible?Is there something else I should change?

EDIT : the best solution I've found: for open key I use:

[HKEY_CLASSES_ROOT\scjsfile\shell\open\command]
@="%SystemRoot%\\System32\\caller.bat \"%1\" \"%*\""

where I have caller.bat in system32:

@echo off
copy "%~nx1"  "%temp%\%~nx1.bat" /Y >nul
"%temp%\%~nx1" .bat %~2

wish simply cmd /c it's harder to manage the arguments.Looks at the moment there's no way to handle command line arguments.

ONE MORE EDIT: The one way to handle the command line arguments is to use [HKEY_CLASSES_ROOT\scjsfile\shell\open\Run] instead of [HKEY_CLASSES_ROOT\scjsfile\shell\open\command] .I don't know what exactly is the difference right now , but it works (I saw this from my AutoIT installation :-) ).

npocmaka
  • 55,367
  • 18
  • 148
  • 187

4 Answers4

2

Although this has already been accepted I thought I would add in my answer that I hacked together.

I created my own file extension .bali in which I can put some batch commands and run them by opening the file.

The .bali registry export looks like this

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.bali]
@="BaliFile"

Note that this value can't have spaces (might work if it's quoted, but didn't try it).

The balifile registry export look like this

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\balifile]

[HKEY_CLASSES_ROOT\balifile\DefaultIcon]
@="%SystemRoot%\\System32\\imageres.dll,-68"

[HKEY_CLASSES_ROOT\balifile\shell]

[HKEY_CLASSES_ROOT\balifile\shell\open]

[HKEY_CLASSES_ROOT\balifile\shell\open\command]
@="cmd.exe /c for /f \"delims=\" %%a in (%1) do %%a"

My file.bali looks like this

echo hello bali
pause

The file will have the cmd icon as well, and when it is run it will run the commands in the prompt, obviously outputting hello bali.

This is limited as to what you can use, you can't for example use variables, but you can experiment with it yourself to find out what you can and can't do.

Not sure if this is what you are looking for, but it was quite fun to make anyways :)

Bali C
  • 30,582
  • 35
  • 123
  • 152
  • 1
    Heh.I've done almost the same with making a %1.bat copy to %temp% – npocmaka Nov 27 '12 at 15:38
  • You can work with variables if you use the CALL trick or else enable delayed expansion. But here is a partial list of things you cannot do with this solution: IF, FOR, prefix command with @, :label, GOTO label, CALL :label, redirection, pipe. There is more that cannot be done, but that is enough for now. – dbenham Nov 27 '12 at 22:58
1

This same question was asked previously, but I can't find it.

The consensus was that it is impossible - Windows will not allow execution of batch files that do not have an extension of .bat or .cmd

I remember one poster mentioned the security loop hole that would be created if it were allowed.

dbenham
  • 127,446
  • 28
  • 251
  • 390
1

First need an "installation" script :

   @echo off

    rem :: A files with .TEST extension will be able to execute batch code but is not perfect as the %0 argument is lost

    rem :: "installing" a caller.
    if not exist "c:\caller.bat" (
       echo @echo off
       echo copy "%%~nx1"  "%%temp%%\%%~nx1.bat" /Y ^>nul
       echo "%%temp%%\%%~nx1.bat"  %%*
    ) > c:\caller.bat

    rem :: associating file extension
    assoc .test=batps
    ftype batps=c:\caller "%%1" %%*

then we can try a simple .test file:

@echo off
for /l (1;1;10) do (
  echo testing .TEST extension
)

ASSOC and FTYPE both have immediate effect so we can start a .test file right after "installation" and there's no need of second cmd instance.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
0

You need to associate a PROGRAM for the desired extension...

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.test]

[HKEY_CLASSES_ROOT\.test\shell]

[HKEY_CLASSES_ROOT\.test\shell\open]

[HKEY_CLASSES_ROOT\.test\shell\open\command]
@="notepad \"%1\""

Now create a new file in your desktop named "File.test" and double-click on it, notepad will open it.

I hope this helped you.

UPDATE

For registered extensions in your PC... for example ".bat" is registered by "batfile" key then you need to associate the program inside the registered key, i'll mean "batfile" key, not ".bat" key.

PS: Sorry for my english.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Hi.The **.scjs** is registered as **scjs** file here : `[HKEY_CLASSES_ROOT\.scjs] @="scjsfile"` .Of course the main problem is the open command.in **.bat** and **.cmd** open program is defined as `@="\"%1\" %*"` which I suppose means - open the file itself with all arguments.But it does not work with my file definition. – npocmaka Nov 27 '12 at 12:12
  • 1
    because SCJS is not a file system that can be interpreted by the system like ".bat", ".vbs" ".cmd", ".js", etc... you need to open it with a program, not itself, isn't an executable file. Change the open command like in my example. – ElektroStudios Nov 27 '12 at 12:25
  • In fact it's easy to create a file open as .vbs or .js - > just need to edit open command as cscript \"%1\" and to copy wscript engine definition form **jsfile** or **vbsfile** registry entries. – npocmaka Nov 27 '12 at 12:40
  • 1
    you want to open the SCJS file like an vbscript? i'll mean with the VBS interpreter? – ElektroStudios Nov 27 '12 at 12:45
  • no.I want to be able to call it as .bat file and to execute commands in it. I already know how to run it as a vbscript or jscript :-) . – npocmaka Nov 27 '12 at 12:47
  • OK... to recap a few things: 1. Double clicking on item in window, maps .ext to filetype. Then maps filetype to program which is then passed to CreateProcess. 2. There's some unfortunate magic in there when doing CreateProcess on a .CMD or .BAT will rewrite the command to be 'CMD /C "filename"'. I think you need to have your .ext map to a filetype and the open verb on the filetype should be something like CMD /C "%1" – MJZ Nov 27 '12 at 23:34