Create .bks file using batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
swathik
Posts: 1
Joined: 26 Sep 2011 01:41

Create .bks file using batch script

#1 Post by swathik » 26 Sep 2011 01:52

Hi All,
Please guide me in the following:

How to create the .bks file at runtime using Batch script.
And the .bks file should be in Unicode format.

Thanks,
Swathi.

Voodooman
Posts: 12
Joined: 25 Sep 2011 07:45

Re: Create .bks file using batch script

#2 Post by Voodooman » 26 Sep 2011 09:36

this would be quite hard,

you can try to use this command to convert dec string into hex or ASCII symbol

call cdm /b exit /b %dec%

and this line to catch hex value or ASCII symbol

set hex=%=exitcode% & set ascii=%=exitcodeascii%

in this case your !ascii! would be a binary byte which you can output to file, and %dec% vould be index number of that symbol in table, and you would need to map a whole table of symbols
http://www.utf8-chartable.de/unicode-ut ... &htmlent=1

and compose unicode characters by ascii symbols.
This would be quite hard and slow.

I suggest you to use combo of to lines above to get hex valuer, and XVI32 hex editor script, which would allow to write binary data from set of hex values, this will help to avoid mapping.
some explanation of how scripts works http://www.chmaas.handshake.de/delphi/f ... xviscr.htm
you can combine them with your bat file just by single command line with several arguments which would be passed to script.

Keep in mind that batch files alone not very friendly with binary data, in most cases best option is to search command line took that could write binary files

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Create .bks file using batch script

#3 Post by aGerman » 26 Sep 2011 12:21

It's quite difficult to create unicode files but it's possible.
That's the way I would create such a file:

Code: Select all

@echo off &setlocal
set "bksFile=%userprofile%\Local Settings\Application Data\Microsoft\Windows NT\NTbackup\Data\test.bks"

:: save the current codepage
for /f "tokens=2 delims=:" %%i in ('chcp') do set /a oemcp = %%~ni

:: switch to ANSI codepage
chcp 1252>nul

:: create the BOM (UTF-16 little endian)
>"%bksFile%" set /p "=ÿþ"<nul

:: write the content in unicode mode
cmd /u /c >>"%bksFile%" echo D:\^
&>>"%bksFile%" echo D:\FolderName\ /exclude^
&>>"%bksFile%" echo SystemState

:: switch back to ASCII codepage
chcp %oemcp%>nul

:: maybe further code here


Regards
aGerman

Post Reply