Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to delete folder that is located at

C:\Program Files\Default Company Name.

The application in which i am implementing this code resides in the same folder.

For that i have used the below code

C#
Public Sub deletefunc()
        Dim Path As String = "C:\Program Files\Default Company Name"
        Directory.Delete(Path, True)
End Sub


Not getting any error.
It deletes the folder(i should say hide) folder until next run.When i try to run application through shortcut then it again shows that folder(which we attempted to delete),that is it was not deleted previously.

My question is : How to delete specific folder?Is there anything needs to be updated with this code?or how to implement other way?

Any help is really appreciated.
Posted
Updated 20-May-13 0:04am
v3

Deleting things from this directory is not really legal operation. No wonder access to this directory has been limited since Window 7 (I don't count Vista). The content of this directory is registered with the Windows Installer database, so any direct deletion may break its integrity. Such operations can be done only via Windows Installer SDK.

For building installation, Visual Studio Setup projects are usually used, by they have been deprecated since v.2012, for a good reason. The project type is not MSBuild-compliant and has other problems. I strongly recommend open-source Microsoft Windows Installer XML Toolset (WiX):
http://en.wikipedia.org/wiki/WiX[^],
http://wixtoolset.org/[^].

—SA
 
Share this answer
 
Comments
Sejal Rabari 22-May-13 5:08am    
Great explanation.My need is,at some time i want the program that resides in this folder should not be run,that is one will get error to reinstall the program. If we neglect to delete the folder,what would be the better choice?
Sergey Alexandrovich Kryukov 22-May-13 12:14pm    
It depends on what you want to do and why. If you copied some executable modules by installation, you still mean to run it. Probably, you need to allow running it under some condition and prohibit under some other conditions. But this is the application-specific aspect of the functionality, so it should be resolved at the level of application itself.

In other words, you may not want the user to run some application directly, depending on some condition. You can do it this ways:

1) Write the code in application itself. Allow to run it always, but check for condition in its code, and, if it should not be run, give the user a message with the advice what to do instead and terminate immediately.

2) Perhaps this is the application is run when some other process starts it, but should not be run by the user directly. If this can be the case, the simple thing is: don't name its entry-point module (*.EXE) *.EXE! name it *.something. You will be able to start the process using some other application, but not by the user directly.

3) Review the architecture. The application which can be run only on some conditions means wrong approach, even it you apply workarounds I advised above.

How about that?

—SA
 
Share this answer
 
Comments
Sejal Rabari 20-May-13 6:30am    
I implemented the same thing as you suggested(verify the code in question and on one of the links you provided). The problem is its working like one time hide.Folder is not getting deleted.
Could this have anything to do with the way you're deploying the application?

My ClickOnce applications will update before launching... This will recreate the folder structure before the app starts.
 
Share this answer
 
Comments
Sejal Rabari 20-May-13 7:28am    
Scenario is,When we install application,it will be installed in the directory i have mentioned in the question. Now,at each time the application starts,i am trying to check some condition,if condition matched,i want to delete the folder,thats it.I have tried using the above code but it is not working as expected,that is its not deleting the folder.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900