Monday, August 01, 2011

Simple vbscript to write computer name to file

On Error Resume Next

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

'Create commonly used objects
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

'get the computer name
strComputer = WshNetwork.ComputerName

'Write Computer Name to file
Set objTextFile = objFSO.OpenTextFile _
("C:\computer.txt", ForWriting, True)

objTextFile.WriteLine strComputer

objTextFile.Close

0 comments: