• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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

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.
1 Solution
strprog = replace(strprog,"%userprofile%",strUserProfile)

Like that?
It seems that simple to me also, List244
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now