Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 0x80041002 1

Status
Not open for further replies.

BKearan

IS-IT--Management
Sep 27, 2007
45
US
Getting an Error: 0x80041002 Code: 80041002 Source: (null)
in scripts on some computers (not others).

here is a snippit
Code:
strPCName = "."

Dim objWMIService, Err, objProcess, strShell, objProgram, searchkey
Dim strDisplayName, strDisplayVersion, strUninstall, strUninstallf
Dim subkey, oReg, arrSubKeys, strKeyPath, NValueName, VValueName, UValueName, intTest, intTest2

	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 'The path in the Registry needed to search
	NValueName = "DisplayName"
	VValueName = "DisplayVersion"
	UValueName = "UninstallString"
	' On Error Resume Next
	Set oReg = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" _
& strPCName & "\root\default:StdRegProv")
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	For Each subkey In arrSubKeys
	searchkey = strKeyPath & "\" & subkey

The error is hitting on the "Set oReg = " line. I've copied it directly from all kinds of VBScript sites, with and without the ") _" line breaks and it keeps getting this error. So, it is NOT the syntax of the line (since it works on some computers) The OS is XP on computers it works on and ones it doesn't.

From one site : (
"The Cause of Code 80041002

Your VBScript contains a misspelled object name. Code 80041002 is an unusual Error in that a number is returned rather than 'Syntax Error' or other message.
The Solutions

Check the class definitions in the WMI section of the your script, check for extra letters, plurals can be a particular problem, e.g. system or systemS. Note: The Line: 4 Char: 1 In this case it Char: 1 is not to blame. When none of the line can execute, the error gets charged to the first character."

Which is NOT the case from all research I've done. (no misspellings).
.
So, WHAT is happening?
:O
 
also used :
Code:
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv")

and other variations of the line.
 
Well, my guess is it doesn't like the computername defined as "."

So how about changing the first four lines to this:
Code:
option explicit
Dim objWMIService, Err, objProcess, strShell, objProgram, searchkey
Dim strDisplayName, strDisplayVersion, strUninstall, strUninstallf
Dim subkey, oReg, arrSubKeys, strKeyPath, NValueName, VValueName, UValueName, intTest, intTest2
Dim WshNetwork, strPCName

Set objNetwork = CreateObject("WScript.Network")
strPCName = objNetwork.ComputerName
[tt]option explicit[/tt] can be annoying but it's annoying for a damn good reason as it'll help errors caused by mistypes of variable names (e.g. strSystems instead of strSystem)

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
The Script in question is supposed to run through the local registry and uninstall old versions of Java, but not IBM java.
Below is the Full Script. "java" can be changed to look for pretty much anything, it just needs to have a MSIExec.exe uninstall based string to uninstall silently. Which is why I exclude the IBM Java, which has it's own funky uninstall string.

Code:
Option Explicit

Const JobSleep = 92000				'Time to sleep between jobs, in milliseconds
Const HKEY_LOCAL_MACHINE = &H80000002
Dim objFSO, strFileEntry, strPCName
Dim ListFile, LogFile, strPCDN, strRem1, strRem2, strRem3, strRem4, strRem5, strRem6
Dim objWMIService, objProcess, strShell, objProgram, searchkey
Dim strDisplayName, strDisplayVersion, strUninstall, strUninstallf
Dim subkey, oReg, arrSubKeys, strKeyPath, NValueName, VValueName, UValueName, intTest, intTest2

' Change text inside quotes after strDisplayName to text to search displayname for
' Make sure the uninstall string will be a MSIExec.exe uninstall to make it silent.
' I've included something to make sure the /I is replaced with /X to do the uninstall with MSIExec.exe


	strPCName = "."

RegistryPull(strPCName)

wscript.quit

Function RegistryPull(strPCName)
	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 'The path in the Registry needed to search
	NValueName = "DisplayName"
	VValueName = "DisplayVersion"
	UValueName = "UninstallString"	
	' On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strPCName & "\root\default:StdRegProv")
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	For Each subkey In arrSubKeys
	searchkey = strKeyPath & "\" & subkey
	  oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, NValueName, strDisplayName
      oReg.GetStringValue HKEY_LOCAL_MACHINE, searchkey, VValueName, strDisplayVersion
      oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, searchkey, UValueName, strUninstall
     intTest=InStr(strDisplayName,"Java")
       	If intTest <> 0 and intTest <> "" Then
       	intTest2=InStr(strDisplayName,"IBM")
       		If intTest2 = 0 or intTest = "" Then
    			If strDisplayVersion <> "1.6.0.30" and strDisplayVersion <> "6.0.30.5" Then
    			strUninstallf = Replace(strUninstall,"/I","/X")
    			wscript.echo strUninstallf
    			'Block to execute Uninstall
    			Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
				Set objProcess = objWMIService.Get("Win32_Process")
				Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_
				objProgram.CommandLine = strUninstallf & " /qn"
				Set strShell = objWMIService.ExecMethod("Win32_Process","Create",objProgram)
				WScript.Sleep(JobSleep)
    			End If
    		End If
    	End If
	Next

Set objWMIService = Nothing
End Function
 
Setting the computername to . is perfectly valid. . jsut means "loacl Machine". If you are getting the error when you try to get the standard reg provider I would look at potential WMI corruption. Search google for WMI diagnosis. There is a script that MS released that does a very detailed analysis of the health of your WMI repository.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
JPJeffery,
The computer name being "." is what all the refrence docs I've found do. I did change the lines to your suggestion, but still got the same error.
Refrence :

A similar script that just looks for "CA Uni" instead of "Java" is working on remote computers. I am trying to test the script on a couple PCs and getting this problem.
I'm wondering if WMI is disabled or ... I dunno... impersonation level?? (I am administrator) I've changed the line to
Code:
Set oReg=GetObject("winmgmts:\root\default:StdRegProv")
and
Code:
Set oReg=GetObject("winmgmts:\\.\root\default:StdRegProv")
and even put in the actual computer name....
Code:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPCName & "\root\cimv2")
gets the same error... (with and without the "{impersonationLevel=impersonate}!" included.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top