Powershell start-process hidden wmplayer file with spaces

647 views Asked by At

powershell Start-Process -WindowStyle Hidden 'C:\Program Files\Windows Media Player\wmplayer.exe' c:\windows\media\notify.wav run ok.

powershell Start-Process -WindowStyle Hidden 'C:\Program Files\Windows Media Player\wmplayer.exe' c:\windows\media\windows background.wavrun bad.

powershell Start-Process -WindowStyle Hidden 'C:\Program Files\Windows Media Player\wmplayer.exe' 'c:\windows\media\windows background.wav'run bad.

powershell Start-Process -WindowStyle Hidden 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\windows\media\windows background.wav"run bad.

powershell "& 'C:\Program Files\Windows Media Player\wmplayer.exe' 'c:\windows\media\windows background.wav'" run ok but it's no hidden.

¿How fix the spaces in the arguments, please?

2

There are 2 answers

0
wyxchari On

No visible player:

powershell (New-Object Media.SoundPlayer 'c:\windows\media\windows background.wav').PlaySync()

powershell $PLAYER = New-Object Media.SoundPlayer; $PLAYER.soundlocation='C:\windows\media\windows background.wav'; $PLAYER.PlaySync()

powershell Add-Type -AssemblyName presentationCore; $mediaPlayer = New-Object system.windows.media.mediaplayer; $mediaPlayer.open('c:\windows\media\windows background.wav'); $mediaPlayer.Play(); start-sleep 3

The sound file does not support spaces: *********************

powershell Start-Process -WindowStyle Hidden 'C:\Program Files\Windows Media Player\wmplayer.exe' c:\windows\media\notify.wav & timeout 3 >nul & taskkill /f /im wmplayer.exe>nul

Visible player:

"C:\Program Files\Windows Media Player\wmplayer.exe" "c:\windows\media\windows background.wav" & timeout 3 >nul & taskkill /f /im wmplayer.exe>nul

W10:

start "" "c:\windows\media\windows background.wav" & timeout 3 >nul & taskkill /f /im music.ui.exe>nul

start "explorer.exe shell:" "c:\windows\media\windows background.wav" & timeout 3 >nul & taskkill /f /im music.ui.exe>nul

W11:

start "" "c:\windows\media\windows background.wav" & timeout 3 >nul & taskkill /f /im microsoft.media.player.exe>nul

start "explorer.exe shell:" "c:\windows\media\windows background.wav" & timeout 3 >nul & taskkill /f /im microsoft.media.player.exe>nul
2
DaSe On

Do you need to do it with wmplayer.exe? The application will not be visible but it will stay loaded as a process to find in taskmanager or Get-Process. The way is more in line with:

powershell (New-Object System.Media.SoundPlayer('c:\windows\media\Windows Battery Critical.wav')).PlaySync()