Solved how to use variables in VBS from CMD?????

January 11, 2015 at 21:26:50
Specs: Windows 7 Pro, i7 Extreme 3.9GHz
Can you help... I am trying to create a shortcut to the "FinalTargetDir" in the "InitialDir" after the move is complete.


@echo Off

setLocal EnableDelayedExpansion

SET InitialDir=%1

SET FolderName=%InitialDir:~-12%

SET ProCylDir=C:\temp

SET SeriesTargetDir=%ProCylDir%\%FolderName:~0,1%
SET BoreTargetDir=%SeriesTargetDir%\%FolderName:~0,3%
SET StrokeTargetDir=%BoreTargetDir%\%FolderName:~0,7%
SET RodTargetDir=%StrokeTargetDir%\%FolderName:~0,8%
SET MountTargetDir=%RodTargetDir%\%FolderName:~0,10%
SET FinalTargetDir=%MountTargetDir%\%FolderName%

IF NOT EXIST %FinalTargetDir% (
MKDIR %FinalTargetDir%

ROBOCOPY %InitialDir% %FinalTargetDir% /MOVE /ETA

SET "FolderNameCMD=%FolderName%.Lnk"

WScript test.vbs

''''''''''''''test.vbs Below'''''''''''''''''''''''

Set objShell = WScript.CreateObject("WScript.Shell")
Set lnk = objShell.CreateShortcut("%FolderNameCMD%") <<<<<<<<this doesn't work
lnk.TargetPath = "%FinalTargetDir%" <<<<<<<THIS WORKS!!! whats the difference???
lnk.Arguments = ""
'lnk.Description = "%FolderName%" <<<<<This doesn't work
lnk.IconLocation = "C:\Windows\system32\imageres.dll, 4"
lnk.WindowStyle = "1"
'lnk.WorkingDirectory = "%FolderName%" <<<<<This doesn't work
MsgBox "FolderName is now moved and archived to Pro\Cylinders.", _
vbInformation + vbSystemModal, "Create shortcut"

See More: how to use variables in VBS from CMD?????

Report •

January 11, 2015 at 22:51:40
Pass the variable as a parameter:

Report •

January 13, 2015 at 14:14:10
✔ Best Answer
If you're dead-set on using environment variables, the easiest method is to use objShell.ExpandEnvironmentStrings(). See:

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question