A script for converting any file into batch processing

Source: Internet
Author: User
Tags echo b

A script that converts any file into a batch.
The advantage of Base64 encoding is that the data size is compressed (compared with bin2str). The disadvantage is that it increases the processing time and script complexity.
Because the efficiency bottleneck lies in the process of generating vbs in bat, it is still possible.
Writing files using ADODB. Recordset is much better than debugging.
Most of the tasks are done by scripts. batch processing only uses echo to generate scripts.
The advantage of echo version is that the file is uploaded after all copies and pasted to the cmd shell.

Any2Bat. vbs by zzzEVAzzz
On error resume next
Set arg = wscript. arguments
If arg. count = 0 then wscript. quit
With CreateObject ("ADODB. Stream ")
. Type = 1:. open:. loadfromfile arg (0): bs =. read: l =. size:. close
End
If err. number <> 0 then wscript. quit
Set fso = CreateObject ("Scripting. FileSystemObject ")
With fso. opentextfile (arg (0) & ". bat", 2, true)
If err. number <> 0 then wscript. quit
. Writeline "@ echo bs = _> xx. vbs"
For k = 1 to l step 129
. Write "@ echo """
. Write b64b (midb (bs, k, 129 ))
. Writeline "+ _> xx. vbs"
Next
. Writeline "@ echo": set rs = CreateObject ("" ADODB. Recordset ")> xx. vbs"
. Writeline "@ echo set ado = CreateObject (" "ADODB. Stream")> xx. vbs"
. Writeline "@ echo l = len (bs): ss =": for k = 1 to l step 4096: ss = ss + ub64 (mid (bs, k, 4096): next: l = len (ss)> xx. vbs"
. Writeline "@ echo rs. fields. append "" B "", 205, l/2: rs. open: rs. addnew: rs ("B" ") = ss + chrb (0): rs. update> xx. vbs"
. Writeline "@ echo ado. mode = 3: ado. type = 1: ado. open: ado. write rs ("B ""). getchunk (l/2)> xx. vbs"
. Writeline "@ echo ado. savetofile" "+ fso. getfilename (arg (0) +" ", 2: ado. close> xx. vbs"
. Writeline "@ echo function ub64 (s): dim t (4), B (3): ub64 =": n = len (s ): r = 2> xx. vbs"
. Writeline "@ echo if n mod 4 ^ <^> 0 then exit function: end if: for I = 1 to n step 4: for j = 0 to 3> xx. vbs"
. Writeline "@ echo a = asc (mid (s, I + j, 1): if a = 43 then: a = 62: else if a = 47 then: a = 63: else if a ^> 47 and a ^ <58 then: _> xx. vbs"
. Writeline "@ echo a = a + 4: else if a = 61 then: a = 0: if r = 2 then r = J-2: end if: else if a ^> 64 and a ^ <91 then: _> xx. vbs"
. Writeline "@ echo a = a-65: else if a ^> 96 and a ^ <123 then: a = a-71: else: exit function: _> xx. vbs"
. Writeline "@ echo end if: t (j) = a: next> xx. vbs"
. Writeline "@ echo B (0) = t (0) + t (1) * 64 mod 256: B (1) = t (1) 4 + t (2) * 16 mod 256: B (2) = t (2) 16 + t (3) * 4> xx. vbs"
. Writeline "@ echo for j = 0 to r: if B (j) ^ <16 then ub64 = ub64 +" "0" ": end if: ub64 = ub64 + hex (B (j)> xx. vbs"
. Writeline "@ echo next: end function> xx.vbs&cscript.exe // nologo xx. vbs & del xx. vbs"
End
Const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /"
Function b64b (bin)
B64b = ""
N = lenb (bin)
For I = 1 to n step 3
A = ascb (midb (bin, I, 1 ))
B64b = b64b + mid (b64, a mod 64 + 1, 1)
If I <n then
B = ascb (midb (bin, I + 1, 1 ))
B64b = b64b + mid (b64, (a 64 + B * 4) mod 64 + 1, 1)
If I + 1 <n then
C = ascb (midb (bin, I + 2, 1 ))
B64b = b64b + mid (b64, (B 16 + c * 16) mod 64 + 1, 1)
B64b = b64b + mid (b64, c 4 + 1, 1)
Else
B64b = b64b + mid (b64, B 16 + 1, 1)
B64b = b64b + "="
End if
Else
B64b = b64b + mid (b64, a 64 + 1, 1)
B64b = b64b + "="
End if
Next
End function

The usage is simple. It is just a parameter-the full path of the file to be converted.
You can also drag and drop a file to the vbs icon.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.