473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sendkeys to notepad

Hello Everyone,

I have this code for sendKeys. This simply sends a text to the notepad.
This method runs fine, but I don't see the notepad and the text entered in
that notepad. Is there any way I can see the notepad. When I go to the
taskbar, I can see that notepad.exe is running there, but I don't see the
notepad itself. I am calling this method from the web page.

public void sendKeysTest()
{
System.Diagnostics.Process.Start("c:\WINNT\notepad .exe")

Process myProcess= new Process();
myProcess.StartInfo.FileName="notepad";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
myProcess.EnableRaisingEvents = true;
if (myProcess.Responding)
{
System.Windows.Forms.SendKeys.SendWait("This text was entered using the
System.Windows.Forms.SendKeys method.");

}
else
myProcess.Kill();


}
Thanks,

Any help will be appreciated.
Apr 8 '07 #1
9 23762
"Vinki" <Vi***@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
I have this code for sendKeys. This simply sends a text to the notepad.
This method runs fine, but I don't see the notepad and the text entered in
that notepad. Is there any way I can see the notepad. When I go to the
taskbar, I can see that notepad.exe is running there, but I don't see the
notepad itself. I am calling this method from the web page.
If you are caling it from the *server code* in a web page, it is
starting Notepad on the server, not on the computer where you are running
the browser. Even if you are running the browser on the same computer as the
web server, the IIS server runs as a service that by default is not allowed
to interact with the desktop, so a program launched from server code will
not appear on screen.

Apr 8 '07 #2
Hi Vinki,

The problem is, Notepad isn't the active window when you use SendKeys, so you effectively send the text to your own application instead.

To bring notepad to the front tap into the win32 api and use the SetForegroundWindow method

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public void sendKeysTest()
{
Process myProcess = Process.Start(@"k:\windows\notepad.exe");

SetForegroundWindow(myProcess.Handle);

if (myProcess.Responding)
SendKeys.SendWait("This text was entered using the System.Windows.Forms.SendKeys method.");
else
myProcess.Kill();
}

// This means use the SetForegroundWindow method defined in user32.dll
// If you read the documentation for SetForegroundWindow, you will see the
// parameters defined as HWND hWnd. A HWND is equivalent to IntPtr in C#
// and since Process has a Handle property, we are all set

[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
--
Happy coding!
Morten Wennevik [C# MVP]
Apr 8 '07 #3
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.

"Morten Wennevik [C# MVP]" wrote:
Hi Vinki,

The problem is, Notepad isn't the active window when you use SendKeys, so you effectively send the text to your own application instead.

To bring notepad to the front tap into the win32 api and use the SetForegroundWindow method

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public void sendKeysTest()
{
Process myProcess = Process.Start(@"k:\windows\notepad.exe");

SetForegroundWindow(myProcess.Handle);

if (myProcess.Responding)
SendKeys.SendWait("This text was entered using the System.Windows.Forms.SendKeys method.");
else
myProcess.Kill();
}

// This means use the SetForegroundWindow method defined in user32.dll
// If you read the documentation for SetForegroundWindow, you will see the
// parameters defined as HWND hWnd. A HWND is equivalent to IntPtr in C#
// and since Process has a Handle property, we are all set

[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
--
Happy coding!
Morten Wennevik [C# MVP]
Apr 9 '07 #4
You will not be able to utilize the SendKeys method from a web page.

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"Vinki" <Vi***@discussions.microsoft.comwrote in message
news:9C**********************************@microsof t.com...
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use
sendKeys
only in windows application.

Thanks.

"Morten Wennevik [C# MVP]" wrote:
>Hi Vinki,

The problem is, Notepad isn't the active window when you use SendKeys, so
you effectively send the text to your own application instead.

To bring notepad to the front tap into the win32 api and use the
SetForegroundWindow method

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public void sendKeysTest()
{
Process myProcess = Process.Start(@"k:\windows\notepad.exe");

SetForegroundWindow(myProcess.Handle);

if (myProcess.Responding)
SendKeys.SendWait("This text was entered using the
System.Windows.Forms.SendKeys method.");
else
myProcess.Kill();
}

// This means use the SetForegroundWindow method defined in user32.dll
// If you read the documentation for SetForegroundWindow, you will see
the
// parameters defined as HWND hWnd. A HWND is equivalent to IntPtr in C#
// and since Process has a Handle property, we are all set

[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
--
Happy coding!
Morten Wennevik [C# MVP]

Apr 9 '07 #5
On Mon, 09 Apr 2007 02:04:00 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.
Actually, it will work in a web application, but it would only open Notepad on the web server.

--
Happy coding!
Morten Wennevik [C# MVP]
Apr 9 '07 #6
Thanks. It worked!!

"Morten Wennevik [C# MVP]" wrote:
On Mon, 09 Apr 2007 02:04:00 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.

Actually, it will work in a web application, but it would only open Notepad on the web server.

--
Happy coding!
Morten Wennevik [C# MVP]
Apr 10 '07 #7
I was wondering that the behaviour of exe file changes if I execute the file
by sendkeys or manually.

I am trying to execute this exe file through sendkeys and my .net
application opens the exe file, but says that exe file license has expired,
but when I manually click on the exe file, the exe application opens. I am
not sure why this happening.

"Morten Wennevik [C# MVP]" wrote:
On Mon, 09 Apr 2007 02:04:00 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.

Actually, it will work in a web application, but it would only open Notepad on the web server.

--
Happy coding!
Morten Wennevik [C# MVP]
Apr 11 '07 #8
Right click on the icon you click to manually start the exe, check for additional parameters.
Also, try setting working folder.

On Wed, 11 Apr 2007 06:12:02 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
I was wondering that the behaviour of exe file changes if I execute the file
by sendkeys or manually.

I am trying to execute this exe file through sendkeys and my .net
application opens the exe file, but says that exe file license has expired,
but when I manually click on the exe file, the exe application opens. I am
not sure why this happening.

"Morten Wennevik [C# MVP]" wrote:
>On Mon, 09 Apr 2007 02:04:00 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.

Actually, it will work in a web application, but it would only open Notepad on the web server.

--
Happy coding!
Morten Wennevik [C# MVP]


--
Happy coding!
Morten Wennevik [C# MVP]
Apr 11 '07 #9
Thanks Morten for all your help. I successfully finished the program.

"Morten Wennevik [C# MVP]" wrote:
Right click on the icon you click to manually start the exe, check for additional parameters.
Also, try setting working folder.

On Wed, 11 Apr 2007 06:12:02 +0200, Vinki <Vi***@discussions.microsoft.comwrote:
I was wondering that the behaviour of exe file changes if I execute the file
by sendkeys or manually.

I am trying to execute this exe file through sendkeys and my .net
application opens the exe file, but says that exe file license has expired,
but when I manually click on the exe file, the exe application opens. I am
not sure why this happening.

"Morten Wennevik [C# MVP]" wrote:
On Mon, 09 Apr 2007 02:04:00 +0200, Vinki <Vi***@discussions.microsoft.comwrote:

Thanks, I will try this code and will let you know. I have one question
though. Will this code work fine in asp.net because I am using asp.net
application not windows application. Everyone told me that I can use sendKeys
only in windows application.

Thanks.


Actually, it will work in a web application, but it would only open Notepad on the web server.

--
Happy coding!
Morten Wennevik [C# MVP]

--
Happy coding!
Morten Wennevik [C# MVP]
Apr 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mr. Bungle | last post by:
I would like to send email automatically via a command button. I have accomplished this just fine through the following code: (Outlook should already be open for reliable results) Private Sub...
2
by: RBohannon | last post by:
I need to create a report in MS Word populated with data from A2K. I have been asked to create the report in Word so that parts of it can be edited as necessary later. The data in the report are...
1
by: George | last post by:
Every time I used the Sendkeys command in my application the "Numlock" turned off and I couldn't use the keypad to hit numbers...... The old code was: Private Sub Command1_Click() SendKeys...
1
by: Bryan | last post by:
I am writing a C# Windows App that updates out Excel reports' modules. The app is complete, but has a problem. The only way MS allows you to unprotect the VBA code in Excel is to do it by hand or...
4
by: Dica | last post by:
i'm primarily a web developer so this is probably some really obvious mistake, but why doesn't sendKeys open the 'Open File' dialogue in photoShop with the following code: '// open the map...
6
by: Michael Maes | last post by:
Hello, I'm invoking successive SendKeys.SendWait("{BACKSPACE}") SendKeys.SendWait("{DELETE}") in a loop. The issue is that it causes a Beep on every Pass. Setting the 'Handled = True' on...
11
by: NVergunst | last post by:
Hello everyone. I have what I believe to be a simple question, yet I can not find anything that is helpful to me. Basically I have an application, that I want to use to control external...
0
by: dtshedd | last post by:
I have a database with hundreds of embedded photos (Microsoft Photo 3.0) Many are larger than 1 MB. I tried Stephen Lebans macro but it did not work probably for the aforementioned reasons Now...
0
by: oslasi | last post by:
Hi, i have followed the post on the link: http://www.thescripts.com/forum/thread629545.html which was helpfull. i am trying to send keys to notepad which started on citrix web portal. same...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.