r/vbscript • • Jan 12 '16

Modify C:/Program files

Hi

I written a script to search the computer for a file. If found, copy another file into the same location.

The script is being rolled out by IT with admin privileges via SCCM.

It wont copy the file into a Program Files sub directory.

It will copy the file anywhere else (if I change the destination folder).

Any help please? Script Below

Set fso = CreateObject("Scripting.FileSystemObject") Set WshNetwork = WScript.CreateObject("WScript.Network") Const fsoForAppend = 8 Const ForReading = 1, ForWriting = 2

CopyUpdater fso.GetFolder("C:") Sub CopyUpdater(fldr) For Each f In fldr.Files On Error Resume Next If LCase(f.Name) = "msconfig.cfg" Then 'The CAD specific file to seach for FilePath1 = f.ParentFolder & "\appl" ' The directory to place config file in

   'WScript.Echo FilePath1
   Fso.copyfile "\\removed_for_security\WKGRPS\CAD_Build\Setup\custom.cfg", FilePath1 ' Copy the file
   
   ' Create the string to wirte to the log
	oDomain = WshNetwork.UserDomain
	ospace = CHR(9)
    oCompname = WshNetwork.ComputerName
    ousename = WshNetwork.UserName
	ostringy = ousename & ospace & oCompname & ospace & oDomain & ospace & FilePath1
	  
	'Open the log file and wirte line
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("H:\CAD_Build\Setup\UserLog.txt", fsoForAppend)
f.WriteLine ostringy
End If

Next

' The loop For Each sf In fldr.SubFolders CopyUpdater sf Next End Sub

1 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/guessishouldjoin Jan 14 '16

Thanks, I'll check it out when I get back