運行同一目錄下的可執(zhí)行程序的VBS代碼,需要的朋友可以參考下。
代碼如下:
Set objShell = CreateObject("WScript.shell")
strCurrentDir = objShell.CurrentDirectory
set fso = createobject("scripting.filesystemobject")
set f=fso.getfolder(strCurrentDir)
For Each i In f.files
If LCase(right(i,4)) = ".exe" Then objShell.Run i,,true
Next
獲取腳本所在目錄還可以:
代碼如下:
set fso = createobject("scripting.filesystemobject")
fso.GetParentFolderName(WScript.ScriptFullName)
一時想不到更好的辦法判斷文件是不是.exe了…… 就這樣了。
代碼如下:
Option Explicit
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim oWS : Set oWS = CreateObject( "WScript.Shell" )
WScript.Echo "Script:"
WScript.Echo "ScriptFullName:", WScript.ScriptFullName
WScript.Echo "ScriptFullPath:", oFS.GetParentFolderName( WScript.ScriptFullName )
WScript.Echo "Current:"
WScript.Echo "FS:", oFS.GetAbsolutePathName( ".\" )
WScript.Echo "WS:", oWS.CurrentDirectory
-------- output -------------
C:\wis\_vbs\0506\dev\forum
cscript curdir.vbs
Script:
ScriptFullName: C:\wis\_vbs\0506\dev\forum\curdir.vbs
ScriptFullPath: C:\wis\_vbs\0506\dev\forum
Current:
FS: C:\wis\_vbs\0506\dev\forum
WS: C:\wis\_vbs\0506\dev\forum
C:\wis\_vbs\0506\dev\forum
cd ..
C:\wis\_vbs\0506\dev
cscript forum\curdir.vbs
Script:
ScriptFullName: C:\wis\_vbs\0506\dev\forum\curdir.vbs
ScriptFullPath: C:\wis\_vbs\0506\dev\forum
Current:
FS: C:\wis\_vbs\0506\dev
WS: C:\wis\_vbs\0506\dev