Hi,
Below is a vbs script that will first check whether ccmexec.exe exist in C:\Windows\CCM. If yes, skip the installation. If no, proceed the installation.
First, copy the client folder and share the folder. Modify str_SiteCode, str_InstallString.
Option Explicit
On Error Resume Next
Dim oShell, objFSO, objFile1, objFile2, ADSysInfo, CurrentUser, wshNet, oSMSClient
Dim sysdir, compname, username, strGroups, sitename, strDiscoverSite, strTemp, message
Dim str_SiteAssignmentText,str_SCCMInstallLogFile ,str_InstallString, str_SiteCode
Set wshNet = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set oShell = WScript.CreateObject("WScript.Shell")
sysdir = oshell.ExpandEnvironmentStrings("%systemroot%")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////
'
' KEY IN YOUR PARAMETERS HERE
str_SiteCode = "XXX"
str_InstallString = "\\SERVER.domain.com\Client\ccmsetup.exe SMSSITECODE=XXX /source:\\SERVER.domain.com\client /mp:SCCMSERVER.domain.com FSP=SCCMSERVER.domain.com"
'
'
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Check whether or not ccmexec.exe file exists, if yes return client site assignment for checking
If objFSO.FileExists(sysdir & "\ccm\ccmexec.exe") Then
'Wscript.echo "Agent already installed " & sitename
Set oSMSClient = CreateObject ("Microsoft.SMS.Client")
sitename = oSMSClient.GetAssignedSite
If err.number=-2147221502 then
sitename = "Not assigned"
End If
If sitename <> str_SiteCode then
'Wscript.echo "Current site assignment is " & sitename
'strDiscoverSite = str_SiteCode
'Call SetAssignedSite (strDiscoverSite)
'Wscript.echo "Installing the Client now " & sitename
oShell.Run str_InstallString
WScript.Sleep 5000
'strTemp = oSMSClient.GetAssignedSite
'If LCase(strTemp) = LCase(strDiscoverSite) Then
'message = "Successfully assigned site code to " & strDiscoverSite
'Else
'message = "Unable to set assigned site code to " & strDiscoverSite & ". Attempting WMI repair"
'Call RepairWMI
'End If
End If
Set oSMSClient=Nothing
Else
set objFile2 = objFSO.OpenTextFile(str_SCCMInstallLogFile, ForAppending, true)
compname = oshell.ExpandEnvironmentStrings("%computername%")
username = oshell.ExpandEnvironmentStrings("%username%")
'Wscript.echo "Installing the Client now " & sitename
oShell.Run str_InstallString
End If
Sub SetAssignedSite (SiteCode)
'Wscript.Echo "About to assign site code to " & SiteCode
oSMSClient.SetAssignedSite SiteCode,0
End Sub
Sub RepairWMI
'Wscript.Echo "Attempting to repair WMI"
oShell.Run "rundll32 wbemupgd, UpgradeRepository"
End Sub
Regards,
Hau