Question

Whenever i launch my program from within Visual Studio 2012 it wil execute the following code correctly:

        int oskID = System.Diagnostics.Process.Start("c:\\WINDOWS\\system32\\osk.exe").Id;
        Thread.Sleep(1500);
        System.Diagnostics.Process.GetProcessById(oskID).Kill();

However when i run the .exe from outside VS 2012 just you do with every program, the OSK will not close and i will be prompted with the following error: Process with id ...... is not being executed.

What is the correct way to shut down one specific OSK? And what is wrong with my code? Running as Administrator does not change anything.

Was it helpful?

Solution

What is the correct way to shut down one specific OSK?

Is it even possible to have more than one instance of OSK open?

How about this instead?

        System.Diagnostics.Process.Start("c:\\WINDOWS\\system32\\osk.exe");
        Thread.Sleep(1500);
        foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("osk"))
        {
            p.Kill();
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top