Jul 22, 2008

Posted by in Tech Tips | 5 Comments

Installing CRM 4.0 with SCCM

Introduction

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.

Solution

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.

Code

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)
objShell.run 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)
	else
		exitcode = 0
		timer = 121
	end if
loop
 
WScript.Quit(exitcode)

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.

Conclusion

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]

  1. Your code has some syntax errors in it:

    &
    should simply be
    &

    and
    <
    should be
    <

    VBSCRIPT does not recognise semi-colons.

    But everything else worked fine for us.

    Thanks.

  2. Hi,
    Thanks made the changes – the site is trying to convert the chars into html tags as I paste the code in.

    Once again sorry for that!

    Ben.

  3. I am installing CRM 4 from SCCM with a vbscript which calls all of the components. i have it set to install as an administrator for that program, but when it calls the setupclient.exe it hangs. Any ideas as to why that would happen? If I log in as an admin and browse through explorer to the location that sccm is calling and run the script, everything runs fine. So it must have to do with this being installed by System.

  4. Hi,
    Do you have any more information about what hangs? Here are a few things to try:

    Do you know the VBscript functions correctly when not run in SCCM?
    On the server hosting setupclient.exe can you see the user accessing the shared resource?
    Can you see the process running in memory?
    From a “run as” prompt running with the SCCM install account does the vbscript work?

    Hope that helps as a starting point for you…

    Ben

  5. Hi there,

    I stumbled accross this post as we’re trying to deploy CRM via SCCM and get the -2 exit code problem. Ive tried using your script but for some reason wscript stays active in task manager and continually runs causing the job to eventually fail also.

    because im no vbscript expert, can you point me in the right direction as to what needs to be done with the code above for the script to work correctly?

    Thanks,
    Chris

Leave a Reply

Your email address will not be published. Required fields are marked *