?
Solved

vb script error 0x80041021

Posted on 2014-09-13
1
Medium Priority
?
1,290 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 2000 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

Technology Partners: 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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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