Discussion:
Using sytem variables in vbs script ie. %homepath%
(too old to reply)
Howes
2006-05-26 15:36:38 UTC
Permalink
Hi,

I am trying to copy a file from a directory location to a user's home
path by using the system variable %homepath%. VBS will not allow me to
do this citing an "invalid path" error. Is their a better way to
accomplish this copy? Here is an example of what I am trying to do:

objFSO.CopyFile "\\Server\ServerDir\file.txt",
"%homepath%\Favorites\file.txt",OverwriteExisting

Any suggestions would be appreciated.

Thank you in advance.

Daryl
mr_unreliable
2006-05-26 19:43:55 UTC
Permalink
hi Daryl,

You can get the value of environment variables by using the
wsh "system environment" object:

Set wshShell = WScript.CreateObject("WScript.Shell")
Set wshSysEnv = wshShell.Environment("PROCESS")
sMyHomePath = wshSysEnv("HOMEPATH")

That will give you the homepath as a string.

Then it's up to you to use vbs string operations to insert
the homepath into the filename.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Post by Howes
Hi,
I am trying to copy a file from a directory location to a user's home
path by using the system variable %homepath%. VBS will not allow me to
do this citing an "invalid path" error. Is their a better way to
objFSO.CopyFile "\\Server\ServerDir\file.txt",
"%homepath%\Favorites\file.txt",OverwriteExisting
Any suggestions would be appreciated.
Thank you in advance.
Daryl
Howes
2006-05-29 12:19:10 UTC
Permalink
Thanks JW,

Exacly what i was looking for thanks.

Jerold Schulman
2006-05-27 12:05:41 UTC
Permalink
Post by Howes
Hi,
I am trying to copy a file from a directory location to a user's home
path by using the system variable %homepath%. VBS will not allow me to
do this citing an "invalid path" error. Is their a better way to
objFSO.CopyFile "\\Server\ServerDir\file.txt",
"%homepath%\Favorites\file.txt",OverwriteExisting
Any suggestions would be appreciated.
Thank you in advance.
Daryl
See tip 9956 ยป How do I use an environment variable in VBScript?
in the 'Tips & Tricks' at http://www.jsifaq.com

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
Loading...