0

I'm trying to make a bat file that when launched will open a mediafile and close after x-number milliseconds.

mediaplay [play time] [audio file]

I'm trying to use nircmd's media play command, but it dosen't recognize it. I've tried the following codes in cmd.

C:\Users\Lind>mediaplay 10000 "C:\Users\Lind\Music\1.mp3"
'mediaplay' is not recognized as an internal or external command,
 operable program or batch file.

I've also tried this but nothing happend

C:\Users\Lind>nircmd.exe mediaplay 10000 "C:\Users\Lind>Music>1.mp3"

**************************************Update************************************

I found out that I've made a mistake in the mp3 file directory name, now it just says

C:\Users\Lind>nircmd.exe mediaplay 10000 "C:\Users\Lind>Music\1.mp3"

Access is denied.

I've tried using cmd as an adminstrator, but then nothing happens.

ChrisM
  • 1,576
  • 6
  • 18
  • 29

3 Answers3

1

If you do not provide the location of nircmd.exe you will need to make sure that nircmd.exe resides within the current directory or a location defined under %PATH%:

Here's an example for you:

@Echo Off
Rem MediaPlay command
Set "mp="C:\Users\Lind\Utilities\NirSoft\nircmd.exe" MediaPlay"

Rem MusicFile location
Set "mf=C:\Users\Lind\Music\1.mp3"

Rem MilliSeconds
Set "ms=10000"

Rem Start it
Start "" %mp% %ms% "%mf%"

Just change the values after the = for the three Set statements as required, (but do not remove or change any of the "'s).

Note: nircmd.exe and nircmdc.exe are both flagged as potential security threats by most antivirus/antimalware programs. If you have one of those then, you'd have to see if you can make an exception for it to run from within your security software.

Compo
  • 36,585
  • 5
  • 27
  • 39
0

In order to execute any external command (ie. any command that is not internal to cmd.exe itself), then you need to do one of the following:

  1. Specify the precise location of the executable (eg use "c:\wherever\your\mediaplay\is located\mediaplay" in place of mediaplay (quotes required if the path or executable name contains separators like spaces))

  2. Include the directoryname for mediaplay into the path variable. This can be done on a permanent basis by using Control Panel>System>Advanced System Settings>Advanced>Environment Variables or preferably by using a dedicated editor like Path Editor or on a temporary basis by prefixing that path; to the path variable within a batch or manually from the prompt.

  3. Navigate to the mediaplayer directory using the three lines "pushd mediaplayerdirectoryname", "mediaplayer...", "popd" (all without the quotes)

The last method is a special case of the second which uses the windows' executable-search strategy to look for an executable first in the current directory, and then in each directory specified in the path variable in turn until the executable is found.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • But i think it's not internal to cmd.exe itself, mediaplay is a command from nircmd. Although really appreciate all the help. – Hans Jørgen Lind Jørgensen Dec 31 '17 at 04:09
  • But i found out but i've made a mistake in the mp3 file directory name, now it just says `C:\Users\Lind>nircmd.exe mediaplay 10000 "C:\Users\Lind>Music\1.mp3" Access is denied.` – Hans Jørgen Lind Jørgensen Dec 31 '17 at 04:17
  • no, windows makes a pop-up that says "This app can't run on your pc" – Hans Jørgen Lind Jørgensen Dec 31 '17 at 04:22
  • i've triad using cmd as an adminstrator, but then nothing happens – Hans Jørgen Lind Jørgensen Dec 31 '17 at 04:29
  • It's certainly not an internal command to `cmd`, therefore one of the three techniques I mentioned should work. `C:\Users\Lind>Music\1.mp3` is incorrect. A directory-delimiter is `\`. `>` is a redirector. The pop-up is from the operating system itself indicating that it's found the executable, but can't run it. Possibly it's too old a version and you need a new version of `nircmd.exe`. – Magoo Dec 31 '17 at 07:45
0

Double check if you didn't turn the nircmd.exe file into a empty file using that command you just did. It should not be a 0kb file. I made the same mistake and turned my exe into a empty file.

Reinstall Nircmd and you should be good with the new command.

VIRNARRA
  • 11
  • 3