Keyfer Mathewson
Keyfer Mathewson

Reputation: 1075

VBScript Writing to Server Text File

I have created a VBScript which pulls the service tag, username, and computer name from a computer. What I need to do now is compile this information in a text document.

How it's set up is as follows:

We have an Active Directory Server, with a folder for login scripts. I have created a batch file to run this .vbs script, and the script works well so far. What I now need is for a file on the AD server, called "logging.txt", to be populated with the information that is created with the .vbs script.

This is the script I have so far:

'Get Dell Service Tag Info
set ProSet = GetObject("winmgmts:").InstancesOf("Win32_BIOS")
Set ProSet1 = GetObject("winmgmts:").InstancesOf("Win32_SystemEnclosure")
For each Pro in ProSet
  For each Pro1 in ProSet1
   ServiceTag=Pro.SerialNumber
    wscript.echo ServiceTag
    exit for
  Next
  exit for
Next

'get username and computername, could also be asked in a batch
Set oShell     = WScript.CreateObject("WScript.Shell")
Set oShellEnv  = oShell.Environment("Process")
sComputerName  = oShellEnv("ComputerName")
sUsername      = oShellEnv("username")
wscript.echo sComputerName & " " & sUsername

Thank you very much in advance!

This is what I've tried so far:

sub log (user, computer)
  dim fs,f
  set fs=Server.CreateObject("Scripting.FileSystemObject")
  set f=fs.OpenTextFile(Server.MapPath(".\logging.csv"),8,true)
  f.WriteLine now & "," & user & "," & computer
  f.Close:set f=Nothing
  set fs=Nothing
end sub

Upvotes: 1

Views: 5131

Answers (2)

carny666
carny666

Reputation: 2430

I feel as though you're leaving something out.. this is how to write a text file in VBS.

dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\somefile.txt", True)
path = filesys.GetAbsolutePathName("c:\somefile.txt")
getname = filesys.GetFileName(path)
filetxt.WriteLine("Your text goes here.")
filetxt.Close
If filesys.FileExists(path) Then
   Response.Write ("Your file, '" & getname & "', has been created.")
End If

Upvotes: 1

Wug
Wug

Reputation: 13196

It would probably be easiest to save the information to a local text file and upload it with the command line ftp utility from the batch script that calls your script rather than trying to invent another wheel and do it in vbscript.

You can list the command line options of ftp with:

ftp /?

I recommend setting up something like this:

ftp -s:control.txt

control.txt would contain something like:

open [hostname or address]
[username]
[password]
cd [remote directory name]
put logging.txt
disconnect
bye

Upvotes: 0

Related Questions