如何检测当前机器中是否安装Office 及其版本??

原创 2006年06月21日 10:32:00

'作者:CSDN 许仙
'Homepage : jjweb.126.com
'MSN :Coderxu#hotmail.com
'QQ:19030300
'转载请保持文章完整,保存以上作者信息 请珍惜他人劳动成果

Option Explicit

Const REG_EXPAND_SZ = 2
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const ERROR_SUCCESS = 0&

Const RegLocation = "software/UnpreXisten/Online Code Browser/"
Const RegKey = HKEY_LOCAL_MACHINE
Dim AppVer As String * 8

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long

Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long

Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long

Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Const REG_SZ = 1
Const REG_DWORD = 4

Public Enum OfficeVer
    Office_97
    Office_2000
    Office_xp
    Office_2003
End Enum
'<CSCM>
'--------------------------------------------------------------------------------
' 工 程 名:  工程1
' 函 数 名: GetString
' 变    量 :  OfKind (OfficeVer)
' 输    入:无
' 输    出:OFFICE 的路径
'我的机器没有OFFICE xp 根据97 200 2003的关系
'可以看出键值为"HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Office/10.0/Common/InstallRoot"
' 日    期 : 2005-7-5
' 作    者 :    许仙
'--------------------------------------------------------------------------------
'</CSCM>
Public Function GetOfficePath(OfKind As OfficeVer) As String

    Dim lValueType
    Dim keyhand As Long, r
    Dim datatype As Long
    Dim lResult As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim intZeroPos As Integer, StrKeyName$

    Select Case OfKind

        Case 0
            r = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Office/8.0/Common/InstallRoot", keyhand)
            StrKeyName = "OfficeBin"

        Case 1
            r = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Office/9.0/Common/InstallRoot", keyhand)
            StrKeyName = "Path"

        Case 2
            r = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Office/10.0/Common/InstallRoot", keyhand)
            StrKeyName = "Path"

        Case 3
            r = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Office/11.0/Common/InstallRoot", keyhand)
            StrKeyName = "Path"

    End Select

    lResult = RegQueryValueEx(keyhand, StrKeyName, 0&, lValueType, ByVal 0&, lDataBufSize)

    If lValueType = REG_SZ Then

        strBuf = String(lDataBufSize, " ")
        lResult = RegQueryValueEx(keyhand, StrKeyName, 0&, 0&, ByVal strBuf, lDataBufSize)

        If lResult = ERROR_SUCCESS Then

            intZeroPos = InStr(strBuf, Chr$(0))

            If intZeroPos > 0 Then

                GetOfficePath = Left$(strBuf, intZeroPos - 1)

            Else

                GetOfficePath = strBuf

            End If

        End If

    End If

End Function

 

 

 

其他人写的方法  很不错的 方法 :)

http://blog.csdn.net/tanaya/archive/2005/04/29/368504.aspx

本函数运行不需要机器上安装过Office

获取当前Office版本的函数

Private Sub Command1_Click()
    MsgBox GetInstalledOfficeVersion()
End Sub

'本函数运行不需要机器上安装过Office
'经典的判断Office版本函数,原创!
'支持到Office 2003
Function GetInstalledOfficeVersion() As String
    On Error Resume Next
    Dim WD
    Dim OfficeVer As String
    OfficeVer = 0
    GetInstalledOfficeVersion = ""
    Set WD = CreateObject("Word.Application.8")
    OfficeVer = CStr(WD.Version)
    WD.quit
    If Not WD Is Nothing Then Set WD = Nothing
    If InStr(OfficeVer, "8") <> 0 Then
       GetInstalledOfficeVersion = "Office 97"
    ElseIf InStr(OfficeVer, "9") <> 0 Then
       GetInstalledOfficeVersion = "Office 2000"
    ElseIf InStr(OfficeVer, "10") <> 0 Then
       GetInstalledOfficeVersion = "Office XP 2002"
    ElseIf InStr(OfficeVer, "11") <> 0 Then
       GetInstalledOfficeVersion = "Office 2003"
    End If
    If Err.Number = 424 Then
       Err.Clear
       GetInstalledOfficeVersion = "没有安装 Microsoft Office"
    End If
End Function


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

排序算法比较

冒泡排序排序过程 图片演示 复杂度分析 C语言代码 插入排序排序过程 图片演示 复杂度分析 C语言代码 快排排序过程 图片演示 复杂度分析 C语言代码 算法 平均时间复杂度 最好情况 最...

C++开发面试常见问题总结

C++后台开发面试常见问题汇总(持续更新中)C和C++语言基础 extern关键字作用extern声明变量在在外部定义? extern修饰函数? extern C的作用?用法? static关键字作用...

声卡驱动ALSA安装指南

声卡驱动ALSA安装指南 ALSA最新版本下载http://download.linuxsir....
  • f5key
  • f5key
  • 2007-07-31 12:13
  • 257

解决头文件相互包含问题的方法

所谓超前引用是指一个类型在定义之前就被用来定义变量和声明函数。                 一般情况下,C/C++要求所有的类型必须在使用前被定义,但...

C/C++ 中头文件相互包含引发的问题

C/C++ 中头文件相互包含引发的问题 今天下午遇到一个头文件相互包含而导致的编译问题,花了我不少时间去调试没找到问题,最后晚上跟师兄讨论不少时间,突然有所顿悟! 问题重现 我把问题脱离于项目简...
  • hazir
  • hazir
  • 2014-08-16 00:39
  • 24643

怎样判断自己掌握了学到的新知识

以前一本书一本书地看,看到一种新东西,那种兴奋劲是不能用语言来形容的,但随之就觉得自己已经学会了这项新技术,感觉比别人高了一截子。任何写在纸上的东西,都是作者的心得体会,而我们看了,可能因为以前你也遇...
  • hazir
  • hazir
  • 2011-05-08 23:53
  • 1270

ASP中Connection对像封装dll解决方案

asp代码保密一直是令人头痛的问题,目前没有非常好的解决方案,无非用vb编译成dll,但工作量实在太大,于是一直苦苦寻求着另一种途径。。。  中午,突然灵感一发,“为什么不尝试用加密数据库?”,通过对...
  • cncco
  • cncco
  • 2006-12-24 22:29
  • 898
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)