我是谁?如何使用 Microsoft Office 权限/用户权限 [英] Who am I? How to use Microsoft Office Permission/UserPermission

查看:30
本文介绍了我是谁?如何使用 Microsoft Office 权限/用户权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft Office 文档,我的情况是:PowerPoint 演示文稿,可以具有受限权限.如何以编程方式找出我的代码对给定文档具有哪些权限?

Microsoft Office documents, im my case: PowerPoint presentations, can have restricted permissions. How can I find out, programmatically, which permissions my code has on a given document?

我可以在 MSDN 上找到关于这个主题的所有内容:http://msdn.microsoft.com/en-us/library/aa432118.aspx

All I can find on MSDN on this topic is this: http://msdn.microsoft.com/en-us/library/aa432118.aspx

如果我运行以下代码,我将获得对给定文档具有权限的用户列表:

If I run the following code, I get a list of users that have permissions on the given document:

Sub test()
    Dim perm As Office.Permission
    Set perm = ActivePresentation.Permission
    Debug.Print "Enabled=" & perm.Enabled
    If perm.Enabled Then
        Debug.Print "PermissionFromPolicy=" & perm.PermissionFromPolicy
        Debug.Print "PolicyName='" & perm.PolicyName & "'"
        Debug.Print "PolicyDescription='" & perm.PolicyDescription & "'"
        Dim uperm As Office.UserPermission
        For Each uperm In perm
            Debug.Print uperm.UserId & ", " & uperm.Permission
        Next uperm
    End If
End Sub

示例输出:

Enabled=True
PermissionFromPolicy=False
PolicyName='Do Not Distribute'
PolicyDescription='Permission is currently restricted. Only specified users can access this content.'
john@doe.com, 64
user@system.de, 33
myname@example.com, 33

权限"是一个位图,我在微软的公共 COM 头文件中找到了它的定义:

The "Permission" is a bitmap the definition for which I found in Microsoft's public COM header files:

enum MsoPermission
{
  msoPermissionView = 1,
  msoPermissionRead = 1,
  msoPermissionEdit = 2,
  msoPermissionSave = 4,
  msoPermissionExtract = 8,
  msoPermissionChange = 15,
  msoPermissionPrint = 16,
  msoPermissionObjModel = 32,
  msoPermissionFullControl = 64,
  msoPermissionAllCommon = 127
};

不过,这并没有告诉我我的代码具有哪些特定权限.如果我只知道我是谁(就 UserPermission.UserId 而言),我可以在 Permission 对象中查找我的权限.但是我找不到那一点信息.我错过了什么?

Still, this does not tell me which particular permissions my code has. If I only knew who I am (in terms of a UserPermission.UserId), I could look up my permissions in the Permission object. But I cannot find that bit of information. What am I missing?

有一些已知的方法可以获取 Windows 用户名(该 Windows 机器上当前用户的登录名).不幸的是,当 PowerPoint 决定我对文档拥有哪些权限时,这不是检查的用户 ID.强调一下:PowerPoint 提供了一个 UI,可让我在运行时更改我是谁".显然,这不会改变登录用户名(即 ADVAPI 返回的名称).PowerPoint 所指的用户名是通过 Microsoft 的 Passport 识别/授权的.

There are known ways to obtain the Windows user name (the login name for the current user on that Windows machine). Unfortunately, this is not the user id that is checked against when PowerPoint decides which permissions I have on the document. To emphasize: PowerPoint provides a UI that lets me change "who I am" at run time. Obviously, this does not change the login use name (i.e., the name returned by ADVAPI). The user names PowerPoint is referring to, are identified/authorized via Microsoft's Passport.

提前致谢!
沃尔克

Thanks in advance!
Volker

推荐答案

今天我收到了来自 Microsoft 的额外答复(仍然是关于 SRQ091221600157),这实际上似乎解决了问题,至少在我的特定情况下是这样.这种方法听起来仍然像是变通方法,并且没有任何文档可以证实它确实有效,但它似乎很有道理并且经得起一些临时测试.而且,与我想出的任何其他解决方法相比,它感觉不那么零散.它是这样的:

Today I received an additional answer from Microsoft (still regarding SRQ091221600157) which actually seems to solve the problem, at least in my particular instance. This approach still smells like work-around and there is no documentation that would confirm that it actually works, but it seems plausible enough and withstands some ad-hoc tests. And, it feels much less patchy than any other work-around I came up with. It goes like this:

只有具有 msoPermissionFullControl 的用户才能看到其他用户的权限(未记录的假设).因此,如果用户没有 msoPermissionFullControl,则 Permission 集合只包含一项,而该项反映当前用户的权限.如果权限集合包含多个项,则表示当前用户必须具有 msoPermissionFullControl.此外,当前用户必须在 Permission 集合中可见,但仍然无法找出 Permission 集合中的哪些身份代表当前用户.

Only users with msoPermissionFullControl can see permissions of other users (undocumented assumption). Thus, if a user does not have msoPermissionFullControl, the Permission collection contains exactly one item and this item reflects the current user's permissions. If the permission collection contains multiple items, this means that the current user must have msoPermissionFullControl. Also, the current user must be visible in the Permission collection, but there is still no way to find out which of the identities in the Permission collection represents the current user.

这篇关于我是谁?如何使用 Microsoft Office 权限/用户权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆