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

Posted on 2006-05-04
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
    LVL 8

    Accepted Solution

    strprog = replace(strprog,"%userprofile%",strUserProfile)

    Like that?
    LVL 6

    Expert Comment

    It seems that simple to me also, List244

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    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…
    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…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now