VOGONS

Common searches


First post, by Cosmin

User metadata
Rank Newbie
Rank
Newbie

Hello all!
I am trying to create a batch file that run DOSBox.exe, and then send input keys (such that dosbox will think that I pressed a certain key). I created it and it works perfectly with notepad.exe.
My problem is that when I go to change the pathname to open DOSBox.exe instead of notepad.exe, it gives me an error:
ERROR: Cannot find the specified file
ERROR CODE: 80070002

Here the code:

(echo with createobject^("wscript.shell"^)
echo .run "C:\Program Files (x86)\DOSBox-0.74-3\DOSBox.exe" <-------------if i change this with "notepad.exe", it works
echo wscript.sleep 2000
echo .sendkeys "MOUNT D: D:\"
echo .sendkeys "{enter}"
echo wscript.sleep 1000
echo .sendkeys "D:"
echo .sendkeys "{enter}"
echo .sendkeys "DIR"
echo wscript.sleep 1000
echo .sendkeys "%%{F4}"
echo end with) > %temp%\sk.vbs
start /w %temp%\sk.vbs

Attachments

  • image.png
    Filename
    image.png
    File size
    66.36 KiB
    Views
    1039 views
    File comment
    Windows script host error
    File license
    Public domain

Reply 1 of 7, by _Rob

User metadata
Rank Member
Rank
Member

You can have a (possibly per-game) dosbox config file with an [autoexec] section where you do the steps such as MOUNT or change drive or run DIR. No need to use an external script.

e.g.

[autoexec]
MOUNT D: D:\
D:
DIR

In addition some dosbox forks (e.g. DOSBox-X or -staging) have support for AUTOTYPE which can be used to perform scripted keyboard entries into a running DOS program.

Reply 3 of 7, by Stretch

User metadata
Rank Member
Rank
Member

Replacing the 2nd line with the following code may work also

echo .run Chr(34) & "C:\Program Files (x86)\DOSBox-0.74-3\DOSBox.exe" & Chr(34)

Win 11 - Intel i7-1360p - 32 GB - Intel Iris Xe - Sound BlasterX G5

Reply 4 of 7, by Cosmin

User metadata
Rank Newbie
Rank
Newbie
Stretch wrote on 2022-03-05, 20:17:
Replacing the 2nd line with the following code may work also […]
Show full quote

Replacing the 2nd line with the following code may work also

echo .run Chr(34) & "C:\Program Files (x86)\DOSBox-0.74-3\DOSBox.exe" & Chr(34)

That works! Now it opens DOSBox.exe but does not send input keys. After run DOSBox.exe it stops and does not execute the rest of the commands. Then, if I manually close the tab, the commands continue, and it prints an error like in the photo:

Attachments

  • 1.png
    Filename
    1.png
    File size
    27.08 KiB
    Views
    971 views
    File comment
    runs dosbox but does not send any input keys
    File license
    Public domain
  • 2.png
    Filename
    2.png
    File size
    31.13 KiB
    Views
    971 views
    File comment
    the error after closing dosbox tab manually
    File license
    Public domain

Reply 5 of 7, by Stretch

User metadata
Rank Member
Rank
Member

I almost had it working except the mount command didn't work for me. You may want to consider autohotkey or autoit instead.

(echo with createobject^("wscript.shell"^)
echo .run "C:\PROGRA~2\DOSBox-0.74-3\DOSBox.exe"
echo wscript.sleep 2000
echo .AppActivate "DOSBox 0.74-3"
echo wscript.sleep 250
echo .sendkeys "MOUNT D D:\"
echo wscript.sleep 250
echo .sendkeys "{enter}"
echo wscript.sleep 1000
echo .sendkeys "D:"
echo wscript.sleep 250
echo .sendkeys "{enter}"
echo wscript.sleep 250
echo .sendkeys "DIR"
echo wscript.sleep 250
echo .sendkeys "{enter}"
echo wscript.sleep 1000
echo .sendkeys "%%{F4}"
echo end with) > %temp%\sk.vbs
start /w %temp%\sk.vbs

Win 11 - Intel i7-1360p - 32 GB - Intel Iris Xe - Sound BlasterX G5

Reply 6 of 7, by Cosmin

User metadata
Rank Newbie
Rank
Newbie

Thank you so much!
So I don't know why it can't send long strings.
Using this :

echo .sendkeys "MOUNT D D:\"

It print only "MOUNT D" then it stops.
So, i separated the string into multiple sendkeys and then it works perfectly.

echo .sendkeys "MOUNT "
echo wscript.sleep 250
echo .sendkeys "D "
echo wscript.sleep 250
echo .sendkeys "D:\"
echo wscript.sleep 250
echo .sendkeys "{enter}"

Reply 7 of 7, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie

This is a very roundabout (and hacky) way of doing things (using an external program to send keypresses to the DOSBox application) when DOSBox already supports individual config files and startup commands. Not to mention batch files.

A case where everything looks like a nail when you're holding a hammer, I guess.