Solved

vb script error 0x80041021

Posted on 2014-09-13
1
1,184 Views
Last Modified: 2014-09-13
hi

when i run this script i got all the time this error 0x80041021
Please help !!!


'================================================================================================      
' Script Section
' First step - Check OS Version
' Second step - Detect 32-bit or 64-bit
' Third Step - Check if Pre Requirement for TSMBAClient installation is installed
'================================================================================================      
'On Error Resume Next
'================================================================================================      
'** GENERAL VARIABLE DECLARATIONS
'================================================================================================      
'Dim strComputerName,strOSVersion,OsType
'Dim strKey32bit,strKey64bit

 
const HKEY_LOCAL_MACHINE = &H80000002
Const AppName = "Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219"
Const AppName1 = "Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219"
Const AppName2 = "Microsoft Visual C++ 2012 x86 Additional Runtime - 11.0.51106"
Const AppName3 = "Microsoft Visual C++ 2012 x64 Additional Runtime - 11.0.51106"


Set objShell = WScript.CreateObject ("WScript.Shell")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"& strComputer & "\root\default:StdRegProv")

strComputerName = "."
StrOSVersion = getOSVersion(strComputerName)
OsType = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
strKey64bit = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strKey32bit = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

'============================================================================================================================
' Windows 2008 R2
'============================================================================================================================
If (instr(strOSVersion,"6.1")) Then

      objReg.EnumKey HKEY_LOCAL_MACHINE, strKey32Path, arrSubKeys
            For Each subkey In arrSubKeys
                  InstalledAppName = ""
                  InstalledAppName = objShell.RegRead("HKLM\" & strKey32bit & "\" & subkey & "\DisplayName")
            If InStr(InstalledAppName, AppName) > 0 Then
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x86_2010.exe"" /q /norestart",0,1
                  End If
            If InStr(InstalledAppName, AppName2) > 0 Then      
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x86_2012.exe"" /q /norestart",0,1
                  End If
            Next      
            objReg.EnumKey HKEY_LOCAL_MACHINE, strKey64Path, arrSubKeys
            For Each subkey In arrSubKeys
                  InstalledAppName = ""
                  InstalledAppName = objShell.RegRead("HKLM\" & strKey64bit & "\" & subkey & "\DisplayName")
            If InStr(InstalledAppName, AppName1) > 0 Then
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x64_2010.exe"" /q /norestart",0,1
                  End If
            If InStr(InstalledAppName, AppName4) > 0 Then      
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x64_2012.exe"" /q /norestart",0,1
                  End If
            Next      
End If

'============================================================================================================================
' Windows 2008
'============================================================================================================================
If (instr(strOSVersion,"6.0")) Then
      If OsType = "AMD64" Then 'Windows 2008 64Bit
            wscript.echo  "Windows 64bit system detected"
      elseif OsType = "x86" Then 'Windows 2008 64Bit
            wscript.echo  "Windows 32bit system detected"
      end if
end if
'============================================================================================================================
' Windows 2003
'============================================================================================================================
If (instr(strOSVersion,"5.2")) Then
      If OsType = "AMD64" then 'Windows 2003 64Bit
            wscript.echo  "*Windows 64bit system detected"
      elseif OsType = "x86" Then 'Windows 2003 32Bit
            wscript.echo  "*Windows 32bit system detected"
      end if
end if
'============================================================================================================================
Function getOSVersion(strComputerName)
      strComputerName = "."
      set objWmi = GetObject("winmgmts://" & strComputerName & "/root/cimv2")
      set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
      for Each objItem in colItems
            strOSVersion = left(objItem.Version, 3)
      Next
      getOSVersion = strOSVersion
End Function
0
Comment
Question by:David Regev
1 Comment
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 500 total points
ID: 40321144
Your problems are being caused because you are not being consistent with the use of your variable names.  I recommend adding Option Explicit to the start of your script.

First off, you use strComputer before you ever assign a value.  After you use it, your assign a value to strComputerName which is not used in the main section of the script.  You also use strKey32Path without a definition.

As a side note, it is best to put code in a code snippet window.  (Just click the word code in the format bar)

Try this updated code - I cleaned up several of your variable names.  (Again Option Explicit helped me find all of them.  Also, I prefer to write vbscript within notepad++ as it gives some nice intellisense capabilities for vbscript to help in this kind of instances.)

Option Explicit	

'================================================================================================      
' Script Section
' First step - Check OS Version
' Second step - Detect 32-bit or 64-bit
' Third Step - Check if Pre Requirement for TSMBAClient installation is installed
'================================================================================================      
'On Error Resume Next
'================================================================================================      
'** GENERAL VARIABLE DECLARATIONS
'================================================================================================      
Dim strComputer, strOSVersion, OSType, strKey32bit, strKey64bit
Dim objShell, objReg, objItem, objWMI, arrSubKeys, subkey, strInstalledAppName
 
const HKEY_LOCAL_MACHINE = &H80000002
Const AppName = "Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219"
Const AppName1 = "Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219"
Const AppName2 = "Microsoft Visual C++ 2012 x86 Additional Runtime - 11.0.51106"
Const AppName3 = "Microsoft Visual C++ 2012 x64 Additional Runtime - 11.0.51106"

strComputer = "."
Set objShell = WScript.CreateObject ("WScript.Shell")
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    
StrOSVersion = getOSVersion(strComputer)
OsType = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
strKey64bit = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strKey32bit = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

'============================================================================================================================
' Windows 2008 R2
'============================================================================================================================
If (instr(strOSVersion,"6.1")) Then

      objReg.EnumKey HKEY_LOCAL_MACHINE, strKey32bit, arrSubKeys
            For Each subkey In arrSubKeys
                  strInstalledAppName = ""
                  strInstalledAppName = objShell.RegRead("HKLM\" & strKey32bit & "\" & subkey & "\DisplayName")
            If InStr(strInstalledAppName, AppName) > 0 Then
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x86_2010.exe"" /q /norestart",0,1
                  End If
            If InStr(strInstalledAppName, AppName2) > 0 Then      
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x86_2012.exe"" /q /norestart",0,1
                  End If
            Next      
            objReg.EnumKey HKEY_LOCAL_MACHINE, strKey64Path, arrSubKeys
            For Each subkey In arrSubKeys
                  strInstalledAppName = ""
                  strInstalledAppName = objShell.RegRead("HKLM\" & strKey64bit & "\" & subkey & "\DisplayName")
            If InStr(strInstalledAppName, AppName1) > 0 Then
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x64_2010.exe"" /q /norestart",0,1
                  End If
            If InStr(strInstalledAppName, AppName4) > 0 Then      
                  objShell.Run """\\servername\install$\Programs Install\Servers\TSM\Prerequisites\vcredist_x64_2012.exe"" /q /norestart",0,1
                  End If
            Next      
End If

'============================================================================================================================
' Windows 2008
'============================================================================================================================
If (instr(strOSVersion,"6.0")) Then
      If OsType = "AMD64" Then 'Windows 2008 64Bit
            wscript.echo  "Windows 64bit system detected"
      elseif OsType = "x86" Then 'Windows 2008 64Bit
            wscript.echo  "Windows 32bit system detected"
      end if
end if
'============================================================================================================================
' Windows 2003
'============================================================================================================================
If (instr(strOSVersion,"5.2")) Then
      If OsType = "AMD64" then 'Windows 2003 64Bit
            wscript.echo  "*Windows 64bit system detected"
      elseif OsType = "x86" Then 'Windows 2003 32Bit
            wscript.echo  "*Windows 32bit system detected"
      end if
end if
'============================================================================================================================
Function getOSVersion(strComputerName)
	Dim colItems
      strComputerName = "."
      set objWmi = GetObject("winmgmts://" & strComputerName & "/root/cimv2")
      set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
      for Each objItem in colItems
            strOSVersion = left(objItem.Version, 3)
      Next
      getOSVersion = strOSVersion
End Function 

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question