LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting a file programmatically from Program Files directory

Hello all,

 

I have an issue in deleting a file located inside the program files folder. By default, to create a folder or file inside the program files directory, I have to provide administrator permission. When I tried to delete a file, LabVIEW throws file permission error. When I tried to set permission using Set Permission node, the node itself is throwing the same error. Is there a way to programmatically delete a file or folder from Program Files directory?

Thanks in advance.

 

Regards,

Prasanna.

0 Kudos
Message 1 of 9
(3,314 Views)

You need to start the process that wants to try to do that with elevated privileges. That means it is not enough to be logged in as administrator to be allowed to change things, but the according process needs to be specifically started with the Start as Administrator option in Explorer.

 

Alternatively you can change the access rights of that folder in Explorer to a normal user, which will prompt you for an according access elevation, possibly with an administrator password request.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 9
(3,309 Views)

Hello,

 

Thanks for the reply. So now you mean to say to delete a file in Program Files directory programmatically through LabVIEW, LabVIEW has to be run with administrator privileges. Is this true?

 

Regards,

Prasanna.

0 Kudos
Message 3 of 9
(3,269 Views)

What file are you trying to delete? Maybe it should not be stored in that directory, but the Program Data directory instead.

0 Kudos
Message 4 of 9
(3,266 Views)

@PrasannaSSRK wrote:

Hello,

 

Thanks for the reply. So now you mean to say to delete a file in Program Files directory programmatically through LabVIEW, LabVIEW has to be run with administrator privileges. Is this true?

 


No, not generally! Only if you want to let your program delete files or directories in the so called protected locations on your disk. They are protected by Windows for a reason, and you either have to elevate a process to be able to access these locations with anything but read access or you have to change the protection settings explciitly to something less restricitive (not recommended for the whole Program Files Folder but can be a workaround for a specific sub folder sometimes). But Windows XP is looooong ago already dead so it is about time that program developers should have learned that an application has ABSOLUTELY NO business in trying to access this folder and its subfolders with write or modification access.

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 9
(3,254 Views)

Hello,

 

similiar case: I have a WebService deployed via executable. My website with index.html is in documents. However in the niembeddedws.conf file I have to change the DocumentRoot standard path with the path to my documents-website path. If I do this it works. I can open the Website from any device by entering the IP:Port and interact with my executable from the server.

 

However, I can't change the documentroot path programmatically, due to windows admin restriction in ProgramFiles. Any Ideas?

 

With best regards

 

Be Exyted

0 Kudos
Message 6 of 9
(2,648 Views)

If you mark the file as 'unlock' in the installer Source File Settings, your application should be able to modify it.

 

IIRC, you should be careful, deleting the file and creating a new file won't work. You need to open it, and change it's content to keep the privileges.

 

And also, I agree this is not recommended on modern Windows. 

0 Kudos
Message 7 of 9
(2,637 Views)

I tried this, but it won't work. Even when I click on OK in installer settings and open it again, the unlock setting is lost for this file. - Be Exyted

0 Kudos
Message 8 of 9
(2,627 Views)

@Exyted wrote:

similiar case:


And similar response.  Windows 10 has security rules that prevent Standard Users (which is the case for most users, particularly on "deployed platforms" with accounts for multiple users) from making modifications to important Folders (such as Program Files, Program Files x86, and folders in Users that belong to other Users.

 

My way of handling this is to make use of the Public Folders.  When you build an Executable, you generally get a sub-folder called "data".  If you build your Executables in Users\Public Documents\LabVIEW Builds, you'll find that each Folder holding a Build has a \data folder, which is an excellent place to put .conf files and the like.

 

The Public Documents folder tends to be less "visible" in Windows 10, which can be a Good Thing, as it keeps folders accessible without needing Admin rights, but "out of sight", for the most part.  To make the program accessible for all users, create a Shortcut to the executable, and place that in the Public Desktop (which is a hidden folder in Public Documents).

 

Bob Schor

0 Kudos
Message 9 of 9
(2,623 Views)