如何从具有不同驱动器号分配的多台计算机上的命令行从共享网络驱动器运行此VBS脚本?

时间:2014-06-13 09:33:41

标签: vba vbscript

运行此VBS脚本的最佳方法是将其位于共享网络驱动器上,我希望它使用命令行运行,它将由多台计算机使用,每台计算机将具有不同的驱动器号分配?< / p>

path = "C:\Users\ecaldwell"
filename = "PANESTCS.csv"
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(path & filename, ForReading)
Set objResult = objFSO.CreateTextFile(path & filename & ".result.csv", True)    

i = 0  

Do While objTextFile.AtEndOfStream <> True

  data = objTextFile.Readline

  If inStr(data, ",") Then

row = split(data, ",")

If Ubound(row) > 8 Then

  ' If Column A = ‘D’  and Column E = Zero Then

  ' Move ‘5’ to Column I

  If row(0) = "D" And row(4) = "0" Then

    row(8) = "5"

  End If

End If 

Else

objTextFile.Skipline

 End If

  objResult.WriteLine Join(row, ",")

  i = i + 1

Loop

objTextFile.Close
objResult.Close 

Wscript.Echo "Processed " & i & " lines. " & path & filename & ".result.csv"

1 个答案:

答案 0 :(得分:0)

加载&#34;我希望它使用命令行&#34;

运行

Cscript.exe可能就是您要找的,它将使用cmd提示符运行Link here

"it will be used by multiple computers and each computer will have different drive letter assignments"

您可以创建一个文本文件来读取每个计算机名称和驱动器号,然后遍历它以提取计算机名称,驱动器号并分配给将用于连接到计算机的变量

编辑 - 添加有关阅读csv文件的信息

Text file to load information from

Computer name, Drive letter
COMPUTER1,C
COMPUTER2,J
'Add other information

像在代码中一样加载文件。要读取csv文件并加载到变量中,需要拆分每个&#34;,&#34;标记

arrayMasterVariableFile = split(strLine, ",")

pcHostname = arrayMasterVariableFile(0)
pcDrive Letter = arrayMasterVariableFile(1)