[VBA] Problem with the shell command

julie75 -  
JuB0 Posted messages 658 Status Member -
Hello everyone!

So, I'm encountering a very strange problem with using the shell command in VBA. I want to run telnet from my Excel sheet, so I'm doing:

AdIP = "10.16.1.212"
prog = "C:\Windows\System32\"
retval = Shell(prog & "cmd /k telnet -f " & AdIP & " F:\BAIES\" & AdIP & ".txt ", 1)

the DOS window launches fine but I get the message: 'telnet' is not recognized as an internal or external command...

When I do it manually, it works perfectly!

What's also strange is that when I do a dir *.exe in the System32 folder from the window generated by the shell function, I get fewer results than when I open cmd on my own... (telnet.exe is not in the first dir)

Do you know what's going on?

A big thank you in advance because I'm stuck!

Configuration: Windows 7 / Firefox 3.5.16

11 answers

JuB0 Posted messages 658 Status Member 81
 
Hi julie75
Try using "telnet.exe" or by providing its full path: "C:\Windows\System32\telnet.exe"
--
Google is your friend ...
0
julie75
 
Up, up, up.....

Oh dear, no savior in the room??

I'm doing a simple:

Shell ("telnet.exe")

and I get a nice "File not found"... while

Shell ("calc.exe") works fine

in DOS I run telnet.exe and it works too...

For your information, I'm on Windows 2008 R2

Thanks, thanks.

EDIT: I just saw your message JuBO (and thank you for that).
well even when I do:
Shell ("C:\Windows\System32\telnet.exe") I get "File not found"
0
JuB0 Posted messages 658 Status Member 81
 
"The strange thing is also that when I do a dir *.exe in the System32 folder from the window generated by the shell function, I get fewer results than when I do it by opening cmd manually... (there's no telnet.exe in the first dir)
It seems like a permissions issue...
Are you running the VBA 'as' ?
--
Google is your friend..."
0
julie75
 
How can I see that JuBO?
0
JuB0 Posted messages 658 Status Member 81
 
Is it you who opens Excel?
(Otherwise, in the task manager you can see the username of each process)
--
Google is your friend ...
0
julie75
 
Ah yes, what a fool!

I was opening it with my domain account (which is in the local administrator group), I tried with the local admin account but still the same, this file "file not found" error 53. Pfffffff

Thanks for your help JuBO.
0
JuB0 Posted messages 658 Status Member 81
 
Are you sure that telnet.exe is located in c:\Windows\System32?
And what if you copy telnet.exe to the root of your drive and modify your script accordingly?
--
Google is your friend...
0
julie75
 
Oh well, I posted a response this afternoon but it doesn't show up!

I was saying that you pinpointed the issue because moving the file from System32 to C:\ works, so it must be a permission problem with the Windows folder.

This isn't convenient for me because my Excel file will be used on other machines; if I have to ask them to modify their permissions, it's not ideal.

Have a good evening/day!
0
JuB0 Posted messages 658 Status Member 81
 
I see 2(3) solutions:
1. The cleanest way would be to understand and resolve your access rights issue.
2. Does VBA not contain an object with Telnet functions (like the Shell object for the command prompt)?
3. You create a "package": you send the telnet.exe file with your Excel workbook to the other machines, and you modify your script to look for the "telnet.exe" file in the same folder as your workbook.
--
Google is your friend...
0
julie75
 
Hello JuBO!

I did your solution 3, which is actually perfect!

Thank you so much for your help!
0
JuB0 Posted messages 658 Status Member 81
 
It's "hacky," but the important thing is that it works!
You're welcome, my pleasure.

Julien
--
Google is your friend ...
0