我需要编写一个查看目录的脚本,找到最新的.zip文件(那里有.zip和.log)然后打开在不同的目录命令提示符,运行以下命令:vb脚本:尝试打开命令提示符,导航到一个目录并运行命令
loaddb.bat -Dlc.file="C:\Program Files\XyEnterprise\SDL LiveContent\data_old\export\<name of the newest file.zip>" -Dlc.pswd=<oor password> RESTORE
我们不能安装任何语言,因此它必须能够在Windows 2003 & 2008服务器上运行,所以我选择的VBScript ...
我有一切工作,除了运行命令,似乎无法破解它。
我的代码如下:
Dim fileNewest
Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("C:\Program Files\XyEnterprise\SDL LiveContent\data\export")
For Each aFile In oFolder.Files
sExtension = fso.GetExtensionName(aFile.Name)
If sExtension = "log" Then
'Msgbox "The file extension is a " & sExtension
Else
'Msgbox "The file extension is a " & sExtension
If fileNewest = "" Then
Set fileNewest = aFile
Else
If fileNewest.DateCreated < aFile.DateCreated Then
Set fileNewest = aFile
End If
End If
End If
Next
Msgbox "The Newest File in the folder is " & fileNewest.Name & chr(13) & "Size: " & fileNewest.Size & " bytes" & chr(13) & "Was last modified on " & FileNewest.DateLastModified
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /k c: & cd ../../../Program Files\XyEnterprise\SDL LiveContent\data\export"
我怎么能现在打开的是DOS提示符后,运行命令?
感谢,
编辑:
添加答案从亚历克斯K A很大的帮助工作:
objShell.Run "%comspec% /k c: & cd ""C:\Program Files (x86)\XyEnterprise\SDL LiveContent\"" & """"loaddb RESTORE -Dlc.file=C:\PROGRA~2\XYENTE~1\SDLLIV~1\data\Import\" & fileNewest.Name & " -Dlc.pswd=N2kAs72z"""""
对于使用命令提示执行程序,有哪些事实可以说明问题? – reporter 2011-05-31 12:50:26
对不起,我不确定你的意思。我需要运行一个loaddb.bat命令,其路径指向每12小时更改一次的文件(从脚本中选取) – 2011-05-31 12:54:58
我明白了。 http://ss64.com/vb/run.html包含一个示例。寻找“DIR”这个词。希望这是你要找的。 – reporter 2011-05-31 13:05:19