在 .vbs 的文件路径中使用变量 [英] Use a variable in file path in .vbs

查看:45
本文介绍了在 .vbs 的文件路径中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 .vbs 的路径中使用变量.我的基本情况是我有一个 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").

脚本编辑一个位于用户目录中的 ini 文件,用于登录的人.我知道批量我可以简单地插入变量 "C:\Users\%Logger%\AppData\Local\stat.ini" 并且变量将被替换.但我不能在 .vbs 中做到这一点.我的脚本到目前为止.或者在此处.

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%\AppData\Local\stat.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:\Users\logger\AppData\Local\stat.ini", strOld, strNew)
blnRes = blnRes Or (Err.Number = 0): Err.Clear

有什么方法可以将 logger 标记为变量,或者有更简单的方法吗?

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

推荐答案

如果我正确理解您的要求,您要么需要进行字符串连接,在其中构建一个类似 "string 的字符串第 1 部分" &记录器"string part 2" 或使用替换函数将 %Logger% (例如 Replace(templateString, "%Logger%", logger)) 替换为您的记录器变量.没有直接等同于批处理文件中使用的 %1 类型的格式.

If I understand what you're after correctly, you're either going to need to do a string concatenation where you build a string like "string part 1" & logger & "string part 2" or use the replace function to replace %Logger% (e.g. Replace(templateString, "%Logger%", logger)) with your logger variable. There's not a direct equivalent to the %1 sort of format used in batch files.

这篇关于在 .vbs 的文件路径中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆