Solved

vb script error 0x80041021

Posted on 2014-09-13
1
1,129 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

912 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now