Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append a line to a text file with partial ComputerName (VBScript) 1

Status
Not open for further replies.

keynoto

IS-IT--Management
Mar 4, 2001
6
0
0
US
I'm trying to append a line in a file (i.e. "c:\test.txt" ) to insert the last 4 characters of the computename. For example if my computername is COMPUTER1234, I would like the script to read the last 4 characters, "1234" and insert it on a line in the text file that reads "NNN = 1234"
Any ideas, thanks?
 
Code:
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = Createobject("Wscript.Network")
strComputer = WSHNetwork.Computername

Set objFile = objFSO.OpenTextFile("filename.txt", ForAppending)

objFile.WriteLine "NNN=" & Right(strComputer,4)
objFile.Close

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark,

Thanks for the reply. This is exactly what I was looking for. You're great man!

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top