Solved

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

Posted on 2009-04-01
3
683 Views
Last Modified: 2012-05-06
Hello,
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.
0
Comment
Question by:fmcsa001
[X]
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
3 Comments
 
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%")
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing

Open in new window

0
 

Author Comment

by:fmcsa001
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)
0
 
LVL 76

Accepted Solution

by:
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
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objShell = Nothing

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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