1

So I want to disable or enable a service depending on which user logs on, as it's a service that only needs to be active for a specific user, and otherwise gobbles up unnecessary system resources.

The easiest way would be to create a batch file per user (it's a local system so not too many users) and run that batch file when a user logs on using net stop/start or sc config. The problem with that approach is that those commands require elevated privileges, and one of the users doesn't have elevated privileges.

Is there another way to do this, or is there a workaround to temporarily grant elevated rights to a batch file?

Thanks.

1
  • 2
    You can configure an automatic task to run as a different user.
    – Ramhound
    Commented Sep 22, 2019 at 2:00

2 Answers 2

2

You can use a scheduled task to get around the elevated privileges problem.

For each end-user:

  1. Start Task Scheduler and create a new task (select "Create Task" on the right)
  2. On the General tab, set the task to run in your own (admin) account, whether logged in or not, and with highest privileges
  3. On the Triggers tab, add an "At log on" trigger and configure the end-user account
  4. On the Actions tab, add a "Start a program" action and supply the command line you want to run ("NET STOP service-name" or "NET START service-name").
  5. Save your new scheduled task.

When one of your end-users logs in, the Task Scheduler will run NET START/STOP in your admin account, starting or stopping the service without requiring elevated privileges at the point of login.

Some questions for you: What happens if both end-users log in? Do you get the correct result under all login sequences (i.e. user A then B and user B then A)? Don't forget to consider logout sequences too...

0

Services are acting the same in all user accounts....so by disable with a batch file ,this will effect the other user (administrator for example)...account....so make another account is worthless :(...try just make 2 batch files. One for stop one for start...im amazed that windows cant have different service usage for different users. and needs...im dissapointed...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .