[VBA] Problem with the shell command
julie75
-
JuB0 Posted messages 658 Status Member -
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
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
Hi julie75
Try using "telnet.exe" or by providing its full path: "C:\Windows\System32\telnet.exe"
--
Google is your friend ...
Try using "telnet.exe" or by providing its full path: "C:\Windows\System32\telnet.exe"
--
Google is your friend ...
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"
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"
"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..."
It seems like a permissions issue...
Are you running the VBA 'as' ?
--
Google is your friend..."
Is it you who opens Excel?
(Otherwise, in the task manager you can see the username of each process)
--
Google is your friend ...
(Otherwise, in the task manager you can see the username of each process)
--
Google is your friend ...
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.
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.
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...
And what if you copy telnet.exe to the root of your drive and modify your script accordingly?
--
Google is your friend...
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!
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!
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...
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...