/build/static/layout/Breadcrumb_cap_w.png

best way to stop and start services in Win Env.

Hello all!

I have a question. I need to create a small program, either VBS or an Application that will start or stop two services in OS. Those two services would be the same all the time. Any suggestions on what would be the more efficient way of doing it and what technology would you use. Would you create a small .net application or create a batch file or VBS?

Thanks

0 Comments   [ + ] Show comments

Answers (21)

Posted by: yarborg 17 years ago
Blue Belt
0
Psservice from Systernals (Microsoft now) would be my choice. You just pass it a command line parameter of the name of the service and the action to perform. Really simple and proven to work well.
Posted by: xaviorpl 17 years ago
Orange Belt
0
Thank you very much for your quick response. To give you a little more details, user will execute that script to stop and start services on a "server" not workstations. Would the program you mentioned be able to handle that? Also remember user will only have a right to execute the script and user is not an admin to the box.

Please advice.
Posted by: AngelD 17 years ago
Red Belt
0
Depending on the OS you're targetting you could use the "net" (start/stop) command. SC could also be usable and is available at XP and 2003 by default.
Posted by: AngelD 17 years ago
Red Belt
0
The use would of course need to have admin rights to perform this.
May I ask why you would want to do this?

A solution but not recommended would be to create a DCOM component that is running under the system account. Then make a call to it of the command to execute but I would say NO NO to this.
Posted by: xaviorpl 17 years ago
Orange Belt
0
Well, i am working on this particular application and i need to package it. That's the first part. Now in order for the user to be able to use the package, they need two services on remote servers to start and stop whenever user request them.

I'll create some kind of an application with the shortcut in a start mentu for start and stop, so they could click on them and specific action would be performed. Once again users would be on locked down PC.

Hope that helps.

Thanks,
Posted by: yarborg 17 years ago
Blue Belt
0
You can pass alternate credentials to PsService that have admin rights. The script may need to call a batch file that has the command line to the PsService.exe instead of PsService directly so that the users can't open the vbscript (or whatever) and see the username and password.
Posted by: xaviorpl 17 years ago
Orange Belt
0
Is there any othe way to hide credentials to the server "user name" and "password"?
Posted by: yarborg 17 years ago
Blue Belt
0
I actually prefer to use Wise for scripting since it encapsulates the script into an exe file vs a plain bat or vbs file. You can also use an encryption method on your vbscript to turn it into a .vbe file. Use the Microsoft Scripting Encoder for this. I can be cracked but not by your average user.
Posted by: AngelD 17 years ago
Red Belt
0
I would use CPAU for this and it's free.
Although I wouldn't rely 100% on the encryption. If they want to crack it they will eventually.
http://www.joeware.net/freetools/tools/cpau/index.htm
Posted by: xaviorpl 17 years ago
Orange Belt
0
I am not sure if i was clear enough with my little project but the deal is user on locked down PC wants to be able to start or stop a service on a remote server. Have you guys done anything similar to that. It would be easier to do that on the same PC but we're talking about remote server.

What would be the best technology to achieve that. Would any of you try to write a perl script or you would go along with either VB or any ther tools?

Thanks,
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngeID,
Net start/stop cannot be used remotedly is that right? SC can be used remotedly but user need to have admin rights to the workstation it is stopping the service on. That's part of my problem, user will not have the rights on the remote pc, therefore
- there will be an administrator account on the box which i could use to pass the parameters but with that there is the risk of someone else getting their hands on the password unless i'll try to hide it somehow.
Posted by: AngelD 17 years ago
Red Belt
0
For managing service on a remove server I would use PsService as yarborg mentioned before to remotely manage the service.
You can find this tool at http://www.microsoft.com/technet/sysinternals/utilities/psservice.mspx
To encrypt it use CPAU so the account and password information will not be visible in plain text.

However I would never allow "normal" users to manage service on a server or any other task.
Why can't you just leave that service running at all time?
Posted by: xaviorpl 17 years ago
Orange Belt
0
I understand you concern and i agree with you. However i am being forced to develop "something" that would allow normal users using this particular application to just click on "start" button and be able to start 2 specific services and upon pressing stop those exactly the same services would stop. One of my requirements is that users will not have admin rights to the server where those services would start or stop.

Keep in mind they would only start or stop those services when running special reports. For some reason the software they have is generating wrong reports when those services run and different part of the software requires those services to be running in order to produce "different" report. I know it sounds strange but that's all i have at this point.

I'll investigate the last link you provided me with tomorrow.

Thanks,
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD,

i have a question. How would i use CPAU in this scenerio:

c:\temp>psservice.exe \\197.54.444.123 -u xavior -p xavior start service_name

In that case psservice.exe and CPAU.exe both are located in temp folder, and i am starting a service on a remote computer with 197.54.444.123 IP. How can i run CPAU on the top of that?

Thanks
Posted by: AngelD 17 years ago
Red Belt
0
When I used this I created a .cmd file with the command I wanted to execute.
ex. psservice.cmd
@echo off
psservice.exe \\197.54.444.123 start service_name

To create a "JOB" file use:
\\server\share\path\cpau.exe -u domain\xavior -p xavior -ex "\\server\share\path\psservice.cmd" -file \\server\share\path\psservice.cpau -enc -crc \\server\share\path\psservice.cmd

To execute the "JOB" file use:
\\server\share\path\cpau -file \\server\share\path\psservice.cpau -dec -profile

Hope it helps.
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD,

Your info was very helpful. I am a little confused about creating a "job" file and then executing "job" file.
You cannot created and execute it at the same time?

Thanks,
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD,

Analyzing those 4 lines,

To create a "JOB" file use:
\\server\share\path\cpau.exe -u domain\xavior -p xavior -ex "\\server\share\path\psservice.cmd" -file \\server\share\path\psservice.cpau -enc -crc \\server\share\path\psservice.cmd


That would create the following file: psservice.cpau is that correct ?

Then the second part

\\server\share\path\cpau -file \\server\share\path\psservice.cpau -dec -profile

would just execute it right? What about -dec and -profile, what's that for.

Sorry if those questions don't make sense but i am new to that .

Thanks
Posted by: AngelD 17 years ago
Red Belt
0
You cannot created and execute it at the same time?
No

That would create the following file: psservice.cpau is that correct ?
Yes

would just execute it right?
Yes

What about -dec and -profile, what's that for.
Run CPAU /? to find out about the available arguments and some examples.
-dec
As you encrypted (-enc) the JOB file -dec will tell to execute an encrypted JOB file
-profile
Do local logon with profile instead of net logon
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD,

Thanks alot you've been very helpful. Do i have to create "job" each time or i can create it once and use it all the time since server name etc won't change?

Do you know of a way to find out about the status of the request after running those commands? It might take some time for the service to start or stop. Is it possible with something simple or that would be more sophisticated task?

Thanks
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD,

I created .cmd file, tested it with user name and password inside, worked fine. I removed user name and password and proceded to creating job file. That created the .cpau file then i was able to run it , "the command completed successfully". Only problem i don't see the service being started or stopped on my test PC. It was workign fine with the .cmd file alone (with user name and password) but once i execute .cpau file it is not working and i am getting a message that it was successfully completed.

Any suggestions on why that is happening?

Thanks,
Posted by: xaviorpl 17 years ago
Orange Belt
0
AngelD

It looks like it needs some time to either start and stop a service. I was able to run it again and both scirpts work fine now.

Once agian thanks alot, this forum was very helpful.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ