关闭共享目录中的所有文件

时间:2013-08-22 23:34:41

标签: windows batch-file vbscript

我有一个执行以下操作的脚本

'Create a bat file
Set objBatFile = objFS.CreateTextFile("X:\" & strType & "\closeit.bat",True)
intExitCode = objBatFile.Write("for /f " & chr(34) & "skip=4 tokens=1" & chr(34) & " %%a in ('net files') do net files %%a /close")
objBatFile.Close
'Run the bat file to close all files in the directory
intExitCode = objShell.Run("X:\" & strType & "\closeit.bat", intWindowStyle, blnWaitOnReturn)
StopStart
'Delete the bat file
Set obj = CreateObject("Scripting.FileSystemObject") 
obj.DeleteFile("X:\" & strType & "\closeit.bat") 'Deletes the file throught the DeleteFile function

我想知道是否有人知道如何使用vbscript替换我用来关闭服务器上的打开文件的.bat文件命令?我想要替换的行是为了更清晰:

for /f " & chr(34) & "skip=4 tokens=1" & chr(34) & " %%a in ('net files') do net files %%a /close

1 个答案:

答案 0 :(得分:1)

执行cmd

intExitCode = objShell.Run("CMD.EXE /C for /f ""skip=4 tokens=1"" %a in ('net files') do net files %a /close"), blnWaitOnReturn)

请注意,FOR外部批处理在变量之前需要单%

您可以用"+Chr(34)+"替换""(至少在VBA和VB.NET中)。