• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Need to modify VBS to append Number

Solaris17

Creator Solaris Utility DVD
Joined
Aug 16, 2005
Messages
19,388 (4.27/day)
Likes
6,298
Location
Florida
System Name Venslar
Processor I9 7980XE
Motherboard MSI x299 Tomahawk Arctic
Cooling EKWB L360 R2.0
Memory 32GB Corsair DDR4 3000mhz
Video Card(s) Gigabyte 1080TI
Storage 2x SG 3TB HDDs (RAID 0) | 1x ADATA 128 SSD (Cache) | 1x Drevo 256 SSD | 1x 1TB Samsung 850 EVO (OS)
Display(s) 3x AOC Q2577PWQ (2k IPS)
Case Inwin 303 White (Thermaltake Ring 120mm Purple accent)
Audio Device(s) Realtek ALC 1220 on Audio-Technica ATH-AG1
Power Supply Seasonic 1050W Snow
Mouse Roccat Tyon White
Keyboard Ducky Shine 6 Snow White
Software Windows 10 x64 Pro
#1
Hey guys I need to modify this script to append a file name instead of rewrighting it. I dont really know anything about VBS unfortunately and I can see where it is saying to over wright. but im unsure how to proceed.

Code:
' ' VBScript
Option explicit

' Next line is important, as it calls our function:
Wscript.Echo CopyAFile( "c:\HORWA05DS\PC\Installation", "\\10.204.103.19\version", "pc_release_id.txt")

' Next three lines illustrate correspondence of data to arguments:
''' strSourceFolder := "c:\HORWA05DS\PC\Installation"
''' strTargetFolder := "\\10.204.103.19\version"
''' strFileName := "pc_release_id.txt"
'

Wscript.Quit

Function CopyAFile( Byval strSourceFolder, Byval strTargetFolder, Byval strFileName)
'
' Presumptions: 
' strSourceFolder folder must exist
' strTargetFolder folder must exist
' strFileName file must exist in strSourceFolder folder
'  
Dim objFSO,[COLOR="Red"] booOverWrite[/COLOR], strResult
Set objFSO = CreateObject( "Scripting.FileSystemObject")
If objFSO.FileExists( strSourceFolder & "\" & strFileName) _
    And UCase( strSourceFolder) <> UCase( strTargetFolder) Then
  If objFSO.FolderExists( strTargetFolder) Then
  Else
    strResult = "The destination folder does not exist! In general, creating a folder may be a non-trivial task."
    CopyAFile = strResult
    Exit Function
  End If
  [COLOR="red"]If objFSO.FileExists( strTargetFolder & "\" & strFileName) Then
    strResult = "The file exists, overwritten"
    booOverWrite = vbTrue[/COLOR]
  Else
    strResult = "The file does not exist, created"
    booOverWrite = vbFalse
  End If
  objFSO.CopyFile strSourceFolder & "\" & strFileName, strTargetFolder & "\", [COLOR="red"]booOverWrite[/COLOR]
Else
  strResult = "The source file does not exist, or identical Source and Target folders!"
End If
CopyAFile = strResult
End Function
Can anyone help me out? Basically I have this script working as it should. I need to pull this file and dump it on a network folder so we can monitor that a specific program version is being used. however I need it to append so that I can make sure when an update hits that its being updated. I have multiple PCs dumping this file. Maybe VBS can pull a computer name and append that instead?
 
Joined
Dec 6, 2005
Messages
9,975 (2.25/day)
Likes
3,928
Location
Manchester, NH
System Name Working on it ;)
Processor I7-4790K
Motherboard MSI Z97 U3 Plus
Cooling Be Quiet Pure Rock Air
Memory 16GB 4x4 G.Skill CAS9 2133 Sniper
Video Card(s) Power Color RD Vega 64 Reference
Storage Samsung EVO 500GB / 8 Different WDs / NAS with 2x2Tb WD Black
Display(s) 34" LG 34CB88-P 21:9 Curved UltraWide QHD (3440*1440)
Case Rosewill Challenger
Audio Device(s) Onboard + HD HDMI
Power Supply Corsair HX750 (love it)
Mouse Logitech G5
Keyboard Logitech G710 Blue / G610 Orion Red
Software Win 7 Pro
#2
Not sure if this helps:

strFile = InputBox ("Enter File Name",,"C:\MyFile.Txt")
Const ForAppending = 8

set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(strFile, ForAppending, True)

objFile.WriteLine("Time Stamp: " & Now)
objFile.Close
MsgBox "Done"
The ForAppending variable does this:
CONSTANT VALUE DESCRIPTION
ForReading 1 Opens a file for reading only
ForWriting 2 Opens a file for writing. If the file already exists, the contents are overwritten.
ForAppending 8 Opens a file and starts writing at the end (appends). Contents are not overwritten.

http://www.devguru.com/technologies/VBScript/14075

http://myitforum.com/cs2/blogs/dhit...cript-to-append-to-a-specified-text-file.aspx
 

Solaris17

Creator Solaris Utility DVD
Joined
Aug 16, 2005
Messages
19,388 (4.27/day)
Likes
6,298
Location
Florida
System Name Venslar
Processor I9 7980XE
Motherboard MSI x299 Tomahawk Arctic
Cooling EKWB L360 R2.0
Memory 32GB Corsair DDR4 3000mhz
Video Card(s) Gigabyte 1080TI
Storage 2x SG 3TB HDDs (RAID 0) | 1x ADATA 128 SSD (Cache) | 1x Drevo 256 SSD | 1x 1TB Samsung 850 EVO (OS)
Display(s) 3x AOC Q2577PWQ (2k IPS)
Case Inwin 303 White (Thermaltake Ring 120mm Purple accent)
Audio Device(s) Realtek ALC 1220 on Audio-Technica ATH-AG1
Power Supply Seasonic 1050W Snow
Mouse Roccat Tyon White
Keyboard Ducky Shine 6 Snow White
Software Windows 10 x64 Pro
#3
Not sure if this helps:



The ForAppending variable does this:
CONSTANT VALUE DESCRIPTION
ForReading 1 Opens a file for reading only
ForWriting 2 Opens a file for writing. If the file already exists, the contents are overwritten.
ForAppending 8 Opens a file and starts writing at the end (appends). Contents are not overwritten.

http://www.devguru.com/technologies/VBScript/14075

http://myitforum.com/cs2/blogs/dhit...cript-to-append-to-a-specified-text-file.aspx
I will try this later thanks :)
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
21,083 (6.22/day)
Likes
10,211
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#4
You just want to add the computer name to the file name?

First, it should be duly noted that modifying this function would result in changes to all places it is used so there may be major unintended consequences.

Second, is this script running on client computers or a server? If it is on server, getting the computer name could be problematical.

Third, maybe it would be better if a more advanced program parsed the log on the client and submitted something to a server application which collates and displays it. Combing through lots of text files checking version numbers sounds tedious to me.


For potential future reference: http://www.codeproject.com/Articles/3183/Enhanced-EventLog-writing-for-NET-Applications
 
Last edited:

Solaris17

Creator Solaris Utility DVD
Joined
Aug 16, 2005
Messages
19,388 (4.27/day)
Likes
6,298
Location
Florida
System Name Venslar
Processor I9 7980XE
Motherboard MSI x299 Tomahawk Arctic
Cooling EKWB L360 R2.0
Memory 32GB Corsair DDR4 3000mhz
Video Card(s) Gigabyte 1080TI
Storage 2x SG 3TB HDDs (RAID 0) | 1x ADATA 128 SSD (Cache) | 1x Drevo 256 SSD | 1x 1TB Samsung 850 EVO (OS)
Display(s) 3x AOC Q2577PWQ (2k IPS)
Case Inwin 303 White (Thermaltake Ring 120mm Purple accent)
Audio Device(s) Realtek ALC 1220 on Audio-Technica ATH-AG1
Power Supply Seasonic 1050W Snow
Mouse Roccat Tyon White
Keyboard Ducky Shine 6 Snow White
Software Windows 10 x64 Pro
#5
You just want to add the computer name to the file name?

First, it should be duly noted that modifying this function would result in changes to all places it is used so there may be major unintended consequences.

Second, is this script running on client computers or a server? If it is on server, getting the computer name could be problematical.

Third, maybe it would be better if a more advanced program parsed the log on the client and submitted something to a server application which collates and displays it. Combing through lots of text files checking version numbers sounds tedious to me.


For potential future reference: http://www.codeproject.com/Articles/3183/Enhanced-EventLog-writing-for-NET-Applications
I just want the Pc name appended. We currently use a specific schema for the names which would help us isolate which Pcs are not updating. This script runs on the client machines copying the version file the program creates to a server that has a shared drive.

the script as is works. but it overwrites and I cant have it do that because then their would be no way to isolate which PCs arent updating.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
21,083 (6.22/day)
Likes
10,211
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#6
In which case...

Edit: ABORT: logical error!

Edit: Fixed...
Code:
' ' VBScript
Option explicit

' Next line is important, as it calls our function:
Wscript.Echo CopyAFile( "c:\HORWA05DS\PC\Installation", "\\10.204.103.19\version", "pc_release_id.txt")

' Next three lines illustrate correspondence of data to arguments:
''' strSourceFolder := "c:\HORWA05DS\PC\Installation"
''' strTargetFolder := "\\10.204.103.19\version"
''' strFileName := "pc_release_id.txt"
'

Wscript.Quit

Function CopyAFile( Byval strSourceFolder, Byval strTargetFolder, Byval strFileName)
'
' Presumptions: 
' strSourceFolder folder must exist
' strTargetFolder folder must exist
' strFileName file must exist in strSourceFolder folder
'  
Dim objFSO, booOverWrite, strResult[color=red], WshNetwork, strDestFileName

Set WshNetwork = CreateObject("WScript.Network")
strDestFileName = WshNetwork.ComputerName & "_" & strFileName ' COMPUTERNAME_FILENAME

[/color]Set objFSO = CreateObject( "Scripting.FileSystemObject")
If objFSO.FileExists( strSourceFolder & "\" & strFileName) _
    And UCase( strSourceFolder) <> UCase( strTargetFolder) Then
  If objFSO.FolderExists( strTargetFolder) Then
  Else
    strResult = "The destination folder does not exist! In general, creating a folder may be a non-trivial task."
    CopyAFile = strResult
    Exit Function
  End If
  If objFSO.FileExists( strTargetFolder & "\" & [color=red]strDestFileName[/color]) Then
    strResult = "The file exists, overwritten"
    booOverWrite = vbTrue
  Else
    strResult = "The file does not exist, created"
    booOverWrite = vbFalse
  End If
  objFSO.CopyFile strSourceFolder & "\" & strFileName, strTargetFolder & "\" [color=red]& strDestFileName[/color], booOverWrite
Else
  strResult = "The source file does not exist, or identical Source and Target folders!"
End If
CopyAFile = strResult
End Function

This is untested code so...enter at your own risk.
 
Last edited:

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
21,083 (6.22/day)
Likes
10,211
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#7
I put the code back up. It should work...theoretically.
 

Solaris17

Creator Solaris Utility DVD
Joined
Aug 16, 2005
Messages
19,388 (4.27/day)
Likes
6,298
Location
Florida
System Name Venslar
Processor I9 7980XE
Motherboard MSI x299 Tomahawk Arctic
Cooling EKWB L360 R2.0
Memory 32GB Corsair DDR4 3000mhz
Video Card(s) Gigabyte 1080TI
Storage 2x SG 3TB HDDs (RAID 0) | 1x ADATA 128 SSD (Cache) | 1x Drevo 256 SSD | 1x 1TB Samsung 850 EVO (OS)
Display(s) 3x AOC Q2577PWQ (2k IPS)
Case Inwin 303 White (Thermaltake Ring 120mm Purple accent)
Audio Device(s) Realtek ALC 1220 on Audio-Technica ATH-AG1
Power Supply Seasonic 1050W Snow
Mouse Roccat Tyon White
Keyboard Ducky Shine 6 Snow White
Software Windows 10 x64 Pro
#8
In which case...

Edit: ABORT: logical error!

Edit: Fixed...
Code:
' ' VBScript
Option explicit

' Next line is important, as it calls our function:
Wscript.Echo CopyAFile( "c:\HORWA05DS\PC\Installation", "\\10.204.103.19\version", "pc_release_id.txt")

' Next three lines illustrate correspondence of data to arguments:
''' strSourceFolder := "c:\HORWA05DS\PC\Installation"
''' strTargetFolder := "\\10.204.103.19\version"
''' strFileName := "pc_release_id.txt"
'

Wscript.Quit

Function CopyAFile( Byval strSourceFolder, Byval strTargetFolder, Byval strFileName)
'
' Presumptions: 
' strSourceFolder folder must exist
' strTargetFolder folder must exist
' strFileName file must exist in strSourceFolder folder
'  
Dim objFSO, booOverWrite, strResult[color=red], WshNetwork, strDestFileName

Set WshNetwork = CreateObject("WScript.Network")
strDestFileName = WshNetwork.ComputerName & "_" & strFileName ' COMPUTERNAME_FILENAME

[/color]Set objFSO = CreateObject( "Scripting.FileSystemObject")
If objFSO.FileExists( strSourceFolder & "\" & strFileName) _
    And UCase( strSourceFolder) <> UCase( strTargetFolder) Then
  If objFSO.FolderExists( strTargetFolder) Then
  Else
    strResult = "The destination folder does not exist! In general, creating a folder may be a non-trivial task."
    CopyAFile = strResult
    Exit Function
  End If
  If objFSO.FileExists( strTargetFolder & "\" & [color=red]strDestFileName[/color]) Then
    strResult = "The file exists, overwritten"
    booOverWrite = vbTrue
  Else
    strResult = "The file does not exist, created"
    booOverWrite = vbFalse
  End If
  objFSO.CopyFile strSourceFolder & "\" & strFileName, strTargetFolder & "\" [color=red]& strDestFileName[/color], booOverWrite
Else
  strResult = "The source file does not exist, or identical Source and Target folders!"
End If
CopyAFile = strResult
End Function

This is untested code so...enter at your own risk.
Sweet deal works mint thanks a bunch!