Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...
earlier i use it through command line[runas /user:administrator cmd]and then use password and services one by one its time consuming, have u any idea regarding batch command if we have admin user ID and password to switch as local user to admin user to (start/stop/restart )services.msc or any other tools..of system
i am unable to pass the password to use as services of admin through batch file command
Posted
Comments
Sergey Alexandrovich Kryukov 19-Sep-11 11:36am    
Language, platform?
--SA

1 solution

Of course you can do it.

Most simple thing is using the Microsoft application SC.EXE which simply a console-oriented front-end communicating with the Service Controller, so it's easy to use in the batch files.
See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sc.mspx?mfr=true[^].

This utility is available in the Resource Kit, see http://en.wikipedia.org/wiki/Windows_Resource_Kit[^] and the references to Microsoft download pages at the bottom of this article.

You can control installed services using the Service Controller in general and this utility in particular.

Also, you can embed the capabilities of controlling the service the way you described using Service Controller API. Actually you can implement such functionality in the same application as your service application. An instant of the process can determine if it is running as a service or interactively. If this is an interactive run, the process can look at command line (or even get a command from a special interactive-only UI) and perform the required operation on the registered service. I'm not giving you any further detail just because you did not share your platform and language. I did it only on .NET. Also, it seems to be you rather look for a solution like the one based on SC.EXE.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900