Error code, 80041021 occurs when you execute a VBScript connecting to WMI
(Windows Management Instrumentation). A wild guess there is a missing
\\ in the winmgmts statement.
The Symptoms you get
The script does not manipulate the WMI object as you had hoped, instead you get a Windows Script Host error message like this picture:
The Cause of Code 80041021
Case 1
Your VBScript contains a misspelled object name. Code 80041021 is an
unusual Error in that a number is returned rather than 'Syntax Error' or
other message. In my example the fault was in a WMI script, the cause
was a syntax error with Set objWMI = GetObject("winmgmts:"
Case 2
In another example, I had the reverse problem, I put: \\ machinename
in the string variable, whereas I should have used plain: machinename.
Case 3
I removed the impersonationLevel=impersonate statement from the VBScript.
Wrong Set objWMIService = GetObject("winmgmts:" _ &
strComputer & "\root\cimv2")
The Solutions
I solved this 80041021 error message by paying close attention to the line number. In
addition, I compared the scripts to other WMI examples. In one case it turned out to
be a missing \\ in Set objWMI = GetObject("winmgmts:\\"..... In another case it was a missing & "{impersonationLevel=impersonate}!\\" _
' ----------------------------------------
' Section to create folder to hold file.
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolder) Then
Set objFolder = objFSO.GetFolder(strFolder)
Else
Set objFolder = objFSO.CreateFolder(strFolder)
Wscript.Echo "Folder created " & strFolder
End If
Set strFile = objFso.CreateTextFile(strPath, True)
'--------------------------------------------
' Next section creates the file to store Events
' Then creates WMI connector to the Logs
Set objWMI = GetObject("winmgmts:" _ & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMI.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'System'" )
Wscript.Echo " Press OK and Wait 30 seconds (ish)"
' -----------------------------------------
' Next section loops through ID properties
intEvent = 1
For Each objEvent in colLoggedEvents
If objEvent.EventCode = intNumberID Then
Try
a different solution, download SolarWinds ipMonitor
Here is my thinking,
ipMonitor will give you valuable data about your network and servers.
This extra information just may unlock the solution to your error code.
One more thing, sometimes when troubleshooting you go around in circles;
therefore if you try a different, but related approach, you may just crack the
problem.
Free Download
of SolarWinds ipMonitor
Their topics and material are ideal for getting you started with VBScript. The
videos are easy to follow and you can control the pace. Try their free demo material and then see if you want to buy the full package.
See more about VB Script Training CD.