Solved

VBS: finding the root drive.

Posted on 2004-04-13
3
299 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 51

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 73
Added a column screws up code 5 63
How to read File Date Created using VB6 8 52
Excel Automation VBA 19 89
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

861 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