Solved

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

Posted on 2009-04-01
3
657 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now