Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

vbscript - Use a variable in file path in .vbs

Is it possible to usa variable in a path in .vbs. My basic situation is I have a vbs script that will often be run on a computer with one person logged in and run by an admin with a completely different user name (assume the file will be right clicked and "Run As").

The script edits an ini file that is located in the user directory for the person logged in. I know in batch I could simply insert the variable "C:Users\%Logger%AppDataLocalstat.ini" and the variable would be replaced. But I can't do this in .vbs. My script thus far. Or look at the bulk of it in an answer here.

Dim blnRes: blnRes = 0
Dim strOld, strNew, logger
strOld = "frogg"
strNew = "frog"
logger = Inputbox("What is your Domain ID exactly as entered when you log into this machine?","Domain ID")

On Error Resume Next
Call update("C:UsersloggerAppDataLocalstat.ini", strOld, strNew)
blnRes = blnRes Or (Err.Number = 0): Err.Clear

Is there some way I can flag logger as a variable, or is there an easier way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I guess you meant a script variable. Try this:

logger = Inputbox("What is ID?","Domain ID")
Call update("C:Users"& logger &"AppDataLocalstat.ini", strOld, strNew)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...