Advice regarding deleteFile() to delete files in other apps 'ProgramData' folder


#1

So part of the functionality for my new app I am writing is to delete some files stored in ‘ProgramData’ for another program (on Windows, i.e. C:\ProgramData\APPNAME\FOLDER_WITH_DATA_TO_DELETE). This either requires Admin rights or give my app access to read/write on that folder. What’s the best & safest way to do this?

Currently calling .deleteFile() on a file in this location fails and the call returns false.

Thanks!

E


#2

I should note that both the file and it’s parent directories both returns true on .hasWriteAccess(), but looking at the attributes on the folder(s) it’s marked as ‘read only’.


#3

You answered your own question. To do this on MacOS you’ll have to create a Helper app.

Is the other App your own?

Rail


#4

I am trying to delete files from another apps ‘ProgramData’ folder (the app is a cleanup kind of app). As for MacOS you said Helper app, how does this work? (I’ve never done any deep development on MacOS).

I thought I saw something on stackoverflow that your app can get privileges over another apps ‘ProgramData’ during installation?

Thanks

E


#5

I would be really pissed off if another app touched anything in my app’s programData folder.

MacOS: https://developer.apple.com/library/content/documentation/Security/Conceptual/SecureCodingGuide/Articles/AccessControl.html

Windows: http://stackoverflow.com/questions/707497/set-app-to-require-elevation

Rail


#6

Thanks! Will look into that. I have this test to make sure the user starts it elevated for now:

bool isElevated()
{
	bool result = false;
	HANDLE hToken = nullptr;
	if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
	{
		TOKEN_ELEVATION Elevation;
		DWORD cbSize = sizeof(TOKEN_ELEVATION);
		if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize))
		{
			result = Elevation.TokenIsElevated > 0;
		}
	}

	if (hToken)
	{
		CloseHandle(hToken);
	}
	return result;
}

Which I found on Stackoverflow.


#7

You can set the flag to make it always run elevated – see the link in my previous post.

Rail


#8

Yeah I might add that in the end.