Append or put variable within string in vbscript?

2019-03-07 02:34发布

I am wanting to include the variable domainUser within the quoted command sent to the commandline but I am not having any luck. What I am trying to accomplish is to create a log file titled with their domain name but I keep getting errors or just getting a txt file with no title.

Dim domainUser
domainUser = Example123

objInParam.Properties_.Item("CommandLine") = "cmd /c ECHO Test >> c:\UserLogs\"""domainUser""".txt"

So line 4 would be read like this (or whatever domain user I put in on line 2)...

objInParam.Properties_.Item("CommandLine") = "cmd /c ECHO Test >> c:\UserLogs\Example123.txt"

1条回答
太酷不给撩
2楼-- · 2019-03-07 03:20

You need concatenation to splice a variable's content into a string and double double quotes to put double quotes into it:

>> Dim domainUser
>> domainUser = "Example123"
>> Dim cmd
>> cmd = "cmd /c ECHO Test >> ""c:\UserLogs\" & domainUser &  ".txt"""
>> WScript.Echo cmd
>>
cmd /c ECHO Test >> "c:\UserLogs\Example123.txt"
查看更多
登录 后发表回答