Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to find Active Drive

I am trying to build a VBScript to automatically run some .exe files. The problem is that the script and the .exe files are on a flashdrive, so it needs to find the current drive letter by itself. I can do it on a batch file using %~d0, but I like some of the functions of VBScript better, especially the ability to send keystrokes. Anyways, I found a whole list of VBScript commands, but I am no expert and I need help with the syntax. So far I have it set to open the task manager and press some keys to have it select the "performance tab" of the task manager:

Dim Act :Set Act = CreateObject("Wscript.Shell")
Act.Run("taskmgr.exe")
Success = Act.AppActivate("taskmgr")
Wscript.Sleep 250
Act.SendKeys "{TAB 5}" :WScript.Sleep 500
Act.SendKeys "{RIGHT 3}" :WScript.Sleep 500

I'd like to know what command I need to use to tell the script to use the drive letter where the script was executed from (USB drive).

like image 684
Wolf Avatar asked Dec 01 '25 18:12

Wolf


1 Answers

Use the .ScriptFullName property to get the full file spec of the running script and apply .GetParentFolderName for the folder's path or .GetDriveName for just the drive letter.

>> Set oFS = CreateObject("Scripting.FileSystemObject")
>> s = WScript.ScriptFullName
>> WScript.Echo oFS.GetParentFolderName(s), oFS.GetDriveName(s)
>>
M:\bin M:

cf. here

like image 74
Ekkehard.Horner Avatar answered Dec 06 '25 07:12

Ekkehard.Horner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!