无法将授权放在文件夹上 [英] Cannot put authorize on a folder

查看:70
本文介绍了无法将授权放在文件夹上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试设置具有完全权限的文件夹,我尝试了以下操作:

Hello, I''m trying to setup a folder with full permission, i tried this:

AddDirectorySecurity(txtDestination.Text + @"Minecraft", "System", FileSystemRights.FullControl, AccessControlType.Allow);


但它行不通,只是给了我这个:


but it wont work, it just gives me this:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Access to the path 'C:\Temp\Minecraft' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Uninstaller.ZIPFinder.button1_Click(Object sender, EventArgs e) in C:\Users\Daniel\documents\visual studio 2010\Projects\Uninstaller\Uninstaller\ZIPFinder.cs:line 363
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.239 (RTMGDR.030319-2300)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Uninstaller
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Daniel/Desktop/Uninstaller/Uninstaller.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.235 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.258 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
ZipForge
    Assembly Version: 3.0.2.0
    Win32 Version: 3.0.2.0
    CodeBase: file:///C:/Users/Daniel/Desktop/Uninstaller/ZipForge.DLL
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.233 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



知道为什么吗?它应该提供权限..



any idea why? it should give the permissions..

推荐答案

由于代码以启动它的用户身份运行,因此告诉您的是该用户没有具有适当的权限来设置该文件夹上的权限.普通用户帐户可能只具有对C:\ Temp文件夹的读取"和列表文件夹"访问权限,因此无法创建Minecraft文件夹,也无法对其设置权限.

您将必须找到一个更合适的位置来创建此文件夹.例如由环境变量"TEMP"指定的一个.在Windows 7上,这通常指向C:\ Users \< userid> \ AppData \ Local \ Temp,用户对该文件夹具有最大的权限.他们可以在其中创建/读取/写入他们想要的任何文件夹或文件,但是无法修改它们的权限.
Since the code runs as the user who launched it, what it''s telling you is that the user doesn''t have the proper permissions to set permissions on that folder. Chances are a normal user account is only going to have Read and List Folder access to the C:\Temp folder, and therefore cannot create the Minecraft folder nor set permissions on it.

You''re going to have to find a more suitable place to create this folder. Such as the one specified by the environment variable "TEMP". On Windows 7, that usually points to C:\Users\<userid>\AppData\Local\Temp, on which the user has most permissions to the folder. They can create/read/write any folder or file they want in there, but cannot modify permissions on them.


让我给您一个简单的建议:目录"C:\ Temp \ Minecraft"不是Windows 7下的合法按应用程序访问文件夹.它是硬编码的路径名吗? 在任何情况下,此类名称都不会有用.

您应该始终在运行时为操作计算一个有效目录.

首先,您可以使用System.IO.Path.GetTempPath:
为当前正在运行该应用程序的用户找到一个临时目录. http://msdn.microsoft.com/en-us/library/system. io.path.gettemppath.aspx [ ^ ].

您可以在此目录中创建一个单独的子目录:
http://msdn.microsoft.com/en-us/library/system. io.directory.createdirectory.aspx [ ^ ].

出于其他目的,您可以在所有用户"目录中找到专用于应用程序设置的目录.使用System.Environment.GetFolderPath:
http://msdn.microsoft.com/en-us/library/dd992682.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.environment. specialfolder.aspx [ ^ ].

根据您的选择,它会基于每个用户保留您的应用程序数据或使它们通用.

—SA
Let me give you one simple advice: The directory "C:\Temp\Minecraft" is not a legal access-by-application folder under Windows 7. Is it a hard-coded path name? There are no situations when such names can be useful.

You should always calculate a valid directory for your operations during runtime.

First of all, you can find out a temporary directory for a user currently running the application using System.IO.Path.GetTempPath:
http://msdn.microsoft.com/en-us/library/system.io.path.gettemppath.aspx[^].

You can create a separate subdirectory in this directory:
http://msdn.microsoft.com/en-us/library/system.io.directory.createdirectory.aspx[^].

For other purposes, you can find a directory dedicated for application settings for a current user of "all users" directory. Use System.Environment.GetFolderPath:
http://msdn.microsoft.com/en-us/library/dd992682.aspx[^],
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^].

Depending on you choice, it will persist your application data on a per-user basis or make them common.

—SA


这篇关于无法将授权放在文件夹上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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