Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sys root 2

Status
Not open for further replies.

emmanuelbeaudet

Programmer
Apr 16, 2002
51
CA
Want to know if there is a function or something in vbscript who can give me the sys root of the computer. Whatever if it is c:\, m:\ or anything else.

Thank you.
 
Something like this ?
Set Sh = CreateObject("WScript.Shell")
Set Env = Sh.Environment
WScript.Echo Env("SystemDrive")

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hello emmanuelbeaudet,

I take the liberty of using again the function from the documentation I used last time just for continuity here. I am not sure I understand exactly what you need here. But, here we go.
Code:
set wshshell=createobject("wscript.shell")
sWinDir=wshshell.ExpandEnvironmentStrings("%WinDir%")
set fso=createobject("scripting.filesystemobject")
sysDrv= fso.GetDriveName(sWinDir)
set fso=nothing
set wshshell=nothing

wscript.echo sysDrv & vbcrlf & ShowRootFolder(sysDrv)

'From documentation
Function ShowRootFolder(drvspec)
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetDrive(drvspec)
   ShowRootFolder = f.RootFolder
End Function
There are something really silly in there, but it is for illustration only.

You can perfectly parse sWinDir for "x:\" directly without using all those object and less used methods and properties.

regards - tsuji
 
Sorry for the typo:
Set Sh = CreateObject("WScript.Shell")
Set Env = Sh.Environment[highlight]("PROCESS")[/highlight]
WScript.Echo Env("SystemDrive")

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top