icons - Is it possible to store a .ico file in a vbscript? -
i have vbscript script takes .ico file , creates desktop shortcut using icon, want able have script needs stored in itself, if possible.
there's easier (and much faster) method convert binary info base64 in vbscript using code @hackoo found. can take advantage of microsoft's implementation of base64 using msxml2.domdocument
class. here's script takes binary file c:\test.jpg
, converts base64. resulting base64-encoded string saved in text file (c:\out.txt
). uses ado stream
read file binary array , passes routine uses domdocument
convert binary info base64-encoded text.
const binary_file = "c:\test.jpg" const base64_file = "c:\out.txt" createobject("scripting.filesystemobject").createtextfile(base64_file, true) .write binaryfiletobase64(binary_file) .close end function binaryfiletobase64(strfilename) createobject("adodb.stream") .type = 1 ' specify binary info (adtypebinary) .open .loadfromfile strfilename binaryfiletobase64 = base64encode(.read) ' read binary contents vt_ui1 | vt_array end end function ' function accepts binary (vt_ui1 | vt_array) info , converts base64-encoded text (unicode string). function base64encode(binarydata) ' string createobject("msxml2.domdocument.3.0").createelement("base64") .datatype = "bin.base64" ' set type of info element should store .nodetypedvalue = binarydata ' write binary info base64encode = .text ' read text end end function
so can utilize script convert binary file base64-encoded string representation. example, stack overflow's icon, saved 12x15 bitmap:
qk1sagaaaaaaadyaaaaoaaaadaaaaa8aaaababgaaaaaabwcaaaaaaaaaaaaaaaaaaaaaaaa hoochoochoochoochoochoochoochoochoochooc3upl3uplhooc3upl3upl3upl3upl3upl 3upl3upl3uplhooc3upl3uplhooc3uplhoochoochoochoochoochooc3uplhooc3upl3upl hooc3upl3upl3upl3upl3upl3upl3upl3uplhooc3upl3uplhooc3uplciyociyociyociyo ciyociyo3uplhooc3upl3uplhooc3upl3upl3upl3upl3uplwttdn8dv3uplhooc3upl3upl 3upl3upl2uhknl/ucafjvpfcvjbcbkpi3upl3upl3upl3upl3+tm3+tmvzfcxjveekvlr8na 3+tmbq7cvkhz3+tm3+tm3+tm4exn4exn3epm4exn4exnsm3ip5fyqzjxs8/jv6tx097o4exn 4ubo4ubo4ubo3utoy6jbn5pxdblc3etoojb0k4/0e63vdqrw4+fp4+fp4+fpqzjyrzvywnbl 3uxpojb0lzd00t7qmyp1llvu5ojq5ojq5ojqxnjm5ojq3+bqopf0lph01uhrcafwpinz5ojq 5enr5enr5enr5enr5enrrjzzlph01+lr3otrmip1psbu5enr5+rs5+rs5+rs5+rs5+rsrs7u 3exs5+rszqlyq4705+rs5+rs6ovt6ovt6ovt6ovt6ovt6ovt6ovt6ovtn4f0s83v6ovt6ovt
to decode base64-encoded string, need perform steps in reverse. first, decode text original binary form. then, write binary info file.
const new_binary_file = "c:\test2.jpg" createobject("scripting.filesystemobject").opentextfile(base64_file) base64tobinaryfile .readall(), new_binary_file .close end sub base64tobinaryfile(strbase64, strfilename) createobject("adodb.stream") .type = 1 ' adtypebinary .open .write base64decode(strbase64) ' write byte array .savetofile strfilename, 2 ' overwrite if file exists (adsavecreateoverwrite) end end sub function base64decode(byval strtext) ' bytearray createobject("msxml2.domdocument.3.0").createelement("base64") .datatype = "bin.base64" .text = strtext base64decode = .nodetypedvalue end end function
so, original question, how embed binary (ico
) file in vbscript file? can add together base64 string somewhere. set @ end, beginning, somewhere in middle. it'll need commented out, of course, since it's not valid vbscript. , may want add together start , end delimiter know begins , ends. example:
' read ourself... createobject("scripting.filesystemobject").opentextfile(wscript.scriptfullname) ' "start"... until .atendofstream strline = .readline() if strline = "' ~end~" fread = false if fread strbase64 = strbase64 & mid(strline, 3) if strline = "' ~start~" fread = true loop end ' re-create our bitmap! base64tobinaryfile strbase64, "c:\stack_overflow.bmp" ' ~start~ ' qk1sagaaaaaaadyaaaaoaaaadaaaaa8aaaababgaaaaaabwcaaaaaaaaaaaaaaaaaaaaaaaa ' hoochoochoochoochoochoochoochoochoochooc3upl3uplhooc3upl3upl3upl3upl3upl ' 3upl3upl3uplhooc3upl3uplhooc3uplhoochoochoochoochoochooc3uplhooc3upl3upl ' hooc3upl3upl3upl3upl3upl3upl3upl3uplhooc3upl3uplhooc3uplciyociyociyociyo ' ciyociyo3uplhooc3upl3uplhooc3upl3upl3upl3upl3uplwttdn8dv3uplhooc3upl3upl ' 3upl3upl2uhknl/ucafjvpfcvjbcbkpi3upl3upl3upl3upl3+tm3+tmvzfcxjveekvlr8na ' 3+tmbq7cvkhz3+tm3+tm3+tm4exn4exn3epm4exn4exnsm3ip5fyqzjxs8/jv6tx097o4exn ' 4ubo4ubo4ubo3utoy6jbn5pxdblc3etoojb0k4/0e63vdqrw4+fp4+fp4+fpqzjyrzvywnbl ' 3uxpojb0lzd00t7qmyp1llvu5ojq5ojq5ojqxnjm5ojq3+bqopf0lph01uhrcafwpinz5ojq ' 5enr5enr5enr5enr5enrrjzzlph01+lr3otrmip1psbu5enr5+rs5+rs5+rs5+rs5+rsrs7u ' 3exs5+rszqlyq4705+rs5+rs6ovt6ovt6ovt6ovt6ovt6ovt6ovt6ovtn4f0s83v6ovt6ovt ' ~end~
vbscript icons desktop ico .ico
No comments:
Post a Comment