Solved

VBS: finding the root drive.

Posted on 2004-04-13
3
284 Views
Last Modified: 2010-05-18
Hi,

I am putting together a pendrive with all my PuTTY settings and keys etc, there are 3 questions in this topic that should all be easy.

I know I can use VBS to create a shortcut, but I have a problem. When I plug the drive in, I do not know what the root letter will be (D:, E:, F: etc) and so cannot hard code a shortcut. I want to find the drive letter that the VBS script is running from. (Or better, and probably easier yet, the full path in case we are on a junction) is there an easy function to do this?

Thanks
Nigel.
0
Comment
Question by:nigel5
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 10820469
Try this:

GetPath.vbs:

function ShowAbsolutePath(path)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")  
   ShowAbsolutePath = fso.GetAbsolutePathName(path)  
end function

function getDrive(path)
      pos = instr(path,"\")
      if pos > 0 then
            getDrive = left(path, pos)
      else
            getDrive = ""
      end if
end function

msgbox ShowAbsolutePath(".")
msgbox getDrive(ShowAbsolutePath("."))

Hope this helps
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10821640
Or just the below to get the path of the current script.

MsgBox WScript.ScriptFullName
0
 

Author Comment

by:nigel5
ID: 10821790
Ryancys

Thanks, I knew there was a simple solution :)

Cheers
N.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now