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


 Update the Terminal Services Profile Path to point to a new Server

 
IMPORTANT: This code needs to be run from a Windows 2003 server (2000 and XP wont work)
  You should also run it with CSCRIPT as it is going to echo a lot of information to the screen

Option Explicit
 
Const OLD_NAME = "OLDSERVERNAME"
Const NEW_NAME = "NEWSERVERNAME"
 
Dim oRootDSE, sDNSDomain, oCommand, oConnection, oRecordSet, oUser, sTerminalServicesProfilePath, sTerminalServicesHomeDirectory, sServerName
 
Set oRootDSE = GetObject("LDAP://RootDSE")
sDNSDomain = oRootDSE.Get("defaultNamingContext")
Set oCommand = CreateObject("ADODB.Command")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
 
oCommand.CommandText = "SELECT adsPath FROM '" & "LDAP://" & sDNSDomain & "' WHERE objectCategory='person' and objectClass='user'"
oCommand.Properties("Page Size") = 100
oCommand.Properties("Timeout") = 30
oCommand.Properties("Cache Results") = False
oCommand.Properties("Searchscope") = 2
Set oRecordSet = oCommand.Execute
 
Do Until oRecordSet.EOF
      Set oUser = GetObject(oRecordSet.Fields("adsPath"))
      sTerminalServicesProfilePath = oUser.TerminalServicesProfilePath
      sTerminalServicesHomeDirectory = oUser.TerminalServicesHomeDirectory
      if sTerminalServicesProfilePath <> "" Then
            sTerminalServicesProfilePath = Right(sTerminalServicesProfilePath,Len(sTerminalServicesProfilePath)-2)
            sServerName = Left(sTerminalServicesProfilePath,InStr(sTerminalServicesProfilePath,"\")-1)
            If UCase(sServerName) = UCase(OLD_NAME) then
              sTerminalServicesProfilePath = "\\" & NEW_NAME & Right(sTerminalServicesProfilePath,Len(sTerminalServicesProfilePath) - InStr(sTerminalServicesProfilePath,"\")+1)
              sTerminalServicesHomeDirectory = "\\" & NEW_NAME & Right(sTerminalServicesHomeDirectory,Len(sTerminalServicesHomeDirectory) - InStr(sTerminalServicesHomeDirectory,"\")+1)
              WScript.Echo "Updating " & UCase(Right(oUser.Name,Len(oUser.Name)-3)) & " " & Chr(34) & oUser.TerminalServicesProfilePath & Chr(34) & " --> " & Chr(34) & sTerminalServicesProfilePath & Chr(34) 
              WScript.Echo "         " & UCase(Right(oUser.Name,Len(oUser.Name)-3)) & " " & Chr(34) & oUser.TerminalServicesHomeDirectory & Chr(34) & " --> " & Chr(34) & sTerminalServicesHomeDirectory & Chr(34) 
              WScript.Echo ""
              oUser.TerminalServicesProfilePath = sTerminalServicesProfilePath
              oUser.TerminalServicesHomeDirectory = sTerminalServicesHomeDirectory
              'oUser.SetInfo
            End if
      End if
      oRecordSet.MoveNext
Loop
oConnection.Close