问题
I just KNOW this is something simple, but I've tried all of the suggestions I could find on this forum, and I still can't get the following ShellExecute statements, which worked perfectly well for four years on XP, to work in Windows 7.
Any suggestions gratefully received!
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c ftp -s:c:\checkout\WebFTPParams.txt 91.208.99.4'), Nil, SW_SHOW);
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c ftp -s:c:\checkout\WWFTPParams.txt 212.78.232.39'), Nil, SW_SHOW);
Thanks anyway, folks, but I found the problem. I should have been using CMD.EXE rather than good old Command.com. Sorry for bothering you!
回答1:
Command.com is not anymore in Windows (it was used in DOS). Use cmd.exe
回答2:
Different versions of Windows use different command-line interpreters. Older versions use command.com, newer versions use cmd.exe instead. Use GetEnvironmentVariable('COMSPEC')
to discover the correct interpreter to use.
With that said, you don't need to use any interpreter in this situation. ftp.exe is its own app, so you can just run it directly. Although you can use ShellExecute()
to run exe files, it really is not meant for that. It will just delegate to CreateProcess()
, so you really should cut out the middle man and use CreateProcess()
directly instead.
Even better, rather than use an external process, you should consider using the FTP protocol directly in your own code. There are plenty of third-party components, like Indy, ICS, Synapse, etc, and APIs, like WinInet, libcurl, etc, that have FTP client implementations, and are easily usable in Delphi.
回答3:
As has been noted, command.com is the DOS/Windows 9x command interpretor. But I see no reason to invoke a command interpretor at all. I'd do it like this:
ShellExecute(Handle, nil, 'ftp.exe', '-s:c:\checkout\WWFTPParams.txt 212.78.232.39', nil, SW_SHOW);
There's no need to specify a verb here either.
来源:https://stackoverflow.com/questions/14170998/delphi-shellexecute-not-working-in-windows-7