1.

Solve : How do I create a batch file script to run another batch file??

Answer»

Hi all! I'm new to computer programming and command lines in batches, so please be patient with me. I'm trying to set up my computer so that my wife and kids can just turn it on, click on an icon, and PLAY any game they want.

With games like Assassin's Creed I and II and Dark SOULS, you have to disable all of the HID-compliant game controllers other than an X360 controller before you can use it. To make this easy, I downloaded the "devcon" program from Windows. On my computer, its executable file is in C:\Program Files (X86)\Windows Kits\10\Tools\x64. I created a batch file in the same folder - "EnableXBOX1.bat" - that enables the X360 controller and disables the others. Then I created a batch file - "EnableAll.bat" - that enables all the controllers. Both these batch files work fine.

What I'm trying to do now is create a third batch file for my desktop (or for a shortcut from my desktop) that will (1) run the "EnableXBOX1.bat" file (to make the controller work), (2) run the game (which, say, is on my G drive), (3) on exiting the game, run the "EnableAll.bat" file (to get all the controllers enabled again) and exit.

This seemed simple to me, but I just can't get the bat files to run. I've tried the start and call commands, but something about my syntax has got to be wrong. Can anyone give me some syntax that would work to do this seemingly simple thing? Thanks so much!Since each game requires an .exe to start/run you would have to build them for each game as the paths are all different...Thanks, but yes, I know that. I'm asking what the command lines I would use.

For example, if I'm trying to have the batch file do the following, what's the actual syntax?

1) Run "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableXBOX1.bat"
2) Run "G:\Darksouls.exe"
3) Run "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableAll.bat"
Code: [SELECT]Call "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableXBOX1.bat"
"G:\Darksouls.exe"
Call "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableAll.bat"
Quote from: bacchuspup on July 15, 2016, 09:43:33 PM

Thanks, but yes, I know that. I'm asking what the command lines I would use.

1) Run "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableXBOX1.bat"
2) Run "G:\Darksouls.exe"
3) Run "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableAll.bat"


This modification allows you to call the script below say gamerun.bat
and in each shortcut for a game you can replace the target executable "c:\folder\gamefile.exe" with the line below and it should do the steps you want. This only requires the one gamerun.bat file but a side effect with a batch script in this way is that a cmd window will be on the taskbar during the gameplay.

Code: [Select]%comspec% /c "c:\folder\gamerun.bat" "c:\folder\gamefile.exe"

Code: [Select]@echo off
Call "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableXBOX1.bat"
start "" /w %*
Call "C:\Program Files (X86)\Windows Kits\10\Tools\x64\EnableAll.bat"Thanks guys... I had tried the Call command before, but it didn't work before and it still isn't working, and I have no idea why.

To simplify things, I made a G drive file "DeviceManager" that holds devon.exe and EnableXBOX.bat. When I double-click on EnableXBOX.bat, I can tell it works, because it enables & disables the controllers as instructed.

Then I made a bat file in a separate G drive file. The only script I included in it was this:

Call "G:\DeviceManager\EnableXBOX.bat"

So if I run that bat file, it should run the "EnableXBOX.bat" file the same as if I had run it directly, right? Only it doesn't. None of the controllers are enabled or disabled in accordance with the EnableXBOX.bat commands.

I have no idea why the Call command in the second bat file isn't making the first bat file run. I'm going to try a work-around and just put the devcon.exe file in the same folder as the file with all my game SHORTCUTS. That way I shouldn't have to run a batch file from another batch file. But I wish I could figure out why I can't do this when it seems so simple.

For what it's worth, I'm on Windows 10.Well, my work-around worked... sorta. For the Dark Souls game, I just put this batch together in the same folder as devcon.exe:

@echo off
devcon enable "{Xbox controller}"
devcon disable "{the other HID controllers}"
"G:\darksouls.exe"
TIMEOUT /t 30
devcon enable "{the other HID controllers}"

This works - when I click on this batch file, the game starts with the proper controller enabled and the others disabled, then after 30 seconds enables the other controllers (I do this to make sure the game starts). As long as the game starts with the other controllers disabled, the X360 controller still works.

The only issue is that when the enable kicks in after the 30 seconds, it minimizes the game and shoots me back to my desktop. I know all I have to do then is click on the game icon again, but that's inelegant. Is there any way to have the script either execute the last instruction (1) after exiting the game, or (2) in the background, so it doesn't minimize the game?

Thanks again for the help!!!Quote
Then I made a bat file in a separate G drive file. The only script I included in it was this:

Call "G:\DeviceManager\EnableXBOX.bat"
Do you mean in a separate G drive folder? You need to put devcon.exe in that folder, or else include the full path to devcon.exe in EnableXBOX.bat. Otherwise it won't see devcon.exe.
Ah - okay, I think that makes sense. Still, now I think I need more the answer to my other question - which is whether there's any way to have the script

(1) disable the applicable controllers (which I now know how to do),
(2) start the game (again, I now know how to do), then
(3) enable the controllers without interrupting the game - either by waiting until exiting the game or by enabling them without minimizing the game.

It's #3 that I can't seem to figure out. Thanks.Does it do that for all games or just selected ones?
It's not a usual behaviour for command line tools and devcon itself may be the problem if all games do this.

You can place devcon.exe on the path and it will work from any folder.

C:\windows or c:\windows\system32 are fairly good spots for this.


Discussion

No Comment Found