2011-08-10 45 views
0

私のWPF MVVMアプリケーションでは、変更するXMLファイルがあります。 Visual Studioで正常に動作しています。 しかし、インストールされているアプリケーションの実行中にエラーが表示されます。私はWPFのファイルへの書き込み権限のプログラム追加

// current security settings. 
FileSecurity fSecurity = File.GetAccessControl(FilePath); 

// Add the FileSystemAccessRule to the security settings. 
string rr = WindowsIdentity.GetCurrent().Name; 
fSecurity.AddAccessRule(new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, 
      FileSystemRights.FullControl, AccessControlType.Allow)); 


// Set the new access settings. 
File.SetAccessControl(FilePath, fSecurity); 

まだカントは

が見..事前に

おかげで、...問題を解決するため、このコードを使用するどのように私は、コードを通じてアクセス権を設定することができます。..

例外...

System.UnauthorizedAccessException:を実行しようとしました。不正操作。 でSystem.Security.AccessControl.Win32.SetSecurityInfo(ResourceTypeが型、 文字列名、SafeHandleハンドル、SecurityInfosセキュリティ情報、 セキュリティ識別子の所有者、セキュリティ識別子基、GenericAcl SACL、 GenericAcl DACL) System.Security.AccessControl.NativeObjectSecurity.PersistでSystem.Security.AccessControl.NativeObjectSecurity.Persistで System.Security.AccessControl.NativeObjectSecurity.Persist(文字列 名、AccessControlSections includeSections、exceptionContextオブジェクト) (文字列に(文字列 名、SafeHandleは exceptionContextオブジェクト、AccessControlSections includeSectionsハンドル) name、AccessControlSections includesSections)atアクセス権を設定するにはSystem.IO.File.SetAccessControl(文字列のパス、 FileSecurity fileSecurity)でSystem.Security.AccessControl.FileSystemSecurity.Persist(文字列 をフルパス)

答えて

0

ほとんどが、それはパワーユーザー権限が必要です(あなたのアールを想定し実行中のウィンドウ7)。

上記を確認するには、Visual Studioを「管理者として実行」として起動し、コードをデバッグします。

正確な例外メッセージとは何ですか?ここで

は実施例である:それは、このコードは、ユーザアカウントの設定を通知しないように設定されている場合にのみ動作し、ユーザーグループEveryone

private static void WriteAcl (string filename) 
     { 
      //Set security for EveryOne Group 
      SecurityIdentifier sid =new SecurityIdentifier(WellKnownSidType.WorldSid, null); 
      IdentityReference userIdentity =sid.Translate (typeof(NTAccount));   

      var AccessRule_AllowEveryOne = new FileSystemAccessRule (userIdentity, FileSystemRights.FullControl, AccessControlType.Allow); 
      var securityDescriptor = new FileSecurity(); 
      securityDescriptor.SetAccessRule (AccessRule_AllowEveryOne);    
      File.SetAccessControl (filename, securityDescriptor); 
     } 

のための完全な権限を設定します。あなたのコンピュータで電源がオンになっているようですか?

回避策は、アプリケーションマニフェストを使用してパワーユーザーとしてアプリケーションを起動することです。

http://msdn.microsoft.com/en-us/library/bb756929.aspx

+0

あなたが手順を説明plzはまだ問題がexists.Could ... – S007

+0

はい、私は、私は、正確な例外メッセージと質問を更新しました....のWindows7を使用しています。 – S007

+0

上記の作業例を追加しました。 – Munawar

関連する問題