Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

776 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