Running .bat over network

13,422

Solution 1

Main Point

It makes better sense to just use PSExec to keep this simple for your particular need. The syntax is rather intuitive and typically just works, but the sample syntax I provided below should be all you need to use to make it work once connected to the VPN.

I'm not sure if you run this from the VPN-connected PC if the username will need to be <domain>\<username> but keep this in mind when testing if you have trouble.

Sample Syntax

Important Note: Run from VPN-connected PC, point the BAT file path as it is from the Game Server's perspective

psexec -u user - p password \\remotepc "c:\mybatchfile.bat"

Further Ideas

Different Example: If the application runs in memory whether or not it's a service then the below will look to confirm that it's running in memory. If it's not you could then tell it to run your process. I'm not sure if it gets hung up and when that occurs you cannot find it running with TASKLIST, but that may be something to check. You could then schedule something like the below to run twice a day, etc. to automate the process.

@ECHO OFF
:::: The remote machine the TASKLIST command is run against must accept incoming WMI traffic from the machine sending the request
::::  Enabling the firewall rule "Windows Management Instrumentation (WMI)" should do the trick
TASKLIST /S ServerName | FINDSTR /I applicationname.exe
IF ERRORLEVEL 1 (GOTO :StartSomething) ELSE (GOTO :EOF)

:StartSomethink
pushd %~dp0
cd /d %CD%
start /b "Dayz Epoch Server" /min "DayZ_Epoch_instance_11_Chernarus.bat"
timeout 15
cd "C:\Users\LostandCrazy\Desktop\DayZ Server\instance_11_Chernarus\BattlEye\Bec"
start  "UEP BattlEye Extended Control" /min "BEC.exe" -f "Config.cfg"
taskkill /f /im cmd.exe
GOTO :EOF

Original Thoughts, etc.

Since you say the (batch) BAT file is on the server, and this server is what you connect to when you connect to the VPN then. . .

  • when you connect to the VPN, remotely connect to the server by signing onto it via RDP, and then launch the BAT file from there

Note: If the BAT file is on the server in the first place, I have no idea why it's even be on your VPN-connected PC so that part is confusing to me.

  • The batch file will need to be run from the server so you need it to run on the server itself. You can setup a scheduled task and automate this too, or connect to the server via RDP to kick off manually, etc.
  • You're not going to be able to launch an EXE file from your "main" PC, etc. that's on \\servername\c$\program files\~ and expect that to run in memory on the server.

An Update

  • With RDP you are only dragging the screen, mouse clicks, and keyboard strokes across the network (i.e. VPN Internet tunnel in your case). This means that RDP is typically a rather efficient protocol in terms of network traffic.

  • Launching it remotely may be possible from the VPN-connected device assuming it's connected to the domain of the VPN you connect to and the server you want to launch it from is able to authenticate any remote commands you send to the server to launch it.

  • If the VPN-connected device is not joined to the domain of the VPN you connect to and the server is not able to authenticate, then you may be able to launch some remote command with RUNAS, etc.

  • You could just RDP into the server and wait for it to load and then launch it that way, or else schedule a process—with task scheduler—on the server with the batch file, and automate so it doesn't need to be done manually.

  • There are batch script solutions you can put into place to "Do Something" when "Something" occurs. You can have it send you an email, etc. if "Something" occurs or is triggered.

Additionally. . .

  • PowerShell can execute processes, etc. remotely but you'd have to ensure prerequisites are in place and test to confirm it works as expected.
  • You can create a scheduled task on the server pointing to the BAT file and then potentially launch it remotely (so it would have NO SCHEDULE for automation so you could run ad hoc as-needed). Again, you'd have to test and confirm all this works as expected

Solution 2

Any time you use LAN paths or shared paths you need to use UNC syntax rather than drive letters. Do not use drive letters. Using UNC paths means shortcuts and bat files can be accessed from anywhere without issue. This is \\servername\folder\folder or \\machinename\folder\folder .

Share:
13,422

Related videos on Youtube

Baibro
Author by

Baibro

Updated on September 18, 2022

Comments

  • Baibro
    Baibro over 1 year

    I have a .bat file on my server pc which contains various file paths etc which are on that server pc. I have vpn set up so that I can access this pc from my main pc but when I launch the .bat it looks for the filepath on my computer and not on the server. I want to be able to launch this .bat on my computer and it launch the program and the filepath on the server pc not my pc. Anyone know how I can do this?

    P.s. the .bat file starts a game server and why it needs to be on that computer and not mine

  • Baibro
    Baibro over 8 years
    The server computer is at another location and thats why I cant launch it directly on there. My internet at my home is slow and RDP is not very efficient. Thats why I connected to vpn so I can view and share files on the server PC with my main PC. Is there any way to launch a bat like i would be double clicking it on the server pc from my home pc without RDP? Nothing i can launch from home pc over vpn?
  • Baibro
    Baibro over 8 years
    Yes that is exactly what I want to do, execute a process on computer A from computer B but without RDP if possible, is there a command or something I can send over cmd or something to execute the batch file? And the server automatically restarts every 3 hours but sometimes on a rare occasion it can crash, and I want to be able to start it form my computer and not wait for ages with crazy input lag and do it over RDP (as i have a high latency internet connection) so what do you think is the best solution for doing this other than RDP? and thanks for helping me out so much by the way :)
  • Baibro
    Baibro over 8 years
    The bat file contains this code pastebin.com/raw.php?i=sUKR3tcT OS is Windows 10 pro And the vpn is just simple for reading .txt log files on the server, im not RDP through that or anything just for the files. If i can get this to work then I will not need to use RDP at all which is what im trying to do. Is that all you need im not sure what is needed to do this?
  • subjectivist
    subjectivist over 8 years
    Unless the process being invoked relates to installed software on the game PC, it doesn't matter what machine it runs on. All files and paths have to be accessible and referenced via UNC paths and not drive letters. Invoking a bat file having C:\zzz means an attempt will be made to use C:\zzz at the machine running the job. This is why UNC paths are needed. Obviously, if this has to do with "installed" software, an attempt can be made to run on any machine, but needed libraries will not be present on other machines. Using UNC paths is not a way to circumvent installation of software.