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

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

问题描述

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上找到关于这个主题的是:
< a href =http://msdn.microsoft.com/en-us/library/aa432118.aspx =nofollow noreferrer> 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

权限是一个位图,我在Microsoft的公共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的护照识别/授权。

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.

提前感谢!

Volker

Thanks in advance!
Volker

推荐答案

今天我收到了微软的另一个答案(仍然关于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。此外,当前用户必须在权限集合中可见,但仍然无法找出权限集合中的哪些身份代表当前用户。

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权限/ UserPermission的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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