How to use VBS to run executable programs in the same directory
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!