Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:06:38+00:00 2026-06-03T23:06:38+00:00

I am getting the below error. I need to uninstall the app and delete

  • 0

I am getting the below error.

I need to uninstall the app and delete all files and folders created either by the application or users in the program files/myapp.

How can I resolve this issue?
Thanks.

Access to the path 'C:\Program Files (x86)\DefaultProgram\Application\app.exe' is denied.

My Code:

protected override void OnAfterUninstall(IDictionary savedState)
        {
            string sFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]);
            string sUsername = "NT AUTHORITY\\LOCALSERVICE";
            DirectoryInfo myDirectoryInfo = new DirectoryInfo(sFolder);
            DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
            myDirectorySecurity.AddAccessRule(
                new FileSystemAccessRule(
                    sUsername, FileSystemRights.Read | 
                    FileSystemRights.Write | 
                    FileSystemRights.Modify, InheritanceFlags.ContainerInherit | 
                    InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
            myDirectoryInfo.SetAccessControl(myDirectorySecurity);
            base.OnAfterUninstall(savedState);
            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            DeleteDirectory(Path.Combine(appPath, "DB"));
            DeleteDirectory(appPath);
        }

        public static void DeleteDirectory(string target_dir)
        {
            string[] files = Directory.GetFiles(target_dir);
            string[] dirs = Directory.GetDirectories(target_dir);
            foreach (string file in files)
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }
            foreach (string dir in dirs)
            {
                DeleteDirectory(dir);
            }
            Directory.Delete(target_dir, false);
        } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:06:40+00:00Added an answer on June 3, 2026 at 11:06 pm

    You can delete your app.exe in this way on XP

    Process.Start("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 3000 > Nul & Del " + 
          Application.ExecutablePath); 
    Application.Exit();
    

    or this in Win7 (EDIT2)

    Process.Start("cmd.exe", "timeout 5 > Nul & Del " + 
          Application.ExecutablePath); 
    Application.Exit();
    

    But you must add in foreach if(file.Contains("app.exe")) continue;

    EDIT

    protected override void OnAfterUninstall(IDictionary savedState)
        {
            base.OnAfterUninstall(savedState);
            string sFolder = Path.GetDirectoryName(Context.Parameters["assemblypath"]);
            string sUsername = "NT AUTHORITY\\LOCALSERVICE";
            DirectoryInfo myDirectoryInfo = new DirectoryInfo(sFolder);
            DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
            myDirectorySecurity.AddAccessRule(
                new FileSystemAccessRule(
                    sUsername, FileSystemRights.Read | 
                    FileSystemRights.Write | 
                    FileSystemRights.Modify, InheritanceFlags.ContainerInherit | 
                    InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
            myDirectoryInfo.SetAccessControl(myDirectorySecurity);
            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
           DeleteDirectory(Path.Combine(appPath, "DB"));
            DeleteDirectory(appPath);
        }
    
        public static void DeleteDirectory(string target_dir)
        {
            string[] files = Directory.GetFiles(target_dir);
            string[] dirs = Directory.GetDirectories(target_dir);
            foreach (string file in files)
            {
                File.SetAttributes(file, FileAttributes.Normal);
                if(file.Contains("app.exe")) continue;
                File.Delete(file);
            }
            foreach (string dir in dirs)
            {
                DeleteDirectory(dir);
            }
            Directory.Delete(target_dir, false);
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error below, and each time I need to delete the
I am getting the below error when executing my application on a Windows XP
When running IIS, I'm getting the below error on all ASPX pages. ASP.NET is
I am getting the error below, which makes no sense. * Terminating app due
I'm trying to build a java application with gcj but getting the error below.
Below is trigger that I need to create but It is not getting created.Please
i'm getting the below error, When compiling the Asp.Net web deploy project Could not
I am getting the error below when I call my WCF service. What am
We are getting the error below calling c:\windows\syswow64\regsvr32.exe on Windows Server 2008 R2 x64.
I'm getting the error below for this SQL statement in VB.Net 'Fill in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.