すでに存在するファイルやフォルダを削除し、新しいファイルと置き換える必要があるインストーラを作成しました。C#を使用してディレクトリとファイルを削除できません
ユーザがインストールをクリックすると、インストーラはUACを要求します。 「はい」を選択すると、インストーラは既存のファイルとフォルダを削除する方法を呼び出します。しかし、ファイルとフォルダを削除することはできません。私が使用しているコードはDI.Delete(パス)です。私は管理者としてコマンドプロンプトを実行してから、「msiexecの/私のsetup.msi」コマンドを使用している場合、それはそれらのファイルやフォルダーを削除している間は、このエラーに
Access to the path 'CodeCreate.aspx' is denied.
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
at System.IO.DirectoryInfo.Delete(Boolean recursive)
at CustomizationCA.CustomActions.DeleteExistingFilesAndFolder(Session session)
を与えます。
Directory.Delete(path、true)を使用する場合。私は例外としてこれを取得しています
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte rawData)
at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte rawData)
at System.Diagnostics.EventLog.WriteEntry(String source, String message)
at CustomizationCA.CustomActions.DeleteExistingFilesAndFolder(Session session)
私はインストーラを作成するためにWIXツールを使用しています。
特定のファイルのプロパティにアクセスし、すべてのユーザーに完全なアクセス許可を与えてからファイルを削除しようとすると、ファイルが削除されています。
私もこのコードを使用しましたが、ファイルを削除していません。私のポストに追加した詳細。 –
削除操作に**偽装**または**エスカレーション**を使用してみませんか? –
インストールが開始されると、インストーラはUACプロンプトを表示します。したがって、権利はすべての方法を通過しなければなりません。右? –