Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't control volume using PHP exec command and NirCmd

Tags:

php

I'm running wampserver 2.2 on Windows 7, and I'm trying to use NirCmd to mute windows volume. My code is:

<?php
exec("c:\nircmd\nircmdc mutesysvolume 1");
?>

The command seems to work well, and mute my sound when run not via PHP, but doesn't work through PHP.

Help anyone? Or any other suggestions on how to make a remote control using PHP?

Thanks

like image 379
Omri Segal Avatar asked Dec 05 '25 06:12

Omri Segal


2 Answers

The sequence \n inside a double-quoted string resolves to a newline character, destroying your path.

You can use single quotes instead:

exec('c:\nircmd\nircmdc mutesysvolume 1');

Or, even better, use forward slashes instead of backslashes to avoid the problem entirely:

exec('c:/nircmd/nircmdc mutesysvolume 1');
like image 146
Jon Avatar answered Dec 08 '25 16:12

Jon


if you use double quoted string do it like ( and try .exe ). Or like "Jon" said use forward slashes.

exec("c:\\nircmd\\nircmdc.exe mutesysvolume 1");
like image 25
moskito-x Avatar answered Dec 08 '25 17:12

moskito-x



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!