当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 运行同一目录下的可执行程序的VBS代码

运行同一目录下的可执行程序的VBS代码

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: set objshell = createobject("wscript.shell") strcurrentdir = objshell.curre
复制代码 代码如下:

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

参考资料:

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网