locked
Problems with Process class RRS feed

  • Question

  • Hi, I am trying to use media player classic to open certain songs in my program and close it after some period of time. Here are the source codes:

    dim myProcess as Process = new Process()

    myProcess.start("mplayer2.exe", "C:\My Song.mp3")

    myProcess.WaitForExit(60000)

    myProcess.CloseMainWindow()

    As the program runs, it can open windows media player and play the song. However, it keeps on displaying exception like this "The process is not associated with certain object" (i don't quite remember the name) when it reaches waitforexit method. anyone can help me? thanks a lot.

     

    Tuesday, January 30, 2007 3:09 AM

Answers

  •  DMan1 wrote:

    In order to run another process beside the default file association process you will have to explicity start the exe file and use the sound file as an argument of the process...in other words when you do this Process.Start(MyFile.mp3) it automaticall starts the associated application...

    if you want the mp3 file to start with winamp for example then you will have to do something like this:

    Dim p As New Process

    p.StartInfo.FileName = "CompletePAthToWinamp"

    p.StartInfo.Arguments = "CompletePathToMyFile.mp3"

    p.Start()

    p.Waitforexit(60000)

    p.Kill

     

     

    This code works fine with other media players except Winamp. I found that you can't just write the arguments as a complete path to mp3 file cos Winamp will only display the path in separate lines. Winamp is unable to run the file at all. Does anybody know how to solve this problem? thanks a lot

    Thursday, February 1, 2007 7:45 AM

All replies

  • Since you are trying to force a shutdown of the application you may wish to use the StartInfo class of the process and redirect the standard error so that the message does not show...and then after your wait period use the kill method of the process to shut down the app
    Tuesday, January 30, 2007 4:52 AM
    Moderator
  • actually i have tried using ProcessStartInfo class to open the application, but is still keeps popping up the error message. is there any way to introduce delay rather than using WaitForExit method cos i am still a newbie in VB.NET? Thanks a lot
    Tuesday, January 30, 2007 6:01 AM
  • Supress the error message and then use Process.Kill
    Tuesday, January 30, 2007 3:07 PM
    Moderator
  • I have managed to supress the error messgae. thanks. Now I have another question to ask. My program is supposed to open different media player (eg.Winamp, Windows Media Player, etc) with different song that I input. The problem is that I can't manage to open different application as I clicked the button. I created different button for different media players. The program can merely open default player associated with certain file types (eg. mp3 is opened by Winamp, wma by Windows Media Player, etc). Can anybody help me with this problem? thanks a lot for your suggestion.
    Wednesday, January 31, 2007 4:50 AM
  • In addition, I created a Process class with the media player that is launched by the program. the media player is programmed to play for the amount of time that users input. initially, i utilize the WaitForExit() method, but it seems not working. if u use Process.kill(), it will stop the application immediately. any suggestions to add delay or other method?? thank u very much
    Wednesday, January 31, 2007 4:59 AM
  • In order to run another process beside the default file association process you will have to explicity start the exe file and use the sound file as an argument of the process...in other words when you do this Process.Start(MyFile.mp3) it automaticall starts the associated application...

    if you want the mp3 file to start with winamp for example then you will have to do something like this:

    Dim p As New Process

    p.StartInfo.FileName = "CompletePAthToWinamp"

    p.StartInfo.Arguments = "CompletePathToMyFile.mp3"

    p.Start()

    p.Waitforexit(60000)

    p.Kill

     

     

    Wednesday, January 31, 2007 3:46 PM
    Moderator
  • Thanks a lot for your suggestion.
    Thursday, February 1, 2007 5:39 AM
  •  DMan1 wrote:

    In order to run another process beside the default file association process you will have to explicity start the exe file and use the sound file as an argument of the process...in other words when you do this Process.Start(MyFile.mp3) it automaticall starts the associated application...

    if you want the mp3 file to start with winamp for example then you will have to do something like this:

    Dim p As New Process

    p.StartInfo.FileName = "CompletePAthToWinamp"

    p.StartInfo.Arguments = "CompletePathToMyFile.mp3"

    p.Start()

    p.Waitforexit(60000)

    p.Kill

     

     

    This code works fine with other media players except Winamp. I found that you can't just write the arguments as a complete path to mp3 file cos Winamp will only display the path in separate lines. Winamp is unable to run the file at all. Does anybody know how to solve this problem? thanks a lot

    Thursday, February 1, 2007 7:45 AM
  • I do not have winamp, however it sounds like it is only 8.3 compatible...Is it breaking the path at the spaces?  IF so then you will have to convert your path to be 8.3 compatible.  This is done by removing spaces from the path and then using the first 6 letters a tilde and then a numeric sequence number DOT the first three letters of the extension...so C:\Documents and Settings\User\My Documents\My Music\MySong.mp3 becomes C:\Docume~1\User\MyDocu~1\MyMusi~1\MySong.Mp3 Just a wag!
    Thursday, February 1, 2007 2:32 PM
    Moderator
  • I am interesting of problem of suppressing windows error messages. I'm tring to redirect standard error, but if does not prevent windows message box to appear. For example, i'm trying to use this code (sorry for not VB.NET):

    Process^ myProcess = gcnew Process;

    ProcessStartInfo^ myProcessStartInfo = gcnew ProcessStartInfo( "halter.exe" );

    myProcessStartInfo->UseShellExecute = false;

    myProcessStartInfo->RedirectStandardError = true;

    myProcess->StartInfo = myProcessStartInfo;

    try

    {

       myProcess->Start();

       StreamReader^ myStreamReader = myProcess->StandardError;

       Console::WriteLine( myStreamReader->ReadLine() );

    }

    catch (Exception^ ex)

    {

    }

    myProcess->Close();

    where halter.exe raises RangeCheckError exception. When I run this code, windows error message box appears with an error message like this "Unknow exception in ... at address...". More over, halter.exe process are still running until I manually close this message box.

    Can you help me, please, how can I suppress any error messages like that and how I can get information about unhandled exceptions in halter.exe and to get exit code right after it raises an unhandled exception? Thanks a lot.

    Friday, March 9, 2007 8:43 AM