如果用户不是管理员,我的程序可以使用的临时目录在哪里?
我的应用程序现在需要创建文件,然后将文件写入驻留在其安装目录中的临时目录。 msi 默认将其放在 Program Files\ 中。我没有考虑如果一些可怜的人使用非管理帐户运行它会发生什么。
Description: Access to the path 'Temp' is denied.
StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj)
at System.IO.Directory.CreateDirectory(String path)
我查看了我的计算机,默认情况下,用户组中的任何帐户都没有对几乎每个文件夹的写入权限。我想我对这一切一无所知,因为我总是以管理员身份运行所有的东西,甚至不假思索。
无论如何,有没有办法:
1:对目录创建/文件写入进行编码,以便在不以管理员身份运行时暂时将程序的权限提升为管理员(我使用的是 C#)
2:配置安装程序以设置“用户”组中每个人的目录权限为“完全控制”(使用 Windows 安装项目 msis)
谢谢!
My application now needs to create and then write files to a temp directory that resides within its installed directory. The msi puts it in Program Files\ by default. I didn't consider what would happen though if some poor soul runs it using a non administrative account.
Description: Access to the path 'Temp' is denied.
StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj)
at System.IO.Directory.CreateDirectory(String path)
I looked on my computer and by default any account in the users group doesn't have write permissions for just about every folder. I guess I'm ignorant of it all because I always run all my stuff as an administrator without even thinking about it.
Anyways, is there a way to:
1: Code the directory creating/file writing so that it temporarily elevates the permissions of the program to administrator if it's not running as an administrator (I'm using C#)
2: Configure the installer to set the directory permissions to 'full control' for everybody in the 'Users' group (using windows setup project msis)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要这样做。
您应该写入 AppData 文件夹中的每个用户目录。 (或 Path.GetTempPath(),即其中的内容)
任何其他内容都会产生安全漏洞。
Don't do that.
You should write to per-user directories in the AppData folder. (or
Path.GetTempPath()
, which is in that)Anything else will create security vulnerabilities.