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

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

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’.

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

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

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

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.

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

Rail

Yeah I might add that in the end.