运行同一目录下的可执行程序的VBS代码
运行同一目录下的可执行程序的VBS代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:SetobjShell=CreateObject("WScript.shell")strCurrentDir=objShe...

复制代码 代码如下:

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_vbs506devforum

cscript curdir.vbs

Script:

ScriptFullName: C:wis_vbs506devforumcurdir.vbs

ScriptFullPath: C:wis_vbs506devforum

Current:

FS: C:wis_vbs506devforum

WS: C:wis_vbs506devforum

C:wis_vbs506devforum

cd ..

C:wis_vbs506dev

cscript forumcurdir.vbs

Script:

ScriptFullName: C:wis_vbs506devforumcurdir.vbs

ScriptFullPath: C:wis_vbs506devforum

Current:

FS: C:wis_vbs506dev

WS: C:wis_vbs506dev

参考资料:http://www.visualbasicscript.com/m43018.aspx

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新vbs学习
热门vbs学习
脚本专栏子分类