Avatar of LONBUSS
LONBUSS
Flag for United Kingdom of Great Britain and Northern Ireland asked on

VBScript add info to a text file on a server

I'm just starting out to write VBScripts and I was wondering how easy it would be to write a script that get's info such as Computer name and IP and then adds them to a text file on a server.

Any help would be appreciated
Windows 2000

Avatar of undefined
Last Comment
Isigow

8/22/2022 - Mon
Isigow

with a winNT+ (2k/xp) client, batch is actually easier,

echo %username% %computername% %Logonserver% > \\server\share\file.txt

but since you want IP as well
Below is a easy (no file manipulation) way of running the same with vbscript, if you want to store it to a file just:
cscript myscript.vbs > \\server\share\file.txt

-----------------------------------------------------------------------------
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set WshProcessEnvironment = objShell.Environment("Process")
EnvLogonServer = WshProcessEnvironment("LogonServer")
EnvUsername = WshProcessEnvironment("username")
EnvComputerName = WshProcessEnvironment("computername")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
            EnvIP = EnvIP & " | "  &  IPConfig.IPAddress(i)
        Next
    End If
Next

WScript.Echo EnvUserName & " | " & EnvComputerName & " | " & EnvLogonServer & " | " & EnvIP
LONBUSS

ASKER
Cheers Isigow,

But what if I don't want the output to be piped into txt file, but instead have the script ammend it to an existing txt file.  Is that harder to do?
ASKER CERTIFIED SOLUTION
Isigow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck