468,309 Members | 1,074 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

AppActivate applied to cmd.exe

Hello Community,

I have a question : why , if I try to use AppActivate applied to cmd.exe it doesn't work?

My purpose is to run a VB script from Excel which opens a Telnet or an ftp session, then it gives commands using SendKeys method. I am using the following code:
'---------------------------------------------------------------
Dim p_ID

Dim FullPath As String

FullPath = "C:\WINDOWS\system32\cmd.exe"

p_ID = Shell(FullPath, 1)

AppActivate p_ID
Application.SendKeys "ABCDE", True
'---------------------------------------------------------------


Note that :
1.If I call a different program (e.g.: FullPath = "C:\WINDOWS\notepad.exe")
everything works.

2.If I use an object "WScript.Shell" I can apply object.Run "ftp....." , but login
fails.

3. If at first I open cmd.exe using : object.Run "cmd" and then I use:
Application.SendKeys "ABCDE", True it doesn't work very much.

Who has an idea? Thanks

diSangro
Jan 8 '07 #1
5 9784
Killer42
8,434 Expert 8TB
I'm confused. I have seen AppActivate ID mentioned in a couple of messages recently. But I thought AppActivate expected a window title, not an ID. Everything I can see in both VB6 and Excel's VBA editor appears to support this.
Jan 9 '07 #2
You can use either the window title , or the task ID returned by the function Shell , this is written in the VB help guide.


I'm confused. I have seen AppActivate ID mentioned in a couple of messages recently. But I thought AppActivate expected a window title, not an ID. Everything I can see in both VB6 and Excel's VBA editor appears to support this.
Jan 9 '07 #3
Killer42
8,434 Expert 8TB
You can use either the window title , or the task ID returned by the function Shell , this is written in the VB help guide.
Fair enough.

(I'm currently on a PC which doesn't have VB help available, or I'd have checked.)
Jan 9 '07 #4
Ehy Killa!

I think I got a way to solve this problem, I should use:

sh.Exec "%COMSPEC% /k.....<whatever characters or commands>"

where sh is WShell object
but now I don't have time to try it.

What do you think?



Fair enough.

(I'm currently on a PC which doesn't have VB help available, or I'd have checked.)
Jan 9 '07 #5
Killer42
8,434 Expert 8TB
Ehy Killa!

I think I got a way to solve this problem, I should use:
sh.Exec "%COMSPEC% /k.....<whatever characters or commands>"
where sh is WShell object
but now I don't have time to try it.
What do you think?
It looks worth a try. Can you include an environment variable like that? If not, perhaps you can concatenate Environ$("COMSPEC") into the string, or something.

Also, if you can get it to use the START command, then you don't need to know what application to run. Just start the data file, and Windows will work out what application to use.
Jan 9 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Alex | last post: by
reply views Thread by Austin | last post: by
1 post views Thread by scottt | last post: by
1 post views Thread by André | last post: by
2 posts views Thread by =?Utf-8?B?bXIgcGVhbnV0?= | last post: by
reply views Thread by tutorialwebs | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.