Using a string variable in the title of a .txt
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Using a string variable in the title of a .txt
Set wshShell = WScript.CreateObject( "WScript.Shell" )Set objFSO = CreateObject("Scripting.FileSystemObject")strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )Set objFile = objFSO.OpenTextFile("c:info.txt",2,true,2)objFile.WriteLine "Computer Name=" & strComputerNameobjFile.Close That above script is very simple. It generates a text file and pouts the computer name in the body. This is just a small snippet of a much larger script. The proper variable, in this case strComputerName has already been declared. What I am trying to accomplish is this. I would like the computer name to be the name of the file so for example : Randompc.txt I have tried Set objFile = objFSO.OpenTextFile("c:%computername".txt",2,true,2)Which didnt work: ' Define the path for our text file strFilePath = "C:WinInfo.txt" strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set objFSO = CreateObject("Scripting.FileSystemObject") ' Open the file for write access. Set objFile = objFSO.OpenTextFile(strFilePath, 2, True, 0)This is a peace from the larger script. here I define the file path, and then call the text file and add write privileges to it. My main question is. Whether you use the first code snip, or the second one (which is preferable) how can I add the actual computer name into the title?
Using a string variable in the title of a .txt
'spelt' is spelled. 'Post OPtions' has the edit item on its menu.
You need to learn basic scripting. You clearly do not have any understanding about strings in VBScript.
Start here: http://www.w3schools.com/vbscript/default.asp
sString are concatenated using the & operator. You cannot just type them all in a row.
"mypsname1" & ".txt" will create a string based on the two parts. With that little gem try your script again.
You need to learn basic scripting. You clearly do not have any understanding about strings in VBScript.
Start here: http://www.w3schools.com/vbscript/default.asp
sString are concatenated using the & operator. You cannot just type them all in a row.
"mypsname1" & ".txt" will create a string based on the two parts. With that little gem try your script again.
Using a string variable in the title of a .txt
Start here: http://www.w3schools.com/vbscript/default.asp
sString are concatenated using the & operator. You cannot just type them all in a row.
"mypsname1" & ".txt" will create a string based on the two parts. With that little gem try your script again.
sString are concatenated using the & operator. You cannot just type them all in a row.
"mypsname1" & ".txt" will create a string based on the two parts. With that little gem try your script again.
Using a string variable in the title of a .txt
Yu need to concatenate a varaible to a string.
Please do this: http://www.w3schools.com/vbscript/default.asp
Study the parts about variables and about strings until it is clear in your mind how this works.
a & b
A & "b"
"A" & "b"
"a & b"
Think about what is happening. You will eventually see it.
Please do this: http://www.w3schools.com/vbscript/default.asp
Study the parts about variables and about strings until it is clear in your mind how this works.
a & b
A & "b"
"A" & "b"
"a & b"
Think about what is happening. You will eventually see it.