Replace %userprofile% windows variable in a string with the actual path in vbscript

Posted on 2006-05-04
Medium Priority
Last Modified: 2008-02-01
I have a script that reads a path from the registry and sets it as a variable and then later moves the files from that location to a mapped drive. On most computers this works fine, however on a few machines the path is set to %userprofile% instead of c:\documents and settings\user. What I want to do is look at the strprog string and if it has %userprofile% replace  the %userprofile% with the string in the strUserProfile variable.

Here is the code I have.

strUserProfile = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
strIdentity = WshShell.RegRead("HKCU\Identities\Default User ID")
strprog = wshshell.regread("HKCU\identities\"& stridentity &  "\software\application\I want to Read").

the strprog is what would contain the %userprofile%

Thanks In Advance.
Question by:hhSATX

Accepted Solution

List244 earned 1000 total points
ID: 16606602
strprog = replace(strprog,"%userprofile%",strUserProfile)

Like that?

Expert Comment

ID: 16607225
It seems that simple to me also, List244

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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 (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

750 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