VB script, Create txt file and copy it to network share.

Posted on 2009-04-01
Last Modified: 2012-05-06
I'm looking for a script that will create a txt file of the computer name which ran the script and copy that .txt file up to a network share.

I just need to see when a system has successfully completed a script and copy a txt file with the computer name in the file name to a network share directory. Hopyfully thats pretty straight forware.
Question by:fmcsa001
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 76

Expert Comment

by:David Lee
ID: 24041033
Hi, fmcsa001.

Here's a script for doing this.  Rather than copy the file to the share it just creates it there.  If that won't work, then I can change the script to copy the file.
Dim objFSO, objFile, objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Replace the path and file name on the next line'
Set objFile = objFSO.CreateTextFile("C:\Computer.txt",True)
Set objShell = CreateObject("Wscript.Shell")
objFile.WriteLine objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing

Open in new window


Author Comment

ID: 24041367
This is almost exactly what I need, could you change it so that the file name is the name of the computer instead of computername.txt? (e.g. Frontdesk PC.txt)
LVL 76

Accepted Solution

David Lee earned 500 total points
ID: 24044648
Try this.
Dim objFSO, objFile, objShell, strComputerName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
strComputerName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
'Replace the path and file name on the next line'
Set objFile = objFSO.CreateTextFile("C:\" & strComputerName,True)
objFile.WriteLine strComputerName
Set objFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing

Open in new window


Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question