[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBScript - profile path

Posted on 2006-11-14
5
Medium Priority
?
1,684 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

864 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