Exchange automation

The default Web site will restart as soon as the M: drive is available and the Public folders will be re-shared.

Any of you who are administering an Exchange 2000 install will know that each time you reboot you have to restart

the default Web and, if needed, re-share any directories on the M: drive. Well, no more. With these handy scripts and instructions, you can have the default Web site restart itself as soon as the M: drive becomes available and the Public folders will be re-shared automatically. Just follow these simple instructions and create the scripts from the code below.

This document refers to problems referenced in KB articles Q259373 and Q258550.

Default Web restart

    1. Create an MMC with the Group Policy snap-in selecting local as the default location.
    2. Open Local Computer Policy / Windows Settings and select Scripts (Startup/Shutdown)
    3. Double click Startup in the righthand pane.
    4. Click Show Files.
    5. You need to copy all supplied scripts to this location before continuing. Once you have done this proceed with step 6.
    6. Click Add. Browse to and select the ExchDefaultWebRestart.wsf file and then click open.
    7. In Script Parameters type: -a 1
    8. Click OK

Re-sharing the public folders on reboot

    1. Using the MMC created above repeat the steps to add the file: ExchSharePublicFolders.wsf (no parameters needed).
    2. Close the MMC (save it if needed).
    3. Open C:WINNTsystem32GroupPolicyMachineScriptsStartup, right click the file CreateShare.wsf and choose Edit from the drop down menu.
    4. Find the following text and edit the fields as required to reflect your server naming:
    '***   Edit variables as required  myserver = "servername" 
        sharedescription = "Exchange 2000 - Public Folders Share"
        sharename = "Public Folders"
        sharepath = "M:YOURDOMAIN.CO.UKPUBLIC FOLDERS"
    5. Save the file.
    6. Close the MMC.

Note: You can set the scripts to run asynchronously to speed up the process at system start but please be aware of the concequences.


Script one. Name script: CreateShare.vbs

'*******************************************************************
'   Name    :  CreateShare.vbs
'
'   Purpose :  This Script creates a new share and sets the
'              security descriptor for the new share.
'********************************************************************

'***   Edit variables as required
    myserver = "SERVERNAME"
    sharedescription = "Exchange 2000 - Public Folders Share"
    sharename = "Public Folders"
    sharepath = "M:DOMAINNAME.CO.UKPUBLIC FOLDERS"
    
'***   Connect to WMI and set security settings.         ******
'***   You should substitute the name of the system  ***
    Set objservices = GetObject("WINMGMTS:" _
                              & "{impersonationLevel=impersonate,(Security)}" _
                              & "!" & myserver & "ROOTCIMV2")

'***   Get the Win32_SecurityDescriptor class and spawn a new instance       ****
    Set objclass = objservices.Get("Win32_SecurityDescriptor")
    Set objSecDescriptor = objclass.SpawnInstance_()
    
'******   Prepare the security descriptor for the new share   ******
    objSecDescriptor.Properties_.Item("ControlFlags") = 4
     
    Set ACE2 = SetACE(objservices, 2032127, _
                      3, _
                      0, _
                      SetTrustee(objservices, Null, _
                                 "EVERYONE", _
                                  Array(1, 1, 0, 0, 0, 0, 0, 1, 0, _
                                        0, 0, 0)))
    
    
    objSecDescriptor.Properties_.Item("DACL") = Array(ACE2)
    
    
'************************ Create the new share *********************
    
    Set objShare = objservices.Get("Win32_Share")
    Set objInParam = objShare.Methods_("Create").InParameters.SpawnInstance_()
    objInParam.Properties_.Item("Access") = objSecDescriptor
    objInParam.Properties_.Item("Description") = sharedescription
    objInParam.Properties_.Item("Name") = sharename 
    objInParam.Properties_.Item("Path") = sharepath 
    objInParam.Properties_.Item("Type") = 0
    
    'objInParam.Properties_.item("MaximumAllowed") = 10     'optional - default is 'max allowed'
    'objInParam.Properties_.item("Password") = "Password"   'optional - default is no password
    
    
'************************ Execute the method **********************
    Set objOutParams = objShare.ExecMethod_("Create", objInParam)
    If objOutParams.ReturnValue = 0 Then
        wscript.echo  "Share created successfully"
    Else
      If objOutParams.ReturnValue = 22 Then
        wscript.echo  "Share may already exist"
      Else
        wscript.echo  "Unable to create share, return value was : " _
            & objOutParams.ReturnValue
      End If
    End If

'************************* HELPER FUNCTIONS *********************
Function SetTrustee(objservices, strDomain, strName, SID)
     Set objTrustee = objservices.Get("Win32_Trustee").SpawnInstance_
     objTrustee.Domain = strDomain
     objTrustee.Name = strName
     objTrustee.Properties_.Item("SID") = SID
     Set SetTrustee = objTrustee
End Function

Function SetACE(objservices, AccessMask, AceFlags, AceType, objTrustee)
     Set objAce = objservices.Get("Win32_Ace").SpawnInstance_
     objAce.Properties_.Item("AccessMask") = AccessMask
     objAce.Properties_.Item("AceFlags") = AceFlags
     objAce.Properties_.Item("AceType") = AceType
     objAce.Properties_.Item("Trustee") = objTrustee
     Set SetACE = objAce
End Function
'******************************************************************

Script Two. Name script: ExchDefaultWebRestart

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- 
    File:    ...
    Author:  ...
-->


<job id="T1">
    <script language="VBScript"> 
    <![CDATA[
 Option Explicit

 Dim Disk, DiskSet, blnDriveExists, TimeOut, TimeElapsed, SleepInterval

 blnDriveExists = false
 TimeOut = 10 * 1000 * 60
 SleepInterval = 1 * 1000
 Set Diskset = GetObject("WinMgmts:").InstancesOf("Win32_LogicalDisk")


 do while (blnDriveExists = false)
  For Each Disk In DiskSet
   '*** M: For Exchange Drive ***
   If Disk.DeviceID = "M:" then
    blnDriveExists = true
   End If
      Next
  If Not blnDriveExists Then
   TimeElapsed = TimeElapsed + SleepInterval
   WScript.Sleep SleepInterval
   
  End If
  If TimeElapsed > TimeOut Then WScript.Quit
 loop

    ]]>
    </script>



    <script language="VBScript" src="stopweb.vbs"/>
    <script language="VBScript" src="startweb.vbs"/>



</job>

Script Three. Name script: ExchSharePublicFolders

<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- 
    File:    ...
    Author:  ...
-->

<job id="T1">
    <script language="VBScript">
    <![CDATA[
 Option Explicit

 Dim Disk, DiskSet, blnDriveExists, TimeOut, TimeElapsed, SleepInterval

 blnDriveExists = false
 TimeOut = 10 * 1000 * 60
 SleepInterval = 1 * 1000

 On Error Resume Next
 
 Do While (blnDriveExists = false)
  Set DiskSet = GetObject("WinMgmts::Win32_LogicalDisk='M:'") 
  if Err.Number = 0 then blnDriveExists = true
  If Not blnDriveExists Then
   TimeElapsed = TimeElapsed + SleepInterval
   WScript.Sleep SleepInterval
   If TimeElapsed > TimeOut Then WScript.Quit
  End If
 loop

 On Error Goto 0
    ]]>
    </script>

    <script language="VBScript" src="CreateShare.vbs"/> 

</job> 

Note: THE STARTWEB AND STOPWEB SCRIPTS ARE THE DEFAULT SCRIPTS FOUND IN THE IIS ADMINSCRIPTS DIR ON ANY MACHINE WITH IIS INSTALLED. COPY THESE SCRIPTS FROM THERE.

This was first published in May 2001

Dig deeper on Microsoft Exchange Server Scripts and Programming

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWindowsServer

SearchEnterpriseDesktop

SearchCloudComputing

SearchSQLServer

Close