Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by fanling3 · May 18, 2012 at 02:27 AM · process

Kill external process in Unity

I'm trying to open an external program in Unity and kill it afterwards by using this code:

 Process myProcess;
 string path;

 path = Application.dataPath + "movie.avi";
 myProcess = new Process();
 myProcess.StartInfo.FileName = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
 myProcess.StartInfo.Arguments = path;
 myProcess.Start();

To kill it:

 myProcess.CloseMainWindow();

Opening the file works fine, but I got the following error when Unity tries to kill it:

 SystemException: No process to kill.

How to solve this? Thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · May 18, 2012 at 09:42 AM 0
Share

Also you shouldn't use an absolute hardcoded path. This wouldn't work on my pc because the "Program Files" folder is called different on a german installation ;) (or any other language)

You should be able to read the full media player application path from this registry key:

 [H$$anonymous$$EY_LOCAL_$$anonymous$$ACHINE\SOFTWARE\$$anonymous$$icrosoft\$$anonymous$$ultimedia\W$$anonymous$$Player]
 "Player.Path"

alternatively you could use Environment.GetFolderPath to get the actual "Program Files" path.

Anyway you should check if the media player is even installed / the exe file exists ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by fanling3 · May 19, 2012 at 02:36 AM

Finally I got a solution:

 foreach (Process p in Process.GetProcessByName("wmplayer")) {
    p.CloseMainWindow();
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SweatyChair · Sep 10, 2018 at 12:23 AM 0
Share

I wanna kill the process in OnApplicationQuit, and this seems to be the only way it works! Thx.

avatar image
1

Answer by Claytonious · May 18, 2012 at 08:56 AM

Try:

 myProcess.Kill();

Instead of:

 myProcess.CloseMainWindow();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fanling3 · May 19, 2012 at 02:34 AM 0
Share

They have the same result

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

System.Diagnostics.Process.StandardInput not defined. 1 Answer

Cross-platform way to start new process? 1 Answer

Detect how much RAM is available? (IL2CPP) Process.GetCurrentProcess().WorkingSet64 returns zero 0 Answers

How can I start a process to open Finder to point to a file? 1 Answer

Problem in starting mysqld Process 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges