Code Examples
  Home arrow Code Examples arrow Page 2 - Writing Binary Data in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Writing Binary Data in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-24

    Table of Contents:
  • Writing Binary Data in WSH
  • ADODB.Stream for writing binary files
  • Fixing the file contents
  • Writing binary files with FSO

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing Binary Data in WSH - ADODB.Stream for writing binary files


    (Page 2 of 4 )

    In order to make this work, I first had to determine what a compressed folder looked like in binary.  To do that I opened an empty compressed folder with a hex editor.  As it turns out, the file is nothing more than a string of twenty-two bytes as follows.

    50 4B 05 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Binary data is typically written in hexadecimal representation, which consists of two digits ranging from 0 to F.  Hexadecimal is a base-16 number system, so each place can have one of sixteen different values.  The numbers 0 through 9 are used for the first 10 and then the letters A through F are used for the remaining 6 digits to avoid confusion.  In any case, what’s important here is that a byte is two hexadecimal digits.

    With CreateObject("ADODB.Stream")

       .Open

       .Type = adTypeText

       .WriteText ChrB(&h50) & ChrB(&h4B) & ChrB(&h5) & ChrB(&h6)

       For i = 1 To 18

           .WriteText ChrB(&h0)

       Next

       .SaveToFile strPath, adSaveCreateNotExist

       .Close

    The script begins by creating an ADO Stream object and setting its type as text.  The reason is that the binary type will only accept a true binary array.  This is a special data structure used for manipulating binary files that is not available in VBScript.

    Once the stream is opened, we begin writing the binary characters to the stream as you saw earlier.  I’m simply supplying each of them in hex notation and using the ChrB function to write a binary character.  Characters are written one after another as if we were writing to a standard text stream object.

    More Code Examples Articles
    More By Nilpo


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek