473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run bat file on remote machine

What is the best way to have my windows app run a .bat file on a remote
server? The .bat will need to run as an admin on the remote machine.
Additonally I need for my windows app to wait for the .bat to finish.

Aug 26 '06 #1
7 10114
have a look at the process names pace assuming you have a share or some way
to access the remote machine, this should work.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Ctal" <wi********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
What is the best way to have my windows app run a .bat file on a remote
server? The .bat will need to run as an admin on the remote machine.
Additonally I need for my windows app to wait for the .bat to finish.

Aug 26 '06 #2

"Ctal" <wi********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| What is the best way to have my windows app run a .bat file on a remote
| server? The .bat will need to run as an admin on the remote machine.
| Additonally I need for my windows app to wait for the .bat to finish.
|

There is nothing in .NET that makes this possible, even WMI is not able to
start a process as a local admnistrator on a remote system.
Take a look at psexec at
h<ttp://www.sysinternals.com/Utilities/PsExec.html>, this utility can run a
process on a remote system with specified credentials, from your code you
can start psexec using Process.Start.

Willy.
Aug 26 '06 #3

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
| have a look at the process names pace assuming you have a share or some
way
| to access the remote machine, this should work.
|

Alvin, The OP's requirement is to run a batch file remotely, this is not
possible using this namespace. You need a client/server style application
like Sysinternals - www.sysinternals.com psexec.exe to run a process
remotely.
Willy.
Aug 26 '06 #4
I'm not sure what you mean here, the process class can start a local or
remote process. If you mean the bat file, then you are right, it won't start
it but that can be fixed easily by writing a small exe to either call the
bat file or reproduce the bat file functionality in the exe.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>
"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
| have a look at the process names pace assuming you have a share or some
way
| to access the remote machine, this should work.
|

Alvin, The OP's requirement is to run a batch file remotely, this is not
possible using this namespace. You need a client/server style application
like Sysinternals - www.sysinternals.com psexec.exe to run a process
remotely.
Willy.


Aug 27 '06 #5


"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
| I'm not sure what you mean here, the process class can start a local or
| remote process. If you mean the bat file, then you are right, it won't
start
| it but that can be fixed easily by writing a small exe to either call the
| bat file or reproduce the bat file functionality in the exe.
|
| --
|

While the Process class can be used to 'monitor' processes on remote
machines, it can't start (that is run a process remotely) or stop a process
on a remote machine. The Process class call's CreateProcess or
CreateProcessWithLogon, and these API's can only create local processes
(Windows has no API to create processes remotely).
If you have to run a process remotely, you have to resort to WMI, or another
C/S (like Psxec.exe) kind of architecture, here the 'client' requests the
'server' to start a process on a remote server (where it gets created as a
local process).
Willy.
Aug 27 '06 #6

Willy Denoyette [MVP] wrote:
"Ctal" <wi********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| What is the best way to have my windows app run a .bat file on a remote
| server? The .bat will need to run as an admin on the remote machine.
| Additonally I need for my windows app to wait for the .bat to finish.
|

There is nothing in .NET that makes this possible, even WMI is not able to
start a process as a local admnistrator on a remote system.
Take a look at psexec at
h<ttp://www.sysinternals.com/Utilities/PsExec.html>, this utility can run a
process on a remote system with specified credentials, from your code you
can start psexec using Process.Start.

Willy.
Thanks Willy, that looks promising. The other way I was approaching
this was with ado commands, my remote machine has sql server installed.
I was going to call xp_cmdshell and use that to launch the .bat (or
exe). That works if the SQL service account has the necessary
credentials (in my case it does)

Thanks all for the suggestions.

Aug 29 '06 #7
You are right Willy. I tried unsuccessfully to do this but it would only
fail silently. I swore I did this a couple years ago but when I went back to
check the code, it wasn't a actually a mapped drive, it was
d:\somepath\somefile.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>
"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
| have a look at the process names pace assuming you have a share or some
way
| to access the remote machine, this should work.
|

Alvin, The OP's requirement is to run a batch file remotely, this is not
possible using this namespace. You need a client/server style application
like Sysinternals - www.sysinternals.com psexec.exe to run a process
remotely.
Willy.


Aug 30 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3390
by: Rocket Hawk | last post by:
Hello All, I am using windows 2000 server IIS 5.0 i was trying to run bat file from asp page and getting: Access Denied but when i run the bat file from the command prompt on the local...
9
8832
by: Doug at SAU | last post by:
I need to run a batch file on a remote machine from an ASP page. I dummied up a test ASP page as follows: <% Set WshShell = Server.CreateObject("Wscript.Shell") wshshell.run...
5
6039
by: Ian Davies | last post by:
Hello I am trying to use php to automate the copying of a file from my remotely hosted directory to my computer. I have put together the following but it will only do the copying from one...
29
3361
by: Tola | last post by:
In my case of study, my teacher gave me a project, after I analysed the problem I found that I had to used open the file on the other machine? Please help? Thank you in advance. Tola CHROUK
1
3880
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt,...
1
3005
by: Saracen | last post by:
I have a major problem with trying to access a foxpro database from a web app. I have created a web app which is deployed on a server. The foxpro database (dbf) is on a different server. The...
18
4316
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
1
8102
by: Duffman | last post by:
Hi, I have what seems to be a common problem, but the solutions I've found don't seem to work. I would like to use a web service to create a file at a UNC location in a shared file. Currently...
5
17656
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.