Metadata for batch files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SirJosh3917
Posts: 36
Joined: 02 May 2016 18:59

Metadata for batch files

#1 Post by SirJosh3917 » 29 Oct 2016 11:59

Hello! Until today, we've all been storing batch file data in other files, making portability of data harder. Today I bring to you a simple solution that stores metadata inside of a batch file, so you don't create any files but you still store data. The following technique only requires some extra coding at the end of your batch file - and at the very end.

Code: Select all

::Metadata solution provided by SirJosh3917.
::Honestly I don't care for credit anywhere
::viewable in the batch file, but if possible just
::leave the first comment.

:metadata

if NOT EXIST metadata.bat (
(
echo.77u/QGVjaG8gb2ZmDQpjb3B5ICV+MyB0bXAuYmF0DQpAZWNoby4+JX4zDQpmb3Ig
echo.L2YgImRlbGltcz0iICUlYSBpbiAoIHRtcC5iYXQgKSBkbyAoDQoJaWYgIiUlYSI9
echo.PSJlY2hvLmE+bnVsJmV4aXQgL2IiICgNCgkJQGVjaG8uc2V0ICV+MT0lfjIgPj4l
echo.fjMNCgkpIGVsc2UgKA0KCQlAZWNoby4lJWE+PiV+Mw0KCSkNCikNCkBlY2hvLmVj
echo.aG8uYV4+bnVsXiZleGl0IF4vYj4+JX4zDQo=
)>tmp.bat
certutil -decode tmp.bat metadata.bat>nul
del /f /s /q tmp.bat>nul
cls
)

::METADATA FOR BATCH FILE

echo.a>nul&exit /b

Just make sure to put this little bit of code at the end of your batch file and you're done! You can now store metadata inside of your batch file.
It's very easy. Here's an example batch file storing metadata

Code: Select all


@echo off

title MetaData Example

call :metadata
del /f /s /q tmp.bat>nul
cls

IF NOT DEFINED name goto :GetName

echo.Oh hello %name%^! It's nice to see you again.

pause

exit

:GetName

echo Hello! What is your name?

set /p name=^>

echo Hello %name%^! Nice to meet you.

call metadata.bat name "%name%" "%~0"

::
::Always put this after you use metadata.bat
::

cls
echo Hello! What is your name?
echo.^> %name%
echo Hello %name%^! Nice to meet you.
echo I'll see you next time!

pause

goto :eof

::Metadata solution provided by SirJosh3917.
::Honestly I don't care for credit anywhere
::viewable in the batch file, but if possible just
::leave the first comment.

:metadata

if NOT EXIST metadata.bat (
(
echo.77u/QGVjaG8gb2ZmDQpjb3B5ICV+MyB0bXAuYmF0DQpAZWNoby4+JX4zDQpmb3Ig
echo.L2YgImRlbGltcz0iICUlYSBpbiAoIHRtcC5iYXQgKSBkbyAoDQoJaWYgIiUlYSI9
echo.PSJlY2hvLmE+bnVsJmV4aXQgL2IiICgNCgkJQGVjaG8uc2V0ICV+MT0lfjIgPj4l
echo.fjMNCgkpIGVsc2UgKA0KCQlAZWNoby4lJWE+PiV+Mw0KCSkNCikNCkBlY2hvLmVj
echo.aG8uYV4+bnVsXiZleGl0IF4vYj4+JX4zDQo=
)>tmp.bat
certutil -decode tmp.bat metadata.bat>nul
del /f /s /q tmp.bat>nul
cls
)

::METADATA FOR BATCH FILE

echo.a>nul&exit /b


If you would like to use metadata, put this when you'd like to store data.

Code: Select all

call metadata.bat name "%name%" "%~0"

::
::Always put this after you use metadata.bat
::


You have to put those comments after you use metadata because metadata is in it's early stage, and hasn't fully developed to it's best yet, and it makes weird output on the screen I'm sure any user wouldn't want to see. After you use metadata, make sure to re-output everything you already had on screen because it makes some funky noises as it's doing stuff (aka outputs text on screen)

If you would like download the working examples, please download the attachment below. The attachment below also contains the source code of metadata.bat


NOTE: metadata.bat is VERY BAD AND UNSTABLE as of right now. Please help out and make it better, if possible at all.
Attachments
Metadata.zip
The working example and source code
(1.08 KiB) Downloaded 434 times

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Metadata for batch files

#2 Post by Squashman » 29 Oct 2016 12:23

We are already using this concept to include things like 3rd party utilities and images in batch files. So I am not understanding how this is any different then that same technique. What extra functionality does this provide?

SirJosh3917
Posts: 36
Joined: 02 May 2016 18:59

Re: Metadata for batch files

#3 Post by SirJosh3917 » 29 Oct 2016 12:27

Squashman wrote:We are already using this concept to include things like 3rd party utilities and images in batch files. So I am not understanding how this is any different then that same technique. What extra functionality does this provide?


You can store variables inside of a batch file instead of in other files, allowing for portability of data.
If this already exists elsewhere then you can go ahead and put me to shame if you'd like.

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Metadata for batch files

#4 Post by jfl » 10 Nov 2016 08:03

Squashman wrote:We are already using this concept to include things like 3rd party utilities and images in batch files. So I am not understanding how this is any different then that same technique. What extra functionality does this provide?

I see an obvious advantage:
Using certutil's -encode and -decode options for generating binary files is considerably simpler than using the very-clever-but-complex pure batch versions published previously in this forum.
And a drawback:
certutil.exe seems to be available in Vista and later, but not in XP. So if you still want to support XP systems, you can't use it.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Metadata for batch files

#5 Post by Squashman » 10 Nov 2016 08:13

jfl wrote:
Squashman wrote:We are already using this concept to include things like 3rd party utilities and images in batch files. So I am not understanding how this is any different then that same technique. What extra functionality does this provide?

I see an obvious advantage:
Using certutil's -encode and -decode options for generating binary files is considerably simpler than using the very-clever-but-complex pure batch versions published previously in this forum.
And a drawback:
certutil.exe seems to be available in Vista and later, but not in XP. So if you still want to support XP systems, you can't use it.

That is my point. We are already have several documented solutions using certutil on the forums already so I am not sure what extra functionality this has over what is already documented on the forums.

Post Reply