1.

Solve : how to use %SystemDrive% in vbs?

Answer»

Hi, I'm trying to make a script i've been working on be able to be run on a variety of computers been as the System Drive is not always forced to be the C: drive like it is on mine i'm trying to use %SystemDrive% wherever there is a C: in my script however it is not working any ideas what I'm doing wrong? as PART of my Program there is a few lines on a batch FILE which amongst a few other jobs I use to execute my vbs I have used %SystemDrive% in the batch file instead of C: and that works fine.
Thanks, James.you can use ExpandEnvironmentStrings():

Code: [Select]Set wshell = CreateObject("WScript.Shell")
WScript.Echo wshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
thanks for your quick reply, so I add those 2 lines at top of my vbs then how do I call upon it I STILL cant substitute C: with %SYSTEMDRIVE% can I? have tried doing that and its not working perphaps you could explain how I could use it in this line of my script.

Code: [Select]Set objFile = objFSO.OpenTextFile(C:\Scripts\CustomReport.xml", ForReading)

Code: [Select]Set objFile = objFSO.OpenTextFile("%SYSTEMDRIVE%\Scripts\CustomReport.xml", ForReading)
doesnt work.

thanks James.ok.

at the top of your script add:

Code: [Select]
Set wshell = CreateObject("WScript.Shell")
sysdrive = wshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")



and then when you need to use it:

Code: [Select]Set objFile = objFSO.OpenTextFile(sysdrive + "\Scripts\CustomReport.xml", ForReading)thanks that works great thats finished my script off nicely just one more thing if you dont mind, I've moved onto trying to make an installer now and having a little difficulty creating some shortcuts, the script is a batch file that CREATES a directory in user documents for later use by the program it creates a directory in program files and copies the scripts for the program to that location and creates a folder in the start menu for some shortcuts. everything works except for the creation of the shortcuts would you happen to know why? script is below.

Code: [Select]ECHO off
MD "%SystemDrive%\Program Files\MyMoviesReports"
copy "%~dp0\Uninstall.bat" "%SystemDrive%\Program Files\MyMoviesReports\"
copy "%~dp0\CreateCustomReport.vbs" "%SystemDrive%\Program Files\MyMoviesReports\"
copy "%~dp0\CreateCustomReport.bat" "%SystemDrive%\Program Files\MyMoviesReports\"
MD "%userprofile%\start menu\programs\MyMoviesReports"
MD "%userprofile%\MyMovieReports"
SHORTCUT -f -t "%SystemDrive%\Program Files\MyMoviesReports\CreateCustomReport.bat" -n "%userprofile%\start menu\programs\MyMoviesReports\CreateCustomReport"
SHORTCUT -f -t "%SystemDrive%\Program Files\MyMoviesReports\Uninstall.bat"



Discussion

No Comment Found