Is there a shared folder in Windows to which non-elevated users have write access?

爱⌒轻易说出口 提交于 2019-12-01 03:59:47

"Shared Documents" Directory in Windows XP

C:\Documents and Settings\All Users\Documents

Or,

%ALLUSERSPROFILE%\Documents

Corresponding directory in Vista/7

C:\Users\Public

Or,

%PUBLIC%\Documents

But what you are really looking for, is the KNOWNFOLDERID value of FOLDERID_PublicDocuments (legacy CSIDL_COMMON_DOCUMENTS). The SHGetFolderPath function can then get you the path.

Or an easier VBScript alternative, but I'm not sure how reliable this is across OS versions:

Const CSIDL_COMMON_DOCUMENTS = &h2e 
Set oShell = CreateObject("Shell.Application")
Wscript.Echo oShell.Namespace(CSIDL_COMMON_DOCUMENTS).Self.Path

I think NameSpace doesn't accept that particular constant. So you might be able to take COMMONAPPDATA = &H23 and then use its parent. But that's not very clean or internationalized:

Wscript.Echo oShell.NameSpace(&h23).ParentFolder.Self.Path & "\Documents"

But since you are using Inno Setup, you should really be using the {commondocs} Shell Folder Constant and make it easy for yourself.

The user owns the document folder. Expect files to be copied, moved, deleted or edited with another program if you put something there, because of the visibility to the user.

I suggest you to create a folder under the common application data (CSIDL_COMMON_APPDATA or FOLDERID_ProgramData) in your installer with a security descriptor that allows everyone access.

E.g.

[Dirs]
Name: "{commonappdata}\productname";Permissions:everyone-modify;

Would stuff under C:\Users\Public\ qualify for what you need?

9000

Solution 1 looks quite reasonable to me. So every user control their and only their installation, and you control the central shared installation.

For solution 2 you can create a write-allowed folder in a well-defined location so that your installer knows about it, or use a registry key for the same purpose. But keep in mind that this may create a security hole because anyone could tamper with uninstall paths of other users.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!