Solved

vb script error 0x80041021

Posted on 2014-09-13
1
1,225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

732 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