Jump to content

vbscript to find a string value in a text file and then write an answer


Recommended Posts

Posted

Hey all

 

I have a vbscript that will read a folder directory and the files with each of the subfolders and then writes this to a txt file

sample of txt file

 

\\servername\packageinstalllogs$\AC-0012

Adobe_Acrobat_9_Pro.txt

 

\\servername\packageinstalllogs$\AC-0013

Adobe_Acrobat_9_Pro.txt

Adobe_Dreamweaver_CS5.txt

Adobe_Fireworks_CS5.txt

Adobe_Flash_CS5.txt

Adobe_Photoshop_CS5.txt

Mediator9.txt

 

\\servername\packageinstalllogs$\AC-0014

Adobe_Acrobat_9_Pro.txt

Adobe_Dreamweaver_CS5.txt

Adobe_Fireworks_CS5.txt

Adobe_Flash_CS5.txt

Adobe_Photoshop_CS5.txt

Mediator9.txt

 

What I need to add to the script is each txt file it finds I need it to open that file look for a script value if it finds it, it write as yes next to the file name if it does not find it, it writes a no.

The above sample would then change to this

 

\\servername\packageinstalllogs$\AC-0014

Adobe_Acrobat_9_Pro.txt, Yes

Adobe_Dreamweaver_CS5.txt, No

Adobe_Fireworks_CS5.txt, Yes

Adobe_Flash_CS5.txt, Yes

Adobe_Photoshop_CS5.txt, Yes

Mediator9.txt, Yes

 

The script I have at the moment is as follows

Dim FSO, LogFile

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set FSO = CreateObject ("Scripting.FileSystemObject")

 

objStartFolder = "\\servername\packageinstalllogs$"

 

Set LogFile = FSO.CreateTextFile("\\servername\packageinstalllogs$\packageinstallcheck.txt",True)

 

Set objFolder = objFSO.GetFolder(objStartFolder)

 

LogFile.writeLine objFolder.Path

 

Set colFiles = objFolder.Files

For Each objFile in colFiles

 

LogFile.writeLine objFile.Name

 

Next

LogFile.writeLine Echo

 

ShowSubfolders objFSO.GetFolder(objStartFolder)

 

Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders

 

LogFile.writeLine Subfolder.Path

 

Set objFolder = objFSO.GetFolder(Subfolder.Path)

Set colFiles = objFolder.Files

For Each objFile in colFiles

 

 

 

LogFile.writeLine objFile.Name

Next

LogFile.writeLine Echo

ShowSubFolders Subfolder

Next

End Sub

 

I have tried hitting the VBscript book off my head but it doesn’t seem to be working any help is appreciated

 

Thank you

Posted
What I need to add to the script is each txt file it finds I need it to open that file look for a script value if it finds it, it write as yes next to the file name if it does not find it, it writes a no.

 

What "script value" are you looking for?

 

aka list all files, if .txt search inside, if found post yes, else no?

 

Steve

Posted

Sorry it is meant to be string value not script value, anyway the value I am looking for

 

Installation success or error status: 0.

 

If that value is in a text file (normal the program name.txt) I want the script to write a line that combines the file name, yes if the vale is not there it writes the file name,no

Posted

Will all these files be .txt and only have 1 line in them? Or do you need it to search through whole files, and determine what types etc it is? :p Reading one line of all .txts a lot easier than that :D

 

Steve

Posted
I bet you can get grep for windows. Then you can script this in batch file in about 5 min

 

Think findstr still exists, but not sure if it's usable in vbs. Bat wise would be nice aye

 

Steve

Posted

hey

 

the text file is a msi output file so very full

 

example

 

 

=== Logging started: 15/07/2011 12:30:25 ===

Action start 12:30:25: INSTALL.

Action start 12:30:25: AppSearch.

Action ended 12:30:25: AppSearch. Return value 1.

Action start 12:30:25: ValidateProductID.

Action ended 12:30:25: ValidateProductID. Return value 1.

Action start 12:30:25: CostInitialize.

Action ended 12:30:25: CostInitialize. Return value 1.

Action start 12:30:25: SetWINVOLUME.

Action ended 12:30:25: SetWINVOLUME. Return value 1.

Action start 12:30:25: FileCost.

Action ended 12:30:25: FileCost. Return value 1.

Action start 12:30:25: CostFinalize.

Action ended 12:30:25: CostFinalize. Return value 1.

Action start 12:30:25: InstallValidate.

Action ended 12:30:25: InstallValidate. Return value 1.

Action start 12:30:25: InstallInitialize.

Action ended 12:30:25: InstallInitialize. Return value 1.

Action start 12:30:25: ProcessComponents.

Action ended 12:30:25: ProcessComponents. Return value 1.

Action start 12:30:25: UnpublishFeatures.

Action ended 12:30:25: UnpublishFeatures. Return value 1.

Action start 12:30:25: StopServices.

Action ended 12:30:25: StopServices. Return value 1.

Action start 12:30:25: DeleteServices.

Action ended 12:30:25: DeleteServices. Return value 1.

Action start 12:30:25: RemoveRegistryValues.

Action ended 12:30:25: RemoveRegistryValues. Return value 1.

Action start 12:30:25: RemoveFiles.

Action ended 12:30:25: RemoveFiles. Return value 0.

Action start 12:30:25: InstallFiles.

Action ended 12:30:25: InstallFiles. Return value 1.

Action start 12:30:25: WriteRegistryValues.

Action ended 12:30:25: WriteRegistryValues. Return value 1.

Action start 12:30:25: StartServices.

Action ended 12:30:25: StartServices. Return value 1.

Action start 12:30:25: RegisterUser.

Action ended 12:30:25: RegisterUser. Return value 1.

Action start 12:30:25: RegisterProduct.

Action ended 12:30:25: RegisterProduct. Return value 1.

Action start 12:30:25: PublishFeatures.

Action ended 12:30:25: PublishFeatures. Return value 1.

Action start 12:30:25: PublishProduct.

Action ended 12:30:25: PublishProduct. Return value 1.

Action start 12:30:25: InstallFinalize.

Action ended 12:30:32: InstallFinalize. Return value 1.

Action ended 12:30:32: INSTALL. Return value 1.

Property(S): COMMONAPPDATAFOLDER = C:\ProgramData

Property(S): COMMONDESKTOPFOLDER = C:\Users\Public\Desktop

Property(S): COMMONPROGRAMMENUFOLDER = C:\ProgramData\Microsoft\Windows\Start Menu\Programs

Property(S): COMMONSTARTMENUFOLDER = C:\ProgramData\Microsoft\Windows\Start Menu

Property(S): COMMONSTARTUPFOLDER = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Property(S): D_0 = C:\Windows\system32\Restore\

Property(S): SystemFolder = C:\Windows\system32\

Property(S): D_1 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2911.0\

Property(S): D_2 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2910.0\

Property(S): D_3 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2909.0\

Property(S): D_4 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2908.0\

Property(S): D_5 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2907.0\

Property(S): D_6 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2906.0\

Property(S): D_7 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2905.0\

Property(S): D_8 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2904.0\

Property(S): D_9 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2903.0\

Property(S): D_10 = C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\

Property(S): D_13 = C:\Windows\Logs\

Property(S): D_14 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectSound\1.0.2902.0__31bf3856ad364e35\

Property(S): D_16 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectPlay\1.0.2902.0__31bf3856ad364e35\

Property(S): D_18 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectInput\1.0.2902.0__31bf3856ad364e35\

Property(S): D_20 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectDraw\1.0.2902.0__31bf3856ad364e35\

Property(S): D_22 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2911.0__31bf3856ad364e35\

Property(S): D_23 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2910.0__31bf3856ad364e35\

Property(S): D_24 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2909.0__31bf3856ad364e35\

Property(S): D_25 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2908.0__31bf3856ad364e35\

Property(S): D_26 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2907.0__31bf3856ad364e35\

Property(S): D_27 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2906.0__31bf3856ad364e35\

Property(S): D_28 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2905.0__31bf3856ad364e35\

Property(S): D_29 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2904.0__31bf3856ad364e35\

Property(S): D_30 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2903.0__31bf3856ad364e35\

Property(S): D_31 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\1.0.2902.0__31bf3856ad364e35\

Property(S): D_33 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\

Property(S): D_35 = C:\Windows\assembly\GAC\Microsoft.DirectX.Diagnostics\1.0.2902.0__31bf3856ad364e35\

Property(S): D_37 = C:\Windows\assembly\GAC\Microsoft.DirectX.AudioVideoPlayback\1.0.2902.0__31bf3856ad364e35\

Property(S): D_39 = C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\

Property(S): D_43 = C:\Windows\INF\

Property(S): D_44 = C:\System Volume Information\SPP\OnlineMetadataCache\

Property(S): TARGETDIR = C:\

Property(S): WINVOLUME = C:\

Property(S): D_11 = C:\Windows\Microsoft.NET\DirectX for Managed Code\

Property(S): D_12 = C:\Windows\Microsoft.NET\

Property(S): WindowsFolder = C:\Windows\

Property(S): D_15 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectSound\

Property(S): D_41 = C:\Windows\assembly\GAC\

Property(S): D_17 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectPlay\

Property(S): D_19 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectInput\

Property(S): D_21 = C:\Windows\assembly\GAC\Microsoft.DirectX.DirectDraw\

Property(S): D_32 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3DX\

Property(S): D_34 = C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\

Property(S): D_36 = C:\Windows\assembly\GAC\Microsoft.DirectX.Diagnostics\

Property(S): D_38 = C:\Windows\assembly\GAC\Microsoft.DirectX.AudioVideoPlayback\

Property(S): D_40 = C:\Windows\assembly\GAC\Microsoft.DirectX\

Property(S): D_42 = C:\Windows\assembly\

Property(S): D_45 = C:\System Volume Information\SPP\

Property(S): D_46 = C:\System Volume Information\

Property(S): SourceDir = \\server\packages$\DirectXfeb2010\

Property(S): VersionNT = 601

Property(S): Manufacturer = Microsoft

Property(S): ProductCode = {0EC85D7E-883F-4E35-99AB-FB71FAD96F9E}

Property(S): ProductLanguage = 2057

Property(S): ProductName = DirectXfeb2010

Property(S): ProductVersion = 1.0.0.0

Property(S): UpgradeCode = {CEE9DF8F-0D39-4A31-A63E-6ECBC3E1D926}

Property(S): ARPNOMODIFY = NoModify

Property(S): REINSTALLMODE = omus

Property(S): ALLUSERS = 1

Property(S): ARPPRODUCTICON = MainIcon

Property(S): MsiLogFileLocation = \\server\packageinstalllogs$\VMC-0002\DirectXfeb2010.txt

Property(S): PackageCode = {AC01DC90-60FA-4895-AE2A-5EB6E7E6A13A}

Property(S): ProductState = -1

Property(S): PackagecodeChanging = 1

Property(S): CURRENTDIRECTORY = C:\Windows\system32

Property(S): CLIENTUILEVEL = 3

Property(S): CLIENTPROCESSID = 1928

Property(S): VersionDatabase = 200

Property(S): VersionMsi = 5.00

Property(S): WindowsBuild = 7600

Property(S): ServicePackLevel = 0

Property(S): ServicePackLevelMinor = 0

Property(S): MsiNTProductType = 1

Property(S): WindowsVolume = C:\

Property(S): System16Folder = C:\Windows\system\

Property(S): RemoteAdminTS = 1

Property(S): TempFolder = C:\Users\internet\AppData\Local\Temp\

Property(S): ProgramFilesFolder = C:\Program Files\

Property(S): CommonFilesFolder = C:\Program Files\Common Files\

Property(S): AppDataFolder = C:\Users\internet\AppData\Roaming\

Property(S): FavoritesFolder = C:\Users\internet\Favorites\

Property(S): NetHoodFolder = C:\Users\internet\AppData\Roaming\Microsoft\Windows\Network Shortcuts\

Property(S): PersonalFolder = C:\Users\internet\Documents\

Property(S): PrintHoodFolder = C:\Users\internet\AppData\Roaming\Microsoft\Windows\Printer Shortcuts\

Property(S): RecentFolder = C:\Users\internet\AppData\Roaming\Microsoft\Windows\Recent\

Property(S): SendToFolder = C:\Users\internet\AppData\Roaming\Microsoft\Windows\SendTo\

Property(S): TemplateFolder = C:\ProgramData\Microsoft\Windows\Templates\

Property(S): CommonAppDataFolder = C:\ProgramData\

Property(S): LocalAppDataFolder = C:\Users\internet\AppData\Local\

Property(S): MyPicturesFolder = C:\Users\internet\Pictures\

Property(S): AdminToolsFolder = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\

Property(S): StartupFolder = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\

Property(S): ProgramMenuFolder = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\

Property(S): StartMenuFolder = C:\ProgramData\Microsoft\Windows\Start Menu\

Property(S): DesktopFolder = C:\Users\Public\Desktop\

Property(S): FontsFolder = C:\Windows\Fonts\

Property(S): GPTSupport = 1

Property(S): OLEAdvtSupport = 1

Property(S): ShellAdvtSupport = 1

Property(S): Intel = 6

Property(S): PhysicalMemory = 1024

Property(S): VirtualMemory = 1608

Property(S): AdminUser = 1

Property(S): MsiTrueAdminUser = 1

Property(S): LogonUser = internet

Property(S): UserSID = S-1-5-21-585913135-526007781-3860785735-5362

Property(S): UserLanguageID = 2057

Property(S): ComputerName = VMC-0002

Property(S): SystemLanguageID = 2057

Property(S): ScreenX = 1024

Property(S): ScreenY = 768

Property(S): CaptionHeight = 22

Property(S): BorderTop = 1

Property(S): BorderSide = 1

Property(S): TextHeight = 16

Property(S): TextInternalLeading = 3

Property(S): ColorBits = 32

Property(S): TTCSupport = 1

Property(S): Time = 12:30:32

Property(S): Date = 15/07/2011

Property(S): MsiNetAssemblySupport = 2.0.50727.4927

Property(S): MsiWin32AssemblySupport = 6.1.7600.16385

Property(S): RedirectedDllSupport = 2

Property(S): MsiRunningElevated = 1

Property(S): Privileged = 1

Property(S): USERNAME = Network Manager

Property(S): COMPANYNAME = Park Hall Academy

Property(S): DATABASE = C:\Windows\Installer\869ef3.msi

Property(S): OriginalDatabase = \\server\packages$\DirectXfeb2010\DirectXfeb2010.msi

Property(S): UILevel = 2

Property(S): ACTION = INSTALL

Property(S): ROOTDRIVE = C:\

Property(S): CostingComplete = 1

Property(S): OutOfDiskSpace = 0

Property(S): OutOfNoRbDiskSpace = 0

Property(S): PrimaryVolumeSpaceAvailable = 0

Property(S): PrimaryVolumeSpaceRequired = 0

Property(S): PrimaryVolumeSpaceRemaining = 0

Property(S): INSTALLLEVEL = 1

Property(S): SOURCEDIR = \\server\packages$\DirectXfeb2010\

Property(S): SourcedirProduct = {0EC85D7E-883F-4E35-99AB-FB71FAD96F9E}

Property(S): ProductToBeRegistered = 1

MSI (s) (F8:04) [12:30:32:181]: Product: DirectXfeb2010 -- Installation completed successfully.

 

MSI (s) (F8:04) [12:30:32:196]: Windows Installer installed the product. Product Name: DirectXfeb2010. Product Version: 1.0.0.0. Product Language: 2057. Manufacturer: Microsoft. Installation success or error status: 0.

 

=== Logging stopped: 15/07/2011 12:30:32 ===

Posted

This script should do it I think:

 

Dim FSO, LogFile, rdFile

Set FSO = CreateObject ("Scripting.FileSystemObject")

objStartFolder = "\\servername\packageinstalllogs$"

Set LogFile = FSO.CreateTextFile("\\servername\packageinstalllog s$\packageinstallcheck.txt",True)
Set objFolder = FSO.GetFolder(objStartFolder)

LogFile.writeLine objFolder.Path

Set colFiles = objFolder.Files
For Each objFile in colFiles
LogFile.writeLine objFile.Name
Next

LogFile.writeLine Echo

ShowSubfolders FSO.GetFolder(objStartFolder)


Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
	LogFile.writeLine Subfolder.Path
	
	Set objFolder = FSO.GetFolder(Subfolder.Path)
	Set colFiles = objFolder.Files
	
	For Each objFile in colFiles
		LogFile.Write objFile.Name
		
		Set rdFile = FSO.OpenTextFile(objFile.Path, 1)
		strContents = rdFile.ReadAll
		rdFile.Close
		
		if InStr(1, strContents, "Installation success or error status: 0", 1) > 0 Then 
			LogFile.Write ", Yes" & Chr(10)
		else
			LogFile.Write ", No" & Chr(10)
		end if
	Next
	
	LogFile.writeLine Echo
	ShowSubFolders Subfolder
Next
End Sub

Posted

Hey

Very close. I have to tweak it to display how I want it to, but it only displays “no” at the end of each Line

Sample

\\server\packageinstalllogs$\VMC-0002

DirectXfeb2010.txt, No

eset_client.txt, No

Mediator9.txt, No

Microsoft_DOTNET4-MSI_netfx_Core_x86.msi.txt, No

Microsoft_DOTNET4-MSI_netfx_Extended_x86.msi.txt, No

Microsoft_DOTNET4.htm, No

Microsoft_Silverlight.txt, No

Microsoft_Silverlight_update.txt, No

MindGenius.txt, No

Scorch_plugin.txt, No

Securus_Client_v7.00.20_v11.txt, No

 

I have had a look at the files and the string value is there

 

Also the changes I have made are below

For Each objFile in colFiles

  

            Set rdFile = FSO.OpenTextFile(objFile.Path, 1)

            strContents = rdFile.ReadAll

            rdFile.Close

            

            if InStr(1, strContents, "success or error status: 0.", 1) > 0 Then 

                LogFile.Write objFile.Name & ", Yes" & Chr(10)

                LogFile.writeLine Echo

            else

                LogFile.Write objFile.Name & ", No" & Chr(10)

                LogFile.writeLine Echo

            end if

        Next

Posted

Try changing:

 

if InStr(1, strContents, "Installation success or error status: 0", 1) > 0 Then 

 

to

 

if InStr(strContents, "Installation success or error status: 0") > 0 Then 

 

Steve

Posted

Might be worth doing a WScript.Echo strContents 

 

just before it does the check, as I thought there was a limit to how much a string could hold at once, it may be as silly as it's cutting off the end of the file.

 

Easy way to check it :D

 

Steve

Posted

I'm afraid I'm at a loss as to why, it works fine for me...

 

Perhaps it could be a permissions issue blocking the script from accessing the files' contents, although I would expect you to get an error message if that were the case...

Posted (edited)

@Steve21 might be on to something, try this to read files line by line (just replace the necessary code in ShowSubFolders):

 

For Each objFile in colFiles
LogFile.Write objFile.Name
	
Set rdFile = FSO.OpenTextFile(objFile.Path, 1)
bFound = False
Do Until rdFile.AtEndOfStream
	srtContents = rdFile.ReadLine
	if InStr(1, strContents, "success or error status: 0", 1) > 0 Then 
		bFound = True
		Exit Do
               End If
Loop
rdFile.Close

if bFound = True Then 
	LogFile.Write ", Yes" & Chr(10)
	LogFile.WriteLine Echo
else
	LogFile.Write ", No" & Chr(10)
	LogFile.WriteLine Echo
end if
Next

Edited by LosOjos
missed an "End If"! :doh:
Posted
Hey

 

your right it does help see below

 

[ATTACH=CONFIG]10859[/ATTACH]

 

Can you post full script you're using atm please will be easier to see it :D

 

Also as a point, the script Los posted "won't" search any .txt files in the same directory as the script, only subfolders. So that may be the simple issue, if that's how you set it up?

 

Steve

Posted

Full script

 

Dim FSO, LogFile, rdFile

 

Set FSO = CreateObject ("Scripting.FileSystemObject")

 

objStartFolder = "\\server\packageinstalllogs$"

 

Set LogFile = FSO.CreateTextFile("\\server\packageinstalllogs$\packageinstallcheckv6.txt",True)

Set objFolder = FSO.GetFolder(objStartFolder)

 

LogFile.writeLine objFolder.Path

 

Set colFiles = objFolder.Files

For Each objFile in colFiles

LogFile.writeLine objFile.Name

Next

 

LogFile.writeLine Echo

 

ShowSubfolders FSO.GetFolder(objStartFolder)

 

 

Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders

'LogFile.writeLine Subfolder.Path

 

Set objFolder = FSO.GetFolder(Subfolder.Path)

Set colFiles = objFolder.Files

 

For Each objFile in colFiles

LogFile.Write objFile.Name

 

Set rdFile = FSO.OpenTextFile(objFile.Path, 1)

bFound = False

Do Until rdFile.AtEndOfStream

srtContents = rdFile.ReadLine

if InStr(1, strContents, "success or error status: 0", 1) > 0 Then

bFound = True

Exit Do

End If

Loop

rdFile.Close

 

WScript.Echo strContents

 

if bFound = True Then

LogFile.Write objFile.Name & ", Yes" & Chr(10)

LogFile.WriteLine Echo

else

LogFile.Write objFile.Name & ", No" & Chr(10)

LogFile.WriteLine Echo

end if

Next

 

LogFile.writeLine Echo

ShowSubFolders Subfolder

Next

End Sub

Posted

the folder are set up as follows

 

packagelogs

PCname-0001

software1.txt

software2.txt

software3.txt

PCname-0002

software1.txt

software2.txt

software3.txt

Posted

Can you just try this script standalone not with the other one:

 


Dim FSO, LogFile, rdFile

Set FSO = CreateObject ("Scripting.FileSystemObject")

Set LogFile = FSO.CreateTextFile("PATHHERE\packageinstallcheck.txt",True)

Set rdFile = FSO.OpenTextFile("PATHHERE\software1.txt", 1)
strContents = rdFile.ReadAll
rdFile.Close

		
if InStr(1, strContents, "success or error status: 0", 1) > 0 Then 
LogFile.Write "Yes" & Chr(10)
else
LogFile.Write "No" & Chr(10)
end if

 

Put a direct path to one of the software.txt files in, and obviously reput your server paths back in.

 

Just want to see if its something about the script, or if its something weird :p

 

Thanks,

Steve

Posted

hey

 

the packageinstallcheck.txt file only has no in it

 

the file that it was looking at was this (just end part)

 

Property(S): SourcedirProduct = {10ABE49D-343A-463E-9753-C4C5A05ECEF9}

Property(S): ProductToBeRegistered = 1

MSI (s) (30:B0) [10:27:08:250]: Product: Sibelius Scorch (Firefox, Opera, Netscape only) -- Installation completed successfully.

 

MSI (s) (30:B0) [10:27:08:250]: Windows Installer installed the product. Product Name: Sibelius Scorch (Firefox, Opera, Netscape only). Product Version: 6.2.0. Product Language: 1033. Manufacturer: Sibelius Software. Installation success or error status: 0.

 

=== Logging stopped: 15/07/2011 10:27:08 ===

Posted
hey

 

the packageinstallcheck.txt file only has no in it

 

the file that it was looking at was this (just end part)

 

Property(S): SourcedirProduct = {10ABE49D-343A-463E-9753-C4C5A05ECEF9}

Property(S): ProductToBeRegistered = 1

MSI (s) (30:B0) [10:27:08:250]: Product: Sibelius Scorch (Firefox, Opera, Netscape only) -- Installation completed successfully.

 

MSI (s) (30:B0) [10:27:08:250]: Windows Installer installed the product. Product Name: Sibelius Scorch (Firefox, Opera, Netscape only). Product Version: 6.2.0. Product Language: 1033. Manufacturer: Sibelius Software. Installation success or error status: 0.

 

=== Logging stopped: 15/07/2011 10:27:08 ===

 

Very strange... That works fine here. Can you try running it locally on your computer with those files (aka C drive), cut out the network part.

 

Could be something stupid like you don't have access to read those files through the script over the network.

 

Especially if everything you try to access the file, your echo's are showing nothing.

 

Steve

Posted
just looked and the encoding is set to unicode, i saved the file as ANSI and it worked so 2 options 1 can VBscript be told to understand unicode or 2 is there a way to convert the software.txt to ANSI
Posted

hey

 

i have just change the following and it works

 

Set rdFile = FSO.OpenTextFile(objFile.Path, 1,) to Set rdFile = FSO.OpenTextFile(objFile.Path, 1, TristateFalse, -1)

 

but i think it is still not full working as i am now getting this error when i run it

 

vbserror2.jpg

 

the full script is below

 

Dim FSO, LogFile, rdFile

 

Set FSO = CreateObject ("Scripting.FileSystemObject")

 

objStartFolder = "\\server\packageinstalllogs$"

 

Set LogFile = FSO.CreateTextFile("\\server\packageinstalllogs$\packageinstallcheckv5.txt",True)

Set objFolder = FSO.GetFolder(objStartFolder)

 

LogFile.writeLine objFolder.Path

 

Set colFiles = objFolder.Files

For Each objFile in colFiles

LogFile.writeLine objFile.Name

Next

 

LogFile.writeLine Echo

 

ShowSubfolders FSO.GetFolder(objStartFolder)

 

 

Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders

LogFile.writeLine Subfolder.Path

 

Set objFolder = FSO.GetFolder(Subfolder.Path)

Set colFiles = objFolder.Files

 

For Each objFile in colFiles

'LogFile.Write objFile.Name

 

Set rdFile = FSO.OpenTextFile(objFile.Path, 1, TristateFalse, -1)

strContents = rdFile.ReadAll

rdFile.Close

 

'WScript.Echo strContents

 

if InStr(1, strContents, "success or error status: 0.", 1) > 0 Then

LogFile.Write objFile.Name & ", Yes"

LogFile.writeLine Echo

else

LogFile.Write objFile.Name & ", No"

LogFile.writeLine Echo

end if

Next

 

LogFile.writeLine Echo

ShowSubFolders Subfolder

Next

End Sub

Posted

That error is usually when you've tried to read an empty text file.

 

Try using the code I posted earlier to read line by line (but remembering to use your new OpenTextFile code) and it should work

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...