0

I'm using a second batch file in my main one to save/load variables, like this:

if not exist "KeemyDataPersistence.bat" (
echo @ECHO OFF > KeemyDataPersistence.bat
echo SET GENDER=F >> KeemyDataPersistence.bat
echo SET BGCOLOR=0 >> KeemyDataPersistence.bat
echo SET FGCOLOR=2 >> KeemyDataPersistence.bat
)
call KeemyDataPersistence.bat

It's working fine, but I'd like to save that second file (KeemyDataPersistence.bat) with another extension (.keemy), so KeemyDataPersistence.keemy. It saves fine just by replacing .bat by .keemy in the whole code, but when using call KeemyDataPersistence.keemy, it runs the windows default window to choose the program the user wants to open it with.

How would I be able to make it call the file as a batch file?

R__
  • 183
  • 2
  • 11
  • 2
    check [this](http://stackoverflow.com/questions/23162474/command-prompt-execute-commands-from-any-text-file-not-having-bat-or-cmd) – npocmaka Nov 25 '15 at 16:14

1 Answers1

2

Try first to run this script once with admin permissions (and .bat extension):

   @echo off

    rem :: A files with .keemy 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 .keemy=batps
    ftype batps=c:\caller "%%1" %*
npocmaka
  • 55,367
  • 18
  • 148
  • 187