我无法从访问中运行.bat文件。创建.bat文件,创建日志(其中没有任何内容),当我在Windows资源管理器中单击它时,.bat文件将运行,我无法使用.RUN命令运行它。
sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
'Print #2, "EXIT"
Close #2
oShell.Run sFileName, 0, True
编辑:
sFileName = "Z:\Recon\FTPUtilSrc\MYFTP.BAT"
sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
Print #2, "EXIT"
Close #2
oShell.run sFileName, 0, True
答案 0 :(得分:1)
尝试一下:
Dim cmd_str As String
cmd_str = "cmd.exe /C ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Call Shell(cmd_str, vbNormalFocus)
答案 1 :(得分:0)
尝试改变一些事情,看看发生了什么:
sFileName = "Z:\Recon\FTPUtilSrc\MYFTP.BAT"
sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
Print #2, "PAUSE" 'PAUSE forces the command prompt window to stay open. This temporarily allows you to see if there are any issues with the ftp statment.
Close #2
oShell.run sFileName, 0, True '3 is "Activates the window and displays it as a maximized window." according to msdn. This will allow you to see the execution of the ftp statment
查看这些更改是否有助于您确定问题,以便您可以将其更改回来。顺便说一句,我通过运行以下代码来测试代码,它按预期工作,这让我相信这是ftp命令的问题。
Public Sub TestBat()
Set oShell = CreateObject("WScript.Shell")
sFileName = "C:\Temp\MYECHO.bat" '"Z:\Recon\FTPUtilSrc\MYFTP.BAT"
sFTP = "echo ""hi"" > C:\Temp\test.txt" '"ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
Print #2, "PAUSE"
Close #2
oShell.Run sFileName, 3, True
End Sub