Note that there are some explanatory texts on larger screens.

plurals
  1. POWho am I? How to use Microsoft Office Permission/UserPermission
    text
    copied!<p>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?</p> <p>All I can find on MSDN on this topic is this: <a href="http://msdn.microsoft.com/en-us/library/aa432118.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa432118.aspx</a></p> <p>If I run the following code, I get a list of users that have permissions on the given document:</p> <pre><code>Sub test() Dim perm As Office.Permission Set perm = ActivePresentation.Permission Debug.Print "Enabled=" &amp; perm.Enabled If perm.Enabled Then Debug.Print "PermissionFromPolicy=" &amp; perm.PermissionFromPolicy Debug.Print "PolicyName='" &amp; perm.PolicyName &amp; "'" Debug.Print "PolicyDescription='" &amp; perm.PolicyDescription &amp; "'" Dim uperm As Office.UserPermission For Each uperm In perm Debug.Print uperm.UserId &amp; ", " &amp; uperm.Permission Next uperm End If End Sub </code></pre> <p>Sample output:</p> <pre><code>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 </code></pre> <p>The "Permission" is a bitmap the definition for which I found in Microsoft's public COM header files:</p> <pre><code>enum MsoPermission { msoPermissionView = 1, msoPermissionRead = 1, msoPermissionEdit = 2, msoPermissionSave = 4, msoPermissionExtract = 8, msoPermissionChange = 15, msoPermissionPrint = 16, msoPermissionObjModel = 32, msoPermissionFullControl = 64, msoPermissionAllCommon = 127 }; </code></pre> <p>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?</p> <p>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. </p> <p>Thanks in advance!<br> Volker</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload