My app cannot write files anywhere on Windows 10

Started by
5 comments, last by Tertsi 8 years ago

My application, once installed in the program files directory does not seem to be able to write files anywhere on Windows 10. (And maybe other Windows versions).
Not to C:\ProgramData\MyfoldercreatedbyNSIS_installer
Not to my documents\MyfoldercreatedbyNSIS_installer
Not to User's APPData.
Not to the program's folder (in program files), that's understandable.
Nowhere!

I need it to be able to create files and write to them.

If i move the application to somewhere else than the program files folder it works just fine and can write anywhere.

I am using the computer as an administrator but I have not set the program to run on admin privileges because I need it to run without them.

I am coding in C++, Visual Studio 2015.

Any solutions? Or is the only solution to force the players to install it outside the program files folder or run it with admin privileges?

Advertisement
Could be some kind of anti-virus blocking you...? It's odd that it depends on the location of the application.

Have you debugged it while it's installed to see what the error is when it fails?

Is your program 32-bit or 64-bit, and is it in the corresponding Program Files folder? (I'm not sure if that actually matters or not, but worth a shot)

Does your program have problems running if you put it into a different folder that has a space in its name?

The locations you listed have in common that they're either read-only or in a folder created in NSIS.

Look at the access rights of the folders created by NSIS in your User folder. Is it restricted in reading or writing? There may be an error in your NSIS script that makes it create folders that require admin rights, and therefore your app can't write in them.

Program Files and Program Data should be read-only so even the NSIS created folders should be read-only. (They're the equivalent of /usr on Mac/Linux.)

Thanks for the replies.

It seems the files get created but not written to.

I use NSIS to set full access to all users. and here is what windows 10 security details says when I check the created folder's details:

$MyCurrentUsername full access

Users group (all users) full access

administrators full access

system full access

(nothing else)

The program is 32 bit and is in the program files x86 folder.

"Does your program have problems running if you put it into a different folder that has a space in its name? " no.

So, have you actually checked the error code (GetLastError) after a create/write fails? This would be a real good indication on what exactly the issue is.

You might think it's an issue with access rights and it could be a wrong path or similar.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

GetLastError reports ERROR_ACCESS_DENIED as I expected.

Alright it seems I figured it out. The other, untested string of my 2 file path strings had the wrong file path.

Thanks guys.

This topic is closed to new replies.

Advertisement