Solved

vb script error 0x80041021

Posted on 2014-09-13
1
1,080 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This is about my first experience with programming Arduino.
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 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 …

762 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

7 Experts available now in Live!

Get 1:1 Help Now