Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use VBS to run executable programs in the same directory

Shulou Source: shulou.com Published: 2022-06-03 06:51:52 10月04日 Update

Editor to share with you how to use VBS to run executable programs in the same directory, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The code is as follows:

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 (iPol 4)) = ".exe" Then objShell.Run iPerry true

Next

You can also get the directory where the script is located:

The copy code is as follows:

Set fso = createobject ("scripting.filesystemobject")

Fso.GetParentFolderName (WScript.ScriptFullName)

I can't think of a better way to judge whether the file is .exe or not. That's it.

The copy code is as follows:

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

The above is all the contents of the article "how to use VBS to run executable programs in the same directory". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code directory article program run content not much method most unexpected location document more knowledge script industry information information channel channel reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei macOS Shulou Information Xiaomi