?
Solved

Execute batch script from another server

Posted on 2011-05-13
11
Medium Priority
?
435 Views
Last Modified: 2012-05-11
Server A has batch script on it that I would like to execute from Server B. What is the best way to do this? In c#
0
Comment
Question by:jessieBoo
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:dennisbbb
ID: 35755007
I would use a tool called PSEXEC http://technet.microsoft.com/en-us/sysinternals/bb897553
From ServerB prompt, type psecec \\ServerA -U administrator -P pass -c -f -h c:\myscript.anything
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35755078
I understand that you have a batch file that lives on Server A, I'm a little unclear on where you want it to execute - Server A or Server B?
0
 

Author Comment

by:jessieBoo
ID: 35755121
I want to execute the batch script on Server A from Server B.

PSEXEC will not work for me because it will always return error code 1.  Internet searches show I’m not the only one having this problem.
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.

 
LVL 18

Expert Comment

by:dj_alik
ID: 35755319
Build Webservice on Server A and call It from Server B
0
 

Author Comment

by:jessieBoo
ID: 35755328
Can I use a powershell script?
0
 
LVL 10

Expert Comment

by:GlobaLevel
ID: 35755357
have the batch script or vbscript on server A check a database every so often..user task scheduler to manage...

On server b if you want to launch write a value to that db with a value "launch"..next time the batch checks that table in five miuntes..it will see value and run...
0
 

Author Comment

by:jessieBoo
ID: 35755371
Can anyone tell me how to code this in powershell using the invoke command?
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 35755404
you post  your question in C# theme.
0
 

Author Comment

by:jessieBoo
ID: 35755416
Yes, but I'm doing my own research and it looks like powershell may be an easy solution. I'm not looing for somethin I can find myself on google.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 1000 total points
ID: 35758813
>> I want to execute the batch script on Server A from Server B.

Hmm...that still doesn't really answer my question. ;)  If the batch script has rmdir c:\someFolder should the folder be removed from server A or B?  I'm guessing your C# program will be running on B, and you want to launch the batch script on A (i.e. the folder would be removed from A)?

If that's right, you can use WMI to remotely start a process: http://www.codeproject.com/KB/cs/Remote_Process_using_WMI_.aspx

Since PowerShell is .Net based you might be able to make that example work in PowerShell too - sorry, I'm not too familiar with PowerShell or it's Invoke method - you would probably be better off asking a new question in the PowerShell zone (otherwise PowerShell guru's might not see this post).

If you just want your program on Server B to simply load a batch file that is stored on Server A and execute it locally (i.e. the folder would be removed from Server B), then you can just use System.Diagnostics.Process to run "cmd.exe" and pass it the path to the batch file, e.g. \\ServerA\c$\some\folder\batch.cmd
0
 

Author Closing Comment

by:jessieBoo
ID: 35768826
Thanks! your suggestion will work as well.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline

862 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