/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Excel add-in vbs load

11/25/2015 1770 views

Hi Gents

I have a fleet of 32 and 64 bit windows 7 machines. I have an addin that changes location path based the OS version e.g C:\program files (x86) or C:\program files\


I can't use PowerShell to do it, and this has to be done by vbs


I've come up with the below however, the script doesn't seem to differentiate between 32bit C:\program files (x86) or 64bit C:\program files path.


What I want is this script to work out if the machine is 32 bit or 64 bit and based on that install the add-in e.g C:\program files (x86)\MyApp1 or C:\program files\Myapp1


I'm been racking my brain but I'm not that best in vb, any help would be appreciated it.

On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\default:StdRegProv")
   strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
   strValueName = "Identifier"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
 if (instr(strValue,"64")) then

 Set objShell = CreateObject("WScript.Shell")
 strPlugin = """C:\Program Files (x86)\Datastream\Datastream Advance\AdvanceOffice.xlam""" 'This is the name of your Excel Addin
 strExcelRegistryKey = "HKCU\Software\Microsoft\Office\14.0\Excel\Options" 'Becareful of your Office version here!
 intCount = 0
 intCompleted = 0
 If objShell.RegRead(strExcelRegistryKey & "\Open") = "" Then
 objShell.RegWrite strExcelRegistryKey & "\Open", strPlugin, "REG_SZ"
 intCompleted = 1
 End If 
  If intCompleted <> 1 Then
  Err.Clear
 Do Until Err.number = -2147024894
  intCount = intCount + 1
 strRegKey = strExcelRegistryKey & "\Open" & intCount
 strRegKeyValue = objShell.RegRead(strRegKey)
 Loop
 objShell.RegWrite strExcelRegistryKey & "\Open" & intCount, strPlugin, "REG_SZ"
 End If
 Set objShell = Nothing
Else '32 bit OS detected
 Set objShell = CreateObject("WScript.Shell")
 strPlugin = """C:\Program Files\Datastream\Datastream Advance\AdvanceOffice.xlam""" 'This is the name of your Excel Addin
 strExcelRegistryKey = "HKCU\Software\Microsoft\Office\14.0\Excel\Options" 'Becareful of your Office version here!
 intCount = 0
 intCompleted = 0
 If objShell.RegRead(strExcelRegistryKey & "\Open") = "" Then
 objShell.RegWrite strExcelRegistryKey & "\Open", strPlugin, "REG_SZ"
 intCompleted = 1
 End If 
  If intCompleted <> 1 Then
  Err.Clear
 Do Until Err.number = -2147024894
  intCount = intCount + 1
 strRegKey = strExcelRegistryKey & "\Open" & intCount
 strRegKeyValue = objShell.RegRead(strRegKey)
 Loop
 objShell.RegWrite strExcelRegistryKey & "\Open" & intCount, strPlugin, "REG_SZ"
 End If
 Set objShell = Nothing
End if

1 Comment   [ + ] Show comment

Comments

  • I am using the next function to detect the OS architecture:
    'Usage
    If WinArchitecture("AMD64") Then
    msgbox "You are using a x64 OS"
    End If

    If WinArchitecture("x86") Then
    msgbox "You are using a x86 OS"
    End If

    'Function
    Function WinArchitecture(strWinArch)
    Dim strArch
    Dim objEnvSys
    Dim objWSH

    Set objWSH = CreateObject("WScript.Shell")
    Set objEnvSys = objWSH.Environment("System")

    strArch = objEnvSys("PROCESSOR_ARCHITECTURE")

    If UCase(strArch) = UCase(strWinArch) then
    WinArchitecture = True
    Else
    WinArchitecture = False
    End If
    End Function


Community Chosen Answer

3
Firstly, there is an excellent script here on IT Ninja for installing Excel add-ins. It's designed to run as a Custom Action in an MSI but could easily be adapted. Search for 'Captain Planet'.

Secondly, I'll bet my last dollar that the add-in is resolutely 32-bit only so, irrespective of whether the OS is 64-bit or 32-bit, it should be installed to the 32-bit location.
Answered 11/25/2015 by: VBScab
Red Belt

All Answers

0
You are correct it's a 32 bit addin but the problem I'm seeing is running the script as a active setup it will try to find in either path depending on the OS. If I install in 32 it will be c:\program files\myapp\myaddin or 64 c:\program files (x86)\myapp\myaddin hence I have to know what path location to look for it. Maybe I'm missing something or there is a better way of doing it? My check out captain planets guide
Answered 11/25/2015 by: djjass
Senior Purple Belt

0
There is a script that Darwin Sanoy has published which will detect whether the CPU is 32 bit or 64 bit and also check other 32/64 bit parameters. I have used this extensively in packages, edited to my specific needs.  If I recall correctly it's on his site but not able to check ATM.
Answered 11/26/2015 by: EdT
Red Belt

0
I am using the next function to detect the OS architecture: 

'Usage
If WinArchitecture("AMD64") Then
    msgbox "You are using a x64 OS"
End If

If WinArchitecture("x86") Then
    msgbox "You are using a x86 OS"
End If

'Function
Function WinArchitecture(strWinArch)
Dim strArch
Dim objEnvSys
Dim objWSH
Set objWSH = CreateObject("WScript.Shell")
Set objEnvSys = objWSH.Environment("System")
strArch = objEnvSys("PROCESSOR_ARCHITECTURE")

If UCase(strArch) = UCase(strWinArch) then
WinArchitecture = True
Else
WinArchitecture = False
End If
End Function

Anyway, for installing and uninstalling Office Addins I recomand you to use Captain_Planet's VBScripts, you can find them here: http://www.itninja.com/question/automated-excel-add-ins , with all information needed.

Regards,
Mihai Terebent
Answered 11/27/2015 by: terebent
Second Degree Brown Belt

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ