Share via


Using a Logon Script to Install the SMS Advanced Client

One of my customers has an extensive lab environment with multiple forests, domains and workgroup computers.  SMS 2003 was deployed to help manage the configuration of all these different systems.  Between the locked down security settings (no C$, ADMIN$ shares!) and the number separate forest/domains/workgroups involved the ability to "push" the advanced client to desktops is no longer an option.  After meeting with the client last week we decided to configure a logon script to install the SMS client.  The script and associated files (CCMSETUP.EXE, CLIENT.MSI, SMSCLIENT.VBS) were placed in a folder named SMS in the NETLOGON share of the Domain Controllers.  We then configured the LOGON SCRIPT properties of the Domain Administrator account to run the SMSSTARTUP.VBS script shown below to install the client.

Now for a quick run through of the code. 

  • Declare our variables and create the objects we will be working with. 
  • Determine the path to the NETLOGON \SMS folder we are using.
  • Check to see if the SMS client is installed (Set oSMSClient ... If Err.Number....)
  • Display a timed popup message with a Cancel button
  • Copy install files to local computer.
  • Run installation script (SMSCLIENT.VBS)
  • Set commands in the RunOnce registry key to delete the SMSCLIENTINSTALL folder the next time someone logs in.

SMSSTARTUP.VBS

'**********************************************
'  SCRIPT: SMSStartup.VBS
'  AUTHOR:
'  DATE:   10/16/2008
' VERSION: 2.0
' PURPOSE: Check for thr presence of the SMS client,
'                   if not installed, copy files from the
'                   network to c:\smsclientinstall and install
' USAGE:     SMSStartup.vbs
'                             
'REVISION: 10/17/2008 added check
'                  to make sure files and folders exist
'                  before moving to next step in script
'         
'**********************************************
OPTION EXPLICIT
On Error Resume Next

Dim oSMSClient, intButton,objWshShell,sFolder, objFSO, sCurrentPath
Dim oExec

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set oSMSClient = CreateObject ("Microsoft.SMS.Client")

'Folder to copy SMS install files to
sFolder = "C:\SMSCLIENTINSTALL"

WScript.Sleep 15000

'Build path to SMS files
sCurrentPath = objWshShell.ExpandEnvironmentStrings("%LOGONSERVER%")
sCurrentPath = sCurrentPath & "\NETLOGON\SMS"

 

 

If Err.Number <> 0 Then 'change to zero when testing complete
     'Clear error buffer
     err.clear
    objWshShell.LogEvent 2, "SMS Client is not installed, installing now."
    intButton=objWshShell.Popup("Installaing SMS Client software on this computer in the background",5,"SMS Client Software Installation",1)
    'wscript.echo intbutton
    If intButton = 2 Then
        objWshShell.LogEvent 1, "SMS Client installation was cancelled by the user"
        wscript.quit
    End If

 'copy files to local computer and begin client installation
 Do While objFSO.FolderExists(sFolder) <> TRUE
  CreateFolder sFolder
  WScript.Sleep 10000
 Loop

 'copy files
 'Check for files before continuing to next file
 Do While objFSO.FileExists(sFolder & "\SMSCLIENT.VBS") <> TRUE
  objFSO.CopyFile sCurrentPath & "\SMSCLIENT.VBS", sFolder & "\", TRUE
  wscript.sleep 2000
 Loop
 
 Do While objFSO.FileExists(sFolder & "\Client.msi") <> TRUE
  objFSO.CopyFile sCurrentPath & "\client.msi", sFolder & "\", TRUE
  wscript.sleep 2000
 Loop
 
 Do While objFSO.FileExists(sFolder & "\ccmsetup.exe") <> TRUE
  objFSO.CopyFile sCurrentPath & "\ccmsetup.exe", sFolder & "\", TRUE
  wscript.sleep 2000
 Loop
 
    'now run sms client install
    Set oExec = objWshShell.Exec("wscript.exe " & sFolder & "\SMSCLIENT.VBS")

    Do While oExec.Status = 0
      WScript.Sleep 1000
    Loop

 'delete the folder by adding command to the Runonce key
 'CMD.exe /c "RD /s /q c:\SMSCLIENTINSTALL"
 objWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\SMS", "CMD.EXE /c " & CHR(34) & "RD /s /q C:\SMSCLIENTINSTALL" & CHR(34), "REG_SZ"

Else
    'Computer has client, quit
 wscript.quit
End If

Function CreateFolder(folder)
   Dim ofso, f
   Set ofso = CreateObject("Scripting.FileSystemObject")
   Set f = ofso.CreateFolder(folder)
   CreateFolder = f.Path
End Function

Sub DeleteAFolder(filespec)
   Dim ofso
   Set ofso = CreateObject("Scripting.FileSystemObject")
   ofso.DeleteFolder filespec,TRUE
End Sub