CScript Visual C++ Runtime Library Error
Last week I had interesting issue with running cscript to execute wsf jobs on a Windows Server 2003 x64 Edition Server running SQL Server 2005. Every time Cscript ran, a Microsoft Visual C++ Runtime Library Error popped up.
Error Details:
——————————————
Runtime Error!
Program: C:\winnt\system32\cscript.exe
R6034
An Application has made an attempt to load the C runtime library incorrectly. Please contact the application’s support team for more information.
—————————————————————————–
We have five other SQL Server that run the same job, so I know the job works. In order to find out what was going on, I ran Process Monitor to see what dlls are being called by cscript. As you can see from the error, the Microsoft Visual C++ Runtime library was being called from the Microsoft SQL Server Tools\Binn directory. CScript should be calling the msvcr80.dll from the C:\winnt\WinSxS directory as noted in the screen shot below. (I ran the job and Process Monitor on a system where the job ran correctly.)
Now that we know that the incorrect msvcr80.dll is being called, we need to figure out why and how to correct it.
Microsoft WinSxs Directory is for Side-by-Side assemblies and dlls. The Windows Kernel works with Fusion to find the correct dll needed for the application. (Learn more about Fusion). In the case of the working system, fusion was finding the correct msvcr80.dll.
The Result:
The wsf script called SQLDMO.dll for a function call. The working system had an updated version of the dll with a Manifest which pointed to the correct msvcr80.dll.
The problem system had an older version of the dll with no Manifest, so the closest msvcr80.dll was being used after SQLDMO.dll was called.
To fix, The SQLDMO.dll was updated to the latest version and the problem was solved.
With this issue, using Process Monitor was the best tool to figure out what the problem system and the control system were doing since it pointed out the different msvcr80.dlls being used.
The many ways to control Windows Services
I’m often asked how windows services are controlled in the enterprise. There is a variety of convenient ways to control services, each with strengths and weeknesses. We’ll go through some of them today.
1. The services.msc MMC is the nice GUI provided by windows. This features a very intuitive interface, but can only connect to one system at a time. This is not very scalable if you need to shut down many services on multiple machines.
2. net start, net stop etc.. This is the original command line version to control services. Good when you are on the system. This is scriptable via a batch file. This command came with Windows NT.
3. sc.exe comes with the Windows Resource Kit. This is a great tool and allows to control services on remote machines. Setting up services can also be done with this tool.
4. PS Service (psservice.exe) from the PS Tools Suite, authored by Mark Russinovch. psservice runs on the command line like sc.exe and shares some of the same features like controlling services on remote machines. One advantage is displaying the security descriptor in a readable format.
5. WMI or Windows Management Instrumentation can control services. WMI can be programmed from VBScript, c# (.NET) and PowerShell. Flow control can be quickly executed with any of the mentioned programming languages giving administrators precise control over which services and systems need to have services controlled. Below is an example of some VBScript functions starting and stopping services via WMI. These functions also start/stop the dependate services which is important.
Function StopServiceWMI(strServiceName)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='" & strServiceName & "'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For each objService in colServiceList
objService.StopService()
Next
Wscript.Sleep 5000
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='" & strServiceName & "'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
End Function
Function StartServiceWMI(strServiceName)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='" & strServiceName & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 5000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='" & strServiceName & "'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
End Function
5. One of the last methods is to use the native Get-Service PowerShell CmdLet. To understand what Get-Service can do. Type in Get-Help Get-Service in the PowerShell command prompt. You can resume, start, stop, restart, suspend, set service properties and create a new service. PowerShell does not currently have remoting capabilities, so all CmdLets are executed on the local server. PowerShell V2 will have remoting capability using WS-MAN, but that will be a topic for another time.
I hope you’ve enjoyed the quick tour with controlling Windows Services. Automation is the key to success in the enterprise.
Mojave Experiment
Microsoft is tired of hearing it’s rebel teen-ager, Apple, poke and prod that the Apple OS is better than Windows. The Mojave Experiment is focus group like marketing event where Microsoft asks for user input on the “next” Windows OS called Mojave. Many people comment that the new OS is “Sexy”, “Easy to Use” and that it “Makes me want to use a computer more often.” Then Microsoft pulls the rug and says this is Vista. Most people are shocked.
This is certainly a clever way to help mitigate the Windows Vista perception issue. This is done is a way that is not directly goading Apple, which is the right move for Microsoft. Microsoft shouldn’t respond back in kind to Apple with similar ads, that would only ligitamize Apple’s campaign. It really is a perception problem at this point. Vista SP1 fixed many concerns about the OS. There is still the lingering “Vista Ready” issue, but that is dying out in the news.
Personally, I have a Vista partition and an XP partition. I use Vista for development, Office, Email etc. On the XP partition I run VMWare workstation. Vista Ultimate takes up too much RAM to run a VM and Vista with 1.5GB RAM. Maybe it’s time to upgrade the PC?




