mystuff

Your IP Address is: 38.107.191.100
Last site update: 23 March 2009
You are visitor number: 

  home | wsname | wallpaper creator | delphi stuff | vb script stuff | other stuff | contact me

Google
Web Site
Here's a collection of Visual Basic (vb) Script functions I've collected over the years.

Services
   Check if a particular service is running

File System
   Delete a file
   Find a file if it's in the path
   Find the CDROM Drive
   Find CDROM Drive with Media
   Generate a filename and path for a working file in the %temp% directory
   Find the size of a file
   Find the location of PST files and log them in a SQL database

Network
   Renew a DHCP lease
   Ping a host (using WMI)
   Ping a host using the external ping.exe
   Convert an IP Address Mask to Slashed Notation
   Set a static IP address from a text file

Registry
   Search through the registry using recursion

Misc
   Including common functions and statement in your scripts
   Open the Control Panel Dialogue to the "Connections" option
   Convert a Binary File to a String
   Check if you're running on a Desktop or Laptop

Working With Data Files (INI, XML, SQL) files
   Using SQL to Generate a Self Incrementing Computer Naming System
   Read a Value from an INI File (GetINI)
   Write to an INI file (WriteINI)
   Read a whole section of an INI file
   Write a whole section to an INI file
   Read a value from an XML file

LDAP, AD, Exchange etc
   Get User Information from an Exchange 5.5 GAL
   Check to see if a User Account Exists in AD
   Get Members of an AD Group
   Update the Terminal Services Profile Path to point to a new Server
   Set Exchange 'Send As' and 'Receive As' Permissions


 Write a whole section to an INI file

This function writes an array to a whole section of an INI file

eg: iResult=GetINISection("c:\myfile.ini","Interesting Stuff",aSectionData

Function WriteINISection(byVal strFileName, byVal strSectionName, byVal aSectionData)
  Dim iI, strWorkingFile, bWrote, bWriteOK, tfSourceINI, tfDestINI
  Dim iReturn, sline
  strFileName=Trim(strFileName)
  strSectionName=Trim(strSectionName)
  bWriteOK = True
  bWrote = False
  If Left(strSectionName,1) <> "[" Then : strSectionName="[" + strSectionName
  If Right(strSectionName,1) <> "]" Then : strSectionName=strSectionName + "]"
  If Not IsArray(aSectionData) Then
    WriteINISection = 1
    Exit Function
  End If
  If UBound(aSectionData) < 0 Then
    WriteINISection = 2
    Exit Function
  End If
  strWorkingFile=GenerateTempFileName
  DeleteFile(strWorkingFile) ' Delete the temporary file if it exists
  Err.Clear
  Set tfSourceINI = fso.OpenTextFile(strFileName, 1, True)
  Set tfDestINI = fso.OpenTextFile(strWorkingFile, 2, True, TRISTATE_FALSE )
  If Err.Number <> 0 Then
    DeleteFile(strWorkingFile)
    Set tfSourceINI = Nothing
    Set tfDestINI = Nothing
    WriteINISection = 3
    Exit Function
  End If
  While tfSourceINI.AtEndOfStream = False
    sline = Trim(tfSourceINI.ReadLine)
    If (UCase(sLine) = UCase(strSectionName)) Then
      tfDestINI.WriteLine sLine
      For iI = LBound(aSectionData) To UBound(aSectionData)
        tfDestINI.WriteLine aSectionData(iI)
      Next
      bWriteOK = False
      bWrote = True
    Else
      If bWriteOK = False Then
        If Left(sline,1) = "[" Then
          bWriteOK = True
          tfDestINI.WriteLine
        End If
      End If
      If bWriteOK Then : tfDestINI.WriteLine sline
    End If
  Wend

  If bWrote = False Then ' strSectionName doesn't exist
    tfDestINI.WriteLine
    tfDestINI.WriteLine strSectionName
    For iI = LBound(aSectionData) To UBound(aSectionData)
      tfDestINI.WriteLine aSectionData(iI)
    Next
  End If

  tfSourceINI.Close
  tfDestINI.Close
  If Err.Number = 0 Then
    DeleteFile(strFileName)
    fso.CopyFile strWorkingFile , strFileName
    DeleteFile(strWorkingFile)
    WriteINISection = 0
  Else
    DeleteFile(strWorkingFile)
    WriteINISection = 4
  End If
  Set tfSourceINI = Nothing
  Set tfDestINI = Nothing
End Function