Tag: unauthorizedaccessexcepti

UnauthorizedAccessException从LOCALAPPDATA中的File.ReadAllBytes“拒绝访问路径”

在读取%LOCALAPPDATA%内的文件时,同一台机器的同一用户间歇性地发生此exception。 研究 我已经检查了这个标题目前提供的所有可能的重复项(有很多)。 有一个与读取没有答案的AES加密文件有关; 我不相信,因为这些文件没有加密。 其中大部分与编写文件有关(但我正在读取文件),或者是MSDN上针对File.ReadAllBytes(字符串)记录的明显原因。 这个例外的三个解释是: “当前平台不支持此操作” – 我不知道这意味着什么; 但鉴于这有时适用于同一台机器上的同一用户(我将在下面解释),我想我可以排除这种情况。 “ path指定了一个目录” – 正如你从下面的代码中看到的那样,调用是在File.Exists的检查中File.Exists ,所以我想我可以排除这一点。 “来电者没有所需的许可。” 这是这个例外的常见解释,我怀疑我得到了某种“边缘情况”。 脚本 当以域用户身份运行的应用程序正在读取同一用户的%LOCALAPPDATA%子文件夹内的文件时,会发生这种情况(对于该用户来说,应该没有权限问题来读取文件)。 其中的子文件夹只遵循正常的“CompanyName”\“ApplicationName”结构,并且没有对子文件夹应用其他权限(我们只是使用该文件夹来保持我们的文件远离其他人)。 例外 System.UnauthorizedAccessException:拒绝访问路径’ [redacted] ‘。 在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) ,System msgPath,Boolean bFromProxy,Boolean useLongPath,Boolean checkHost)at System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share,Int32 bufferSize,FileOptions options,String msgPath,Boolean bFromProxy,Boolean useLongPath, […]

序列化问题:System.UnauthorizedAccessException

我收到此错误:mscorlib.dll中出现未处理的“System.UnauthorizedAccessException”类型exception 附加信息:访问路径’C:\ Users \ Storm Kiernan \ Desktop(NEW)Archetype Development Kit \ Laboratory \ Laboratory \ bin \ x86 \ Debug \ lol.dataf’被拒绝。 从尝试通过此代码序列化任何对象: public static void BinarySerialize(this T t, string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); directoryInfo.EnsureDirectory(); using (FileStream stream = new FileStream(directoryInfo.FullName, FileMode.OpenOrCreate)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, t); } } […]

C#Registry SetValue抛出UnauthorizedAccessException

在您尝试使用“快速Google搜索”进行回答之前。 我想指出我已经。 这是情况,我有以下方法尝试修改注册表项值。 我得到的问题是,当执行时,它会抛出一个UnauthorizedAccessException, 即使我已经将密钥打开为可写 。 我以管理员身份运行Visual Studio,甚至尝试使用清单文件制作一个小的.exe,强制它以管理员身份运行,执行代码时没有运气。 密钥已经存在,它不会尝试进入CreateKey方法。 这是代码块。 Path = “S-1-5-21-1644491937-1078145449-682003330-5490\Software\Microsoft\Windows\CurrentVersion\Policies\System” Key = “DisableTaskMgr” NewValue = 1 public OperationResult ModifyKey() { OperationResult result = new OperationResult(); if (!Path.IsNullOrEmptyTrim()) { if (!Key.IsNullOrEmptyTrim()) { try { var key = Microsoft.Win32.Registry.Users.OpenSubKey(Path, true); if (key != null) { key.SetValue(Key, NewValue); key.Close(); } else { result = CreateKey(); […]

可以使用FileShare.Delete导致UnauthorizedAccessException吗?

我正在使用以下代码打开一个文件,用于读取我之前在用户的%TEMP%文件夹中创建的文件: new FileStream(cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete); 在某些用户的计算机上,这有时会抛出UnauthorizedAccessException,并显示消息“访问路径…被拒绝”。 我无法重现这一点。 我最初的猜测是反病毒或索引引擎正在做一些时髦的事情,但我也注意到这段代码正在使用“FileShare.Delete”,我不确定应该在那里。 是否存在使用“FileShare.Delete”导致UnauthorizedAccessException的情况?

WinRT – MessageDialog.ShowAsync将在我的自定义类中抛出UnauthorizedAccessException

我想编写自己的控件,当调用ctor时,会显示一个MessageBox。 public class Class1 { public Class1() { ShowDialog(); } void ShowDialog() { SynchronizationContext context = SynchronizationContext.Current; if (context != null) { context.Post((f) => { MessageDialog dialog = new MessageDialog(“Hello!”); dialog.ShowAsync(); }, null); } } } 如果我的类被某人使用,并编写如下代码,则始终在dialog.ShowAsync();抛出UnauthorizedAccessException dialog.ShowAsync(); void MainPage_Loaded(object sender, RoutedEventArgs e) { ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1(); MessageDialog dialog1 = new MessageDialog(“”); dialog1.ShowAsync(); […]

Android Unity c#:UnauthorizedAccessException写保存游戏数据

我在Android中调试Unity游戏,一切都在Unity编辑器中运行。 我在Android上保存当前游戏数据时收到UnauthorizedAccessException。 我写的是persistentDataPath,所以我不明白为什么访问被阻止。 这是使用Logcat的控制台日志: AndroidPlayer(motorola_Moto_G_(5)@192.168.0.26) UnauthorizedAccessException: Access to the path “/current.sg” is denied. at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x0028a] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320 at System.IO.FileStream..ctor (System.String path, FileMode mode) [0x00000] in :0 at SaveLoadManager.SaveGame (.Game currentGame) [0x0002a] in F:\Work\Magister\Magister\Magister\Assets\Scripts\SaveLoadManager.cs:16 at PlayerController.FixedUpdate () [0x0058e] in F:\Work\Magister\Magister\Magister\Assets\Scripts\PlayerController.cs:244 来自在FixedUpdate()循环中运行的PlayerController的相关代码: […]

枚举目录时如何访问系统文件夹?

我正在使用此代码: DirectoryInfo dir = new DirectoryInfo(“D:\\”); foreach (FileInfo file in dir.GetFiles(“*.*”,SearchOption.AllDirectories)) { MessageBox.Show(file.FullName); } 我收到此错误: UnauthorizedAccessException未处理 对“D:\ System Volume Information”路径的访问被拒绝。 我怎么解决这个问题?