12 Replies - 22488 Views - Last Post: 03 June 2010 - 03:50 PM Rate Topic: -----

#1 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Open On-Screen Keyboard in C#

Posted 24 May 2010 - 07:11 AM

Hi
I know I'm not the 1st one asking this question but I ran into a little problem while trying to open Microsoft On-SCreen Keyboard.
I'm developing an app that requires login. I decided to add the possibility to use the OSK as an extra security measure.
I used this code:
using System.Diagnostics;

private void btnOSK_Click(object sender, EventArgs e)
        {
            Process.Start(@"C:\windows\system32\osk.exe");
        }



and this
private void btnOSK_Click(object sender, EventArgs e)
        {
           System.Diagnostics.Process.Start("osk");
        }



The problem is that every time I click the OSK button I receive the message "Could not start On-Screen Keyboard".
This happens on my Win7 x64 machine. Please note that UAC is disabled, I am using an admin account and I run VS2008 as admin. Same thing on Vista.
However this doesn't happen on Windows XP. Moreover OSK.exe runs fine(the file is not corupt o my machine - know this sound stupd but I tried this too).
Any ideas how to solve this? If i try running notepad or calc or paint everything works fine....

Is This A Good Question/Topic? 0
  • +

Replies To: Open On-Screen Keyboard in C#

#2 Antiokus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 192
  • Joined: 06-September 06

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 08:18 AM

I had an app that I was working on that had this kind of problem. It was always random in my case. Though I never saw it happen with a windows command...

My temporary solution was to use shortcuts to the .exes that threw this error.

This post has been edited by Antiokus: 24 May 2010 - 08:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 08:24 AM

View PostAntiokus, on 24 May 2010 - 07:18 AM, said:

I had an app that I was working on that had this kind of problem. It was always random in my case. Though I never saw it happen with a windows command...

My temporary solution was to use shortcuts to the .exes that threw this error.

Thanks I'll give it a try and post back here.

LE
OK I tried something else.
I used a batch file containing this line %WINDIR%\system32\osk.exe
This was an incredible stupid idea. Not only that it didn't work (although it worked with notepad, calc, paint etc.) but it blocked my system and I ended up with a blue screen :| after receiving the error message "The specified file was not found".
On XP it worked fine, of course :| Same thing happened while using a shortcut to the osk.exe file....

This post has been edited by daydr3am3r: 24 May 2010 - 03:15 PM

Was This Post Helpful? 0
  • +
  • -

#4 No0Vad  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 18-February 10

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 08:43 AM

I just tried your code and it works fine on my machine, running Win7 x64. The On-Screen Keyboard opens.
Was This Post Helpful? 0
  • +
  • -

#5 batesy3k  Icon User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 03:03 PM

Your code also works on Win 7 Ultimate x32.
Was This Post Helpful? 0
  • +
  • -

#6 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 03:46 PM

I didn't try it on Win7 x32.
Till now I believed this is a Win7 & Vista error.
Now I don't know what to say.
I'll keep searching and post back.
---
A final thought - My Windows and VS are genuine, MSDNAA download.
I was asked ths before so I wanted to make it clear.
Was This Post Helpful? 0
  • +
  • -

#7 No0Vad  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 18-February 10

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 03:53 PM

Saw your edit, strange that it caused you a BlueScreen, you might have some malware. Try this

string windir = Environment.GetEnvironmentVariable("windir");
Process p = new Process();

p.StartInfo.FileName = windir + @"\System32\cmd.exe";
p.StartInfo.Arguments = "/C " + windir + @"\System32\osk.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;

p.Start();
p.Dispose();

Was This Post Helpful? 0
  • +
  • -

#8 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 04:14 PM

View PostNo0Vad, on 24 May 2010 - 02:53 PM, said:

Saw your edit, strange that it caused you a BlueScreen, you might have some malware. Try this

string windir = Environment.GetEnvironmentVariable("windir");
Process p = new Process();

p.StartInfo.FileName = windir + @"\System32\cmd.exe";
p.StartInfo.Arguments = "/C " + windir + @"\System32\osk.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;

p.Start();
p.Dispose();

Nope it didn't work.
--
I run a full system scan yesterday after cleaning up my HDD. Besides it's hard to have 2 machines + 1 VBox installation infected at the same time.
--
Any way I know what is causing the error.
I have a 7 project solution, every project using a MS ACCESS db.
I switched from Any CPU platform to x86 platform so that I can use the OLE DB driver.
I tried now using Any CPU platform and it worked.
Unfortunately, I have to use x86 so that I can use the DBs.
So I tried a few free OSK. Now the problem is that every time I try to open an external exe file using
Process.Start(@"|DataDirectory|\osk.exe");

I receive the error File not found...
I guess I have to find a way to fix this or to see how I can fix the porting error.
Was This Post Helpful? 0
  • +
  • -

#9 No0Vad  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 18-February 10

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 04:20 PM

I dont know what |DataDirectory| is, but if you have a external osk in the same folder as your application this will start it

Process.Start(Application.StartupPath + "\\osk.exe");

Was This Post Helpful? 1
  • +
  • -

#10 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 04:33 PM

Data Directory is the directory where the project output is located.
I used it with access db, usually like this
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = |DataDirectory|\DB.mdb;";

Anyway Application.StartupPath worked fine.
I'll try to use it from now on.
Thank you very much for your time :D. You saved my day :^:

Data Directory is the directory where the project output is located.
I used it with access db, usually like this
string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = |DataDirectory|\DB.mdb;";

Anyway Application.StartupPath worked fine.
I'll try to use it from now on.
Thank you very much for your time :D. You saved my day :^: Or night..

This post has been edited by daydr3am3r: 24 May 2010 - 04:33 PM

Was This Post Helpful? 0
  • +
  • -

#11 No0Vad  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 18-February 10

Re: Open On-Screen Keyboard in C#

Posted 24 May 2010 - 04:42 PM

Glad you got it working :)
Was This Post Helpful? 0
  • +
  • -

#12 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Open On-Screen Keyboard in C#

Posted 03 June 2010 - 01:40 PM

View PostNo0Vad, on 24 May 2010 - 03:42 PM, said:

Glad you got it working :)


I found a solution for the OSK problem
static void StartOSK()
{
  string windir = Environment.GetEnvironmentVariable("WINDIR");
  string osk = null;

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "sysnative"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
  {
    osk = "osk.exe";
  }

  Process.Start(osk);
}


Was This Post Helpful? 0
  • +
  • -

#13 lol1337  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 19-August 09

Re: Open On-Screen Keyboard in C#

Posted 03 June 2010 - 03:50 PM

This Will Works Too
ProcessStartInfo p = new ProcessStartInfo(((Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\osk.exe")));

Process aa = Process.Start(p);

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1