The commonly used VBS tools: iconv, unix2dos/dos2unix, base64Encode/Decode

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

As a technology curtilage, sometimes do not have some ready to use the gadget is not, like the download games documentation is garbled swollen? Some configuration files using Notepad to open no newline, give it a newline after the game will not be able to load and run the swollen? Some games are written in Base64 in the configuration files in the swollen? (the amount of...... The next scene is more far fetched...) Okay, collected some VBS gadgets, without installing any compiler or interpreter manual installation, direct deposit into a text document to change the extension to run, convenient and quick, share out, perhaps useful to more people. In addition, the code is simple and easy to understand, when necessary, can remember we write method currently used, ha ha...

File: iconv.vbs

Effect: convert text code

Use: double click to run their help....

Set oArgs = WScript.Arguments
If oArgs.Count <> 3 Then
	outStr = "Usage: {wscript | cscript} "& Wscript.ScriptName &" fileName fromCode toCode" & vbcrlf
	outStr = outStr & vbcrlf &"Available in the registry code view "HKEY_CLASSES_ROOT\MIME\Database\Charset"" & vbcrlf
	'set WSHshell=wscript.createobject("WScript.Shell") 
	'WScript.Echo WSHshell.RegRead("HKEY_CLASSES_ROOT\MIME\Database\Charset\")
	Const HKCR = &H80000000
	strPath = "MIME\Database\Charset"
	Set oReg = GetObject("Winmgmts:\root\default:StdRegProv")
	oReg.EnumKey HKCR,strPath,arr
	outStr = outStr & vbcrlf & "The available coding format:" & vbcrlf
	For Each s In arr
		outStr = outStr & s & vbtab
	Next
	WScript.Echo outStr
Else
	ChangeCode oArgs(0),oArgs(1),oArgs(2)
End If
Set oArgs = Nothing

Function ChangeCode(strFile,code1,code2)
	Set ADOStrm = CreateObject("ADODB.Stream")
	ADOStrm.Type = 2
	ADOStrm.Mode = 3
	ADOStrm.CharSet = code1
	ADOStrm.Open
	ADOStrm.LoadFromFile strFile
	data= ADOStrm.ReadText
	ADOStrm.Position = 0
	ADOStrm.CharSet = code2
	ADOStrm.WriteText data
	ADOStrm.SetEOS
	ADOStrm.SaveToFile strFile&"_"&code2&".txt", 2
	ADOStrm.Close
End Function

File: unix2dos.vbs

Effect: convert UNIX text file into dos/windows wrap wrap

Usage: to convert the document to drag the icon on the vbs script

Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then
	WScript.Echo  "Usage: {wscript | cscript} "& Wscript.ScriptName &" fileName " & vbcrlf
Else
	Unix2DosFile(oArgs(0))
End If

Function Unix2DosFile(filePath) 
	Dim Fso
	Set Fso = wscript.CreateObject("Scripting.FileSystemObject")
	Const ForReading = 1
    Const ForWriting = 2
    Const isCreateNew = True
	Set f=fso.OpenTextFile(filePath, ForReading, isCreateNew)
	s=replace(f.ReadAll,vbLf,vbCrLf) 'replace dos to unix format: vbcrlf=chr(13)chr(10)
	f.Close
	Set f=fso.OpenTextFile(filePath,ForWriting,isCreateNew)
	f.Write s
	f.Close
	Set f=Nothing
	Set Fso=Nothing
End Function

File: dos2unix.vbs

Effect: convert dos/windows text file into UNIX wrap wrap

Usage: to convert the document to drag the icon on the vbs script

Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then
	WScript.Echo  "Usage: {wscript | cscript} "& Wscript.ScriptName &" fileName " & vbcrlf
Else
	Dos2UnixFile(oArgs(0))
End If

Function Dos2UnixFile(filePath) 
	Dim Fso
	Set Fso = wscript.CreateObject("Scripting.FileSystemObject")
	Const ForReading = 1
    Const ForWriting = 2
    Const isCreateNew = True
	Set f=fso.OpenTextFile(filePath, ForReading, isCreateNew)
	s=replace(f.ReadAll,vbCrLf,vbLf) 'replace dos to unix format: vbcrlf=chr(13)chr(10)
	f.Close
	Set f=fso.OpenTextFile(filePath,ForWriting,isCreateNew)
	f.Write s
	f.Close
	Set f=Nothing
	Set Fso=Nothing
End Function

File: base64Encode.vbs

Effect: the file is converted to Base64 code

Usage: to convert the document to drag the icon on the vbs script

Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then
	WScript.Echo  "Usage: {wscript | cscript} "& Wscript.ScriptName &" fileName " & vbcrlf
Else
	hexVal = ReadBinary(oArgs(0))
	Call WriteFile_Append(oArgs(0) & "_base64.txt", hexVal) 
End If
Set oArgs=Nothing

Function ReadBinary(FileName)
  Const adTypeBinary = 1
  Dim stream, xmldom, node
  Set xmldom = CreateObject("Microsoft.XMLDOM")
  Set node = xmldom.CreateElement("binary")
  node.DataType = "bin.base64"
  Set stream = CreateObject("ADODB.Stream")
  stream.Type = adTypeBinary
  stream.Open
  stream.LoadFromFile FileName
  node.NodeTypedValue = stream.Read
  stream.Close
  Set stream = Nothing
  ReadBinary = node.Text
  Set node = Nothing
  Set xmldom = Nothing
End Function

Public Function WriteFile_Append(pathway,words)	
    Dim fileSystemObj,fileSpec,logFile,way
    Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
    fileSpec = pathway 
    Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true) 
    logFile.WriteLine (CStr(words))
    logFile.Close
    Set logFile = Nothing
End Function

File: base64Decode.vbs

Effect: the base64 code decoding text file

Usage: to convert the document to drag the icon on the vbs script

Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then
	WScript.Echo  "Usage: {wscript | cscript} "& Wscript.ScriptName &" fileName " & vbcrlf
Else
	Conv2Binary(oArgs(0))
End If
Set oArgs=Nothing

Function Conv2Binary(FileName)
  Set stream = CreateObject("ADODB.Stream")
  stream.Type = 2
  stream.Mode = 3
  stream.CharSet = "ASCII"
  stream.Open
  stream.LoadFromFile FileName
  Dim stream, xmldom, node
  Set xmldom = CreateObject("Microsoft.XMLDOM")
  Set node = xmldom.CreateElement("binary")
  node.DataType = "bin.base64"
  node.Text=stream.ReadText
  stream.Close
  stream.Type = 1
  stream.Mode = 3
  stream.Open
 stream.Position = 0
  stream.write node.NodeTypedValue
  stream.SetEOS
  stream.SaveToFile  FileName & "_decode.txt", 2
  stream.Close
  Set stream = Nothing
  Set node = Nothing
  Set xmldom = Nothing
End Function
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Robert at December 27, 2013 - 4:55 AM