Excel add-in vbs load
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
Answers (4)
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.
Comments:
-
.... - Badger 9 years ago
'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 - terebent 8 years ago