Starting services in batch file on windows 7
Download the Elevation PowerToys for Windows from Microsoft. You can then include scripts in your install process so that you can run from the batch file elevate net start servicename
and it will give them a UAC elevation prompt. As long as the user has administrative privileges on the computer or can get an administator to perform the elevation for them, it will run the command with elevated privileges and should work just fine. No need to specify a username or anything. There is a whole section in that article about creating a script that can detect if it is running with a sufficient access level, and if not, elevating itself.
Change the permissions of the myservice
service to allow it to be started by ordinary users.
An easy way to do this is to use Process Explorer: start the service, double-click on its process in ProcExp, open the Services tab, and use the Permissions button.
The hard way:
C:\>sc sdshow Schedule
D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPLOCRRC;;;PU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SY)
The text displayed is a Security Descriptor String. Each (...)
element is an ACE string.
For example, appending this to the SD would allow Users to control the service:
(A;;GX;;;BU)
BU
is the SID string for Built-in Users group. For most purposes, granting GX
(GENERIC_EXECUTE
) should be enough.
Note: The "rights" in the ACE string don't seem to correspond in any obvious way to actual permissions given. For example, "Start service" is RP
(READ_PROPERTY
) and "Stop service" is WP
(WRITE_PROPERTY
).