I am running three batch files 1 - main.bak (hidden) 2 - open.bat (shown) 3 - hide.bat (shown)

open.bat contains,

attrib -s -h main.bak
ren main.bak main.bat
call main.bat

main.bak or main.bat contains,

@echo off
start hide.bat
echo hi
echo Welcome

hide.bat contains,

ren main.bat main.bak
attrib +s +h main.bak

Now the problem is, when i run open.bat it rename and unhide and runs main.bat and shows output,

press any key to continue...

(while showing hi it already started running hide.bat , it rename and hides the main.bat file.)

So now, my output files stucks at Hi and not showing Welcome

Main thing am doing this is to hide my source of batch programming from others which was in main.bat

Any helps appreciated.. Thank u guys in Advance. Pls help.. i want to hide my source from others (right click » edit)


Unfortunately, you cannot prevent this if the script is on a Windows machine in it's native format. You can however use conversion or wrapping methods to hide the code to a degree.

Your best option would easily be F2KO Software's Bat To Exe Converter (Freeware) to convert the batch scrip into an executable binary. Your other option would br to use WinRAR (Trial/Price varys) to wrap the script in an SFX archive.

Note: Bat To Exe has a UPX packer built-in, but UPX is rather unsecure and obsolete.

To secure the code, I use ASPack (Price varys) to obfuscate my scripts. There is a free alternative called Pitete, but is not as secure. An experienced hacker with a debugger could easily find the OEP to unpack the obfuscation. ASPack is more secure but not invunerable.

An added bonus of using an executable module is that you can add a custom icon and version information to your program. In some cases, converting a script to an executable format may break it! In your case, I would use Bat To Exe Converter and set the Working directory to Current directory.

Please note that wrapping a script, JAR, ect is not going to protect your code even if you obfuscate or compress the extraction module. This is due to the fact that the module extracts the contents to %TEMP% (or some other location). All the end-user has to do is run Task Manager to trace the script to it's source!

| improve this answer | |
  • Thnx for your answer, but, every method you says extract the source bat file to the %temp% folder when running exe file. This was the problem. All my users know about this. Still i want to secure my source. There is none other way ? like encrypting bat ? while running it need to decrypt itself and run, after that encrypt itself. ? like that anything ? pls.. – Philip Aug 15 '17 at 4:36
  • If you use Bat To Exe Converter and set the Working directory paramater to Current directory the script will be ran in a sandboxed environment. The only way to extract the code from this method would be rather complex... Using this method is not wrapping the script. – Mr. Mendelli Aug 15 '17 at 4:48
  • That's good idea and instead of running it in current directory , is there any way to run it in custom directory ? i tried Bat to Exe Convertor it doesn't have custom directory option to browse and fix one from c: drive . Is that anyother app can do it ? or any other way ? any clues ? any idea ? anything will be appreciated and thankful – Philip Aug 15 '17 at 5:01
  • You cannot customize the working directory in Bat To Exe Converter outside of the two options provided. You can with WinRAR though. – Mr. Mendelli Aug 15 '17 at 5:04
  • But, winrar creates only SFX installable exe file. It runs only bat file with right click » edit (source viewer option) . Is that any other way bro... ? Sorry for repeated Questions.. Is there any way to run bat file in hidden mode ? mean the bat file need to hide itself (note: not the program hidden) the file need to hide itself and need to run ? any way for this ? or any way to run the attrib -s -h file.bat hide command when user close the [X] app using top right corner close button ? Please help. – Philip Aug 15 '17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.