Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

18 Experts available now in Live!

Get 1:1 Help Now