If you want to bypass the protection that you get as a standard user, the best solution is to change permissions on the folder and registry key so that all users can change your application folder.
GrantAllUsersFullControlToFileOrFolder("C:\Program Files\Grobtastic");
with pseudo code implementation:
void GrantAllUsersFullControlToFileOrFolder(String path) { PACL oldDACL; PACL newDACL; PSECURITY_DESCRIPTOR sd; //Get the current DALC (Discretionary Access Control List) and Security Descriptor GetNamedSecurityInfo(path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, ref oldDACL, nil, ref sd); //Create an SID for the "Users" group PSID usersSid = StringToSid("S-1-5-32-545"); // Initialize an EXPLICIT_ACCESS structure for the new Access Control Entry (ACE) EXPLICIT_ACCESS ea; ZeroMemory(@ea, SizeOf(EXPLICIT_ACCESS)); ea.grfAccessPermissions = GENERIC_ALL; ea.grfAccessMode = GRANT_ACCESS; ea.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT; ea.Trustee.TrusteeForm = TRUSTEE_IS_SID; ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP; ea.Trustee.ptstrName = PChar(usersSID); // Create a new ACL that merges the new ACE into the existing ACL. // SetEntriesInAcl takes care of adding the ACE in the correct order in the list SetEntriesInAcl(1, @ea, oldDACL, ref newDACL); //use LocalFree to free returned newDACL //Attach the new ACL as the object new DACL SetNamedSecurityInfo(path, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, newDACL, nil); LocalFree(HLOCAL(sd)); LocalFree(HLOCAL(newDACL)); FreeSid(usersSID); }
This works even when UAC is disabled (i.e., the user is a standard user and there is no convenient way to increase them). It also runs on Windows XP, where there was no UAC feature, and you had to switch quickly to run something as an administrator.
You then demonstrate your executable to run asInvoker , since you do not need administrative permissions.
Ask yourself:
What would I do in Windows XP?
What would I do on Windows 7 with UAC disabled? A.
If they are standard users, your program crashes to the dead?
Ian boyd
source share