First up I would like to point people towards the following post by the Dynamics team as a starting point for installing CRM via SMS or SCCM. The post covers many of the aspects you will need to think about when deploying CRM such as how to include the .net prerequisite files so that the clients don’t download them from the Internet each time. So why am I writing another post covering potentially old ground? Well there is a major “bug” in the basic dynamics installer (Clientsetup.exe”) that really affects automated installations. When the clientsetup.exe is run by SCCM it runs all the pre-requisite checks and then fires away the client.msi install, before the msi file has finished clientsetup.exe exits and therefore does not return a valid status code to SCCM (-2 is returned). This makes SCCM think that the installer has failed to complete correctly and so you only ever end up with “failed” deployments.  Thanks to EnglishKeith over at the MS forums for figuring out why the installer does not work and for giving me the basis for my script.


So my solution to this problem is to wrap the actual clientsetup.exe installer up inside a VBscript, the VBscript executes the client side install and then waits 10 seconds at a time (for upto 20 minutes) looking for the shortcuts to appear on the start menu for CRM. When the shortcuts appear it concludes that CRM has installed correctly and then returns a valid exit code of 0 to SCCM. If after 20 minutes there have been no shortcuts detected it exits with a code of –2 so that the deployment is marked as incomplete.


On error resume next
Set objShell = CreateObject("Wscript.Shell")
Set objfso = CreateObject ( "scripting.FileSystemObject" )
dim strComputer
dim alluserpath
dim timer
dim installed
dim currentdirector
dim exitcode
currentdirectory = objShell.CurrentDirectory
alluserpath = objshell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
strComputer = "."
timer = 0
installed = 0
exitcode = -2
'run install program
CRMClient = Chr(34) & currentdirectory & "\SetupClient.exe " & Chr(34) & "/q" &Chr(34) CRMClient,1,true
'reset timer
timer = 0
do while timer < 120
	If objfso.Fileexists(alluserpath & "\Start Menu\Programs\Microsoft Dynamics CRM 4.0\Configuration Wizard.lnk") = False Then
		timer = timer + 1
		wscript.sleep (10000)
		exitcode = 0
		timer = 121
	end if

Deployment Scenario

In my organisation our deployment scenario called for CRM to be installed but not configured at the same time, for this reason I did not see the point in using the batch file as created by the Dynamics Team which restarts the machine, also I was unsure about how the batch file would pass back any exit codes generated by the install program. Our install was assigned to run at next logon with no user notification, it runs with elevated privileges but only runs when the user is logged in.The next step in my deployment is to configure the user options but as we are now using roaming profiles we will instruct our users how to do this onetime setup rather than using XML files.


Obviously there are a few big potential sticking areas with the script in this post that might cause issues during deployment, looking for the shortcuts to be created is by no means a foolproof way of detecting a valid install for a start. In theory it should be possible to modify the Dynamics Team VBscript that reads the created log file and return error codes based on its contents but I did not have the time to implement that. Hopefully although the solution posted above is “quick and dirty” it should do the job and help with any CRM deployments.

Finally I just wanted to pass comment on the behavior of the clientsetup.exe installer program, I find it incomprehensible that this program behaves as it does. It was my understanding that one of Microsoft’s requirements for new enterprise products was that they were compatible with SCOM and SCCM, yes the install works but it is very bad behavior to return false information from the installer and it seems so unnecessary.

[tags]vbscript, crm 4.0,SCCM 2007[/tags]