?
Solved

I need help to translate a really simple batch file to VBS

Posted on 2011-04-19
8
Medium Priority
?
377 Views
Last Modified: 2012-05-11
Hi,

We have a batch file with the following code.  

psservice \\servername restart messenger

The batch file is not supported by the scheduler system that we are using and it needs to be moved to vbs.

Can someone help me out to translate this into a VBS?

Thank you.

---------------------

Usage: psservice [\\computer [-u username] [-p password]] <command> <options>

query Displays the status of a service.
config Displays the configuration of a service.
setconfig Sets the start type (disabled, auto, demand) of a service.
start Starts a service.
stop Stops a service.
restart Stops and then restarts a service.
pause Pauses a service
cont Resumes a paused service.
depend Lists the services dependent on the one specified.
security Dumps the service's security descriptor.
find Searches the network for the specified service.
\\computer Targets the NT/Win2K system specified. Include the -u switch with a username and password to login to the remote system if your security credentials do not permit you to obtain performance counter information from the remote system. If you specify the -u option, but not a password with the -p option, PsService will prompt you to enter the password and will not echo it to the screen.
0
Comment
Question by:llarava
  • 5
  • 2
8 Comments
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35426935

set args=wscript.arguments
strcomputer = args(0)
cmd = "psservice \\" & strcomputer & " restart messenger"

set WshShell = WScript.CreateObject("WScript.Shell")
wshShell.run cmd
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35426949
You may need to change this...
cmd = "psservice \\" & strcomputer & " restart messenger"

...to include the FULL PATH to psservice.
cmd = "C:\psservice.exe \\" & strcomputer & " restart messenger"

0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35426983
Oh...I forgot...
You have to call it like this...

script.vbs "computername"

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:llarava
ID: 35427061
The servername has to be hardcoded within the script.

set args=wscript.arguments
strcomputer = server1
cmd = "C:\temp\psservice \\" & strcomputer & " restart messenger"

set WshShell = WScript.CreateObject("WScript.Shell")
wshShell.run cmd

Line2 / Char 13 error
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35427110
...just put it in like this.

cmd = "cmd /c C:\temp\psservice \\server1 restart messenger"
0
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 2000 total points
ID: 35427119
..syntax.


strcomputer = server1

...should have been...

strcomputer = "server1"
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35429117
Just curious, what scheduler are you using, seems a little odd that it would support VBS scripts, but not BAT or CMD scripts.

~bp
0
 

Author Comment

by:llarava
ID: 35429203
I had the same thought when someone said this to me today...

This is all custom made by one of our vendors that is no longer in business. This is just a patch in order for their custom app to run. We will be replacing this as soon as we are done testing the new business app.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question