0

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"
Sam
  • 71
  • 1
  • 1
  • 9
  • Possible duplicate of [Not able to launch bat file form VBScript if path contains a space](http://stackoverflow.com/questions/37254375/not-able-to-launch-bat-file-form-vbscript-if-path-contains-a-space) – user692942 Jul 21 '16 at 20:33
  • Possible duplicate of [About using Double quotes in Vbscript - Stack Overflow](http://stackoverflow.com/questions/15770599/about-using-double-quotes-in-vbscript) – user692942 Jul 21 '16 at 21:11
  • Possible duplicate of [Use a variable in file path in .vbs](http://stackoverflow.com/q/7534459/692942) – user692942 Jul 21 '16 at 21:12
  • Take your pick and that's just a small selection. – user692942 Jul 21 '16 at 21:13

1 Answers1

1

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"
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96