Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

findstr If Then search

Status
Not open for further replies.

mrdecrypter

IS-IT--Management
Aug 18, 2005
24
US
Here is an example of what i am trying to do:

getoutput("findstr.exe ""test"" c:\test.txt")
function getoutput(app)
If lcase(getoutput) = "" Then
msgbox("Found")
else
msgbox("Not Found")
end if
end function

this may be a totally broken approach at trying to use an If Then statement in vbscript. All im simply trying to do is search a text file for a specific string, and if it does or doesnt find the text then 'do something'....i know how to do it in DOS with simple findstr and %errorlevel% returns, but vbscript is kicking my rear on it. This one is probably real simple for you experts. any help?
 
strFile = "C:\Foo.txt"
strSearchFor = "Something"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
WScript.Echo "Found It"
Else
WScript.Echo "Didn't find it"
End If

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks!, now how do i use this to search the registry in the same manner for if/then?
 
Searching the registry is a good bit harder. Search this forum for "Enumerate Registry". Are you doing this on your own machine only?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
It will be in the logon script for my domain. It will search the registry for installed apps and then compile a report to a log file. Thats why i needed the search text file function, so that if it does not find a specific string, then it will install the missing apps. We all have admin rights, its a simple unsecured intranet.
 
For what you are doing, I would suggest looking at your apps and finding a good way to tell if each one is installed then write code to generalize the various methods of determining install status. There is no one way to always determine if some arbitrary app is installed. It will have to be on a case by case basis.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
generally, registry entries dont change for the installation location keys. for example, HKLM\Software\Macromedia\Flashplayer\Currenversion will never change unless i upgrade to a new version. So if i search for HKLM\Software\Macromedia\Flashplayer and it is missing, then the script will install it :)
 
That is my point. You will need to generalize the ability to have the script determine if an app is installed. So for instance you would write a function that is handed the name of an app and the location of a registry key associated with that app being installed and it would return true or false edpending on whether or not the key is there. This is not at all the same thing as searching the registry. You know a specific location and you are testing if it is valid. Searching would be getting a list of every key that had the word Macromedia in it.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
ah yes im sorry, i misunderstood you. i will already know the locations of the specific keys. i only have about 5-10 apps that i want to ensure are installed
 
In that case search this forum or use google. Determining the existence of a key has been covered before.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
yep. PHV's link is perfect. Thanks fellas i owe you a beer
 
I know that the link PHV provided was helpful, but you might like to give this a try to.

Here is a finction I wrote for my inventory script. this will return all of the installed software on a PC.

Code:
Function GetSoftware()
	Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
	".\root\default:StdRegProv")
	oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
	software = vbCrLf & "******************************************" & vbCrLf
	software = software & "Installed Software List" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
	For Each subkey In arrSubKeys
	'MsgBox subkey
	If Left (subkey, 1) <> "{" And Lcase(Left(subkey, 2)) <> "kb"Then
		software = software & subkey & vbCrLf
	End If
	Next
	GetSoftware = software
End Function

I hope you find this post helpful.

Regards,

Mark
 
This function will return all software that puts a key in the uninstall key. Not all software installs do this, but the majority do.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top