I having a hard time to combine my scripts which work separately...

basicly I have a batch script with following in it:

START "" "mpc-hc64.exe" "video.avi"

this will open my video in mediaplayer. so far so good. then I had some reading on SO and SE about how to open window on set position via cmd/bat and found out in answers about AutoHotkey (documentation: here). so I downloaded a zip with executable and created a AHK script:

Run mpc-hc64.exe
WinWait, Media Player Classic Home Cinema
WinMove A,, 960, 0, A_ScreenWidth-960, A_ScreenHeight-29

this will open my mediaplayer at the right side of my screen if I run this cmd/bat:

AutoHotkeyU32.exe "script 1.ahk"

and now I would need to combine all above into one batch which if I run it thet it will open my video file in my mediaplayer and on the right side of my screen. can enyone help?

  • 1
    Put both commands in the same batch file. – DavidPostill May 20 '18 at 6:58
  • @DavidPostill lol, like I wouldnt try that already... – gamer0 May 20 '18 at 10:24
  • So why didn't you say so in your question? What happened when you tried? – DavidPostill May 20 '18 at 10:25
  • @DavidPostill well, I wouldnt ask my question here if it would work, would I... happened what is already obvious from my post... eather I can open my video in player with no possition or open my player on window position without my video. so with combo of my codes happens this: video will open in my player on almost full screen ocupation and then 2nd player will open over my first player but now vithout video however on desired position. – gamer0 May 20 '18 at 10:34
  • So fix your ahk script to act on the current player instead of opening a new one. – DavidPostill May 20 '18 at 10:38

Can you use parameters to pass the commandline argument to the script?

I didn't test this code below, but the basic concept would be to use commandline variables in both the .bat file and the .ahk file to capture what the user types on the commandline and pass it through to be executed.


C:\>launch video.avi


@echo off
AutoHotkeyU32.exe "script 1.ahk" %1

script 1.ahk

Run mpc-hc64.exe %1%
WinWait, Media Player Classic Home Cinema
WinMove A,, 960, 0, A_ScreenWidth-960, A_ScreenHeight-29

I found a way (on official discord AHK chanel):


mpc := "C:\T4\mpc-hc 1.7.16 x64\mpc-hc64.exe"
avi := "C:\T1\scripts\avi.avi"

Run, % """" mpc """ """ avi """", , , pid

WinWaitActive, % "ahk_pid " pid
WinGet, mpc_hwnd, ID, % "ahk_pid " pid

SetTimer, CheckWindowPosition, 100

    if(!WinExist("ahk_pid " pid)) {
    WinGetPos, x, y, width, height, % "ahk_pid " pid
    WinGet, hwnd, ID, % "ahk_pid " pid
    if(DllCall("GetParent", "Ptr", hwnd, "UInt", 3) = 0 && DllCall("GetAncestor", "Ptr", hwnd, "UInt", 3) = mpc_hwnd) {
            if(x != 960 || y != 0 || width != A_ScreenWidth - 960 || height != A_ScreenHeight - 29) {
            WinMove, % "ahk_pid " pid, , 960, 0, % A_ScreenWidth - 960, % A_ScreenHeight - 29
  • But your question states.... "now I would need to combine all above into one batch"..... uh..... this is just AHK script only, correct? Furthermore, just as FYI since you appear to be able to figure out things pretty well in your automation tasks AutoIT is FREE, simple, and does not require any installs to do similar such tasks and you can compile into an executable that will run from any machine if you test properly. That's just FYI since you seem to figure out and understand logic and code pretty well in case you get time to read/review. – Pillsbury IT Doughboy May 26 '18 at 4:08
  • @PimpJuiceIT the drill was that I was missing few parts in AHK script which I thought I will compensate by using cmd, but that was the wrong way of thinking. yes this is AHK-only and I call it from batch like this AutoHotkeyU32.exe "script 1.ahk" and all works. whit this one I've got huge help from AHK devs over AHK Official Discord, so no credit goes for me tho. – gamer0 May 26 '18 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.