Solved

VBScript - profile path

Posted on 2006-11-14
5
1,675 Views
Last Modified: 2008-01-09
What is the best way to retrieve the current user's local profile path (documents and settings\username\...) in a script?
I'm working on a script to copy files to a folder in the user's profile.
0
Comment
Question by:artthegeek
  • 3
  • 2
5 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17943389
This should do it - reference the shell's volatile environment...


Dim objEnv
Dim strProfile

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Volatile")
strProfile=objEnv("HomeDrive") & objEnv("HomePath")

msgbox strProfile

set objEnv=Nothing
wscript.quit
0
 
LVL 3

Author Comment

by:artthegeek
ID: 17943413
This looks good -
do I need the  

set objEnv=Nothing
wscript.quit

?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17943432
set objEnv=Nothing
'supposedly' releases the memory used for that object (I suppose it's debatable - but good coding to terminate these objects to prevent potential memory leaks - although a small script like this shouldn't matter much).

wscript.quit
again, not 'really' necessary - more just standard coding practice so that you control when the script terminates.  It basically says - time to stop processing.
0
 
LVL 3

Author Comment

by:artthegeek
ID: 17943443
Great stuff - thank you.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17943448
Happy to have helped. :^)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now