透視圖:此腳本將在用戶登錄和命令上運行,並在桌面上使用快捷方式。申請開始的順序勢在必行。在整個腳本中,我需要完整路徑和程序名稱。來自For Each的VBS多維數組
問題:每個程序路徑都是數組中的一個值。我試圖通過「\」拆分每個程序路徑,並獲取程序名的上限。然後Redim保留原始數組並在第二維上添加程序。在閱讀了很多小時之後,我明白我只能改變最後一個維度,但我無法弄清楚如何避免出錯界限。這Creating a Multidimensional, Associative Array in VBScript不是試圖從一個For Each分裂中重新保留。
Set objFso = CreateObject("Scripting.FileSystemObject")
'---Create Program Variables
strProgram1 = "%SystemRoot%\notepad.exe"
strProgram2 = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
strProgram3 = "C:\Program Files\Microsoft Office\root\Office16\ONENOTE.EXE"
strProgram4 = "C:\Program Files (x86)\Internet Explorer\iexplore.exe" & " https://www.google.com" 'IE with URL
'---Add Program Path Variables to an Array
ReDim strProgramList(3)
strProgramList = Array(strProgram1,strProgram2,strProgram3,strProgram4)
strProgramNameList = Array()
strProgramRestartList = Array()
boolNeedsRestart = false
'---Iterating using For each loop to get program name.
ReDim Preserve strProgramList(3, 1)
For Each strProgramPath In strProgramList
strPathComponents = Split(strProgramPath, "\")
strProgramName = strPathComponents(Ubound(strPathComponents))
strProgramList(0, LBound(strProgramList) + 1) = strProgramName
Next
MsgBox strProgramList(0,0) & vbNewLine & strProgramList(1,0) & vbNewLine & strProgramList(2,0) & vbNewLine & strProgramList(3,0) & vbNewLine & strProgramList(0,1) & vbNewLine & strProgramList(1,1) & vbNewLine & strProgramList(2,1) & vbNewLine & strProgramList(3,1)
的可能的複製[創建多維, VBScript中的關聯數組](// stackoverflow.com/q/4588469) – Lankymart