سؤال

I have created a win32 application in Visual Studio 2010. the application is sort of installer, it copies an exe to system32 folder.

The exe which is copied by installer is executed every time the windows is restarted. i have created an entry for it in the registry, now the problem i am having is i want to run that exe as administrator every time it is executed.

I can change the properties of the exe to run as administrator, but it works only for the specific system, i have mentioned my application is an installer, so it is quite hectic to change the privileges at every system.

Kindly guide me how can i solve this problem

هل كانت مفيدة؟

المحلول

First of all, please note that privileges and rights are specified for users rather than executables.

In order to have an executable run elevated, you typically need to add an application manifest to your executable that specifies the requireAdministrator execution level. Such an application will fail to run if the user is not an administrator, or cannot find an administrator to perform over-the-shoulder elevation.

Now, this probably won't help you much. If you want elevation to happen at logon (assuming your registry setting is HKLM\Software\Microsoft\Windows\CurrentVersion\Run) then this will lead to the user being presented with a UAC elevation dialog every time the program starts. I cannot imagine that behaviour is desirable.

Perhaps the cleanest way to avoid all of this would be to convert your application to run as a service. Services run in session 0 and are not subject to UAC. Simply run the service under a user account that has sufficient rights.

One final point, that I cannot stress enough. You should not be copying files to system32. That is the system folder and it belongs to the system.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top