我无法使用 VS 2008 WPF C# 代码在 Windows 7 64 位计算机上的“程序文件”文件夹下创建文件。我在以下代码中遇到的错误
myFile = File.Create(logFile);
如下。 (这是innerException堆栈跟踪)。
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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.Create(String path)
at MyFirm.MyPricingApp.UI.App.InitializeLogging() in C:\Projects\MyPricingApp\App.xaml.cs:line 150
at MyFirm.MyPricingApp.UI.App.Application_Startup(Object sender, StartupEventArgs e) in C:\Projects\MyPricingApp\App.xaml.cs:line 38
at System.Windows.Application.OnStartup(StartupEventArgs e)
at System.Windows.Application.<.ctor>b__0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
这似乎与 Windows 7 中的 UAC 有关,因为我的用户已经是计算机上的管理员,为什么我会得到这个?
另外,由于 WinIOError 具有 SECURITY_ATTRIBUTES,我认为这与 Windows 7 中处理安全性的“新方式”有关。
我尝试浏览到“Program Files”文件夹,在该文件夹下创建日志文件夹和文件。我可以手动创建文件夹,但是当我尝试创建文件时,我收到类似的“访问被拒绝”异常。