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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Almost there... Look at my script!

Status
Not open for further replies.

ErrolDC

MIS
May 26, 2004
72
US
Thanks to everyone's input, I'm almost done with my script. I'm posting because I'm very proud of it :). Especially since I am very much a newbie when it comes to this language.

Here is the script.

Code:
set objNet = CreateObject("Wscript.NetWork")
set shell = CreateObject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
dim username
dim domainname
dim counter
TargetGroup = "SAV Install"
username = objNet.UserName
domainname = objNet.UserDomain
computername = objNet.ComputerName
mcafee="McAfee VirusScan"
msicall="msiexec /I"&Chr(34)&"\\dfiint-flsvr\data\SAVTools\INSTALL\Symantec Antivirus.msi"&Chr(34)&" INSTALLDIR="&Chr(34)&"C:\Program Files\Symantec AntiVirus"&Chr(34)&"ADDLOCAL=SAVMain,SAVUI,SAVHelp,EMailTools,OutlookSnapin,Pop3Smtp,QClient NETWORKTYPE=1 INSTALLSERVER=0 SERVERNAME=DFIINT-APPSVR /l C:\savinst.log REBOOT=Suppress /qn"

Set User = GetObject("WinNT://" & domainname & "/" & username & ",user")
counter = 0 ' set count to 0 initially. 
For Each Group in User.Groups
If Group.Name = TargetGroup then 
	counter = counter + 1
end if
next
if counter > 0 then
	installlog = "C:\savinst.log"
	if not fso.FileExists(installlog) then		
		shell.Exec("REGSVR32 /s \\dfiint-flsvr\data\SAVTools\RegObj.dll")
		Wscript.Sleep(2000)
		dim objRegRootKey ' initialize the variable
		set objReg = CreateObject("RegObj.Registry") ' create the object
		SWKey="\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" ' this is the subkey I need to search through
		set objRegRootKey=objReg.RegKeyFromString(SWKey) 
		On Error Resume Next
		counter = 0 ' reset the counter. don't know any other way to do this
		For Each objSubKey in objRegRootKey.Subkeys ' begin looping through the subkeys
		set subreg=objReg.RegKeyFromString(SWKey&objSubKey.Name)
		swname=subreg.values("displayname").value
		if instr(swname, mcafee) <> 0 then
			counter = counter + 1
			set mykey=subreg
			Exit For
			end if
		next
		if counter = 0 then
			Wscript.Echo "Mcafee's not installed!"
			call loginscript
		end if
		set stream = fso.CreateTextFile("C:\uninstall_mcafee.aut")
		stream.Write "Platform=WinNT" & vbCRLF & "runprogram=HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & objSubKey.Name & ", UninstallString"			
		stream.Close								
		fso.CopyFile "\\dfiint-flsvr\data\SAVTools\UNINSTALL\AV32.exe", "C:\"
		set uninstall = Shell.Run("C:\AV32.exe C:\uninstall_mcafee.aut")
		uinstall
		do while not fso.FileExists("C:\STATUS.INI")
		Wscript.Sleep(1000)
		loop
		set str = fso.OpenTextFile("C:\STATUS.INI")
		str.SkipLine
		match=str.ReadLine
		if instr(match, "AV32 was successful") = 0  then
			Wscript.Echo "The uninstall of current AV failed"
			str.Close
			call loginscript
			else			
			str.Close
			set install = Shell.Exec(msicall)
			install 
			do while install.Status = 0
			Wscript.Sleep(5000)
			loop
			set str = fso.OpenTextFile("C:\savinst.log")
			dim status
			do until str.AtEndofStream
			str.ReadLine	
			match=str.ReadLine
				if instr(match, "completed successfully.") = 0 then
				str.SkipLine
					else if	instr(match, "completed successfully.") <> 0 then
					status=1
					exit do
					end if					
				end if				
			loop
			end if
		if status=1 then
			set stream = fso.CreateTextFile("\\dfiint-flsvr\data\SAVTools\LOGS\" & computername &".log")
			stream.WriteLine "install was successful"
			stream.Close
			
		else
			set stream = fso.CreateTextFile("\\dfiint-flsvr\data\SAVTools\LOGS\" & computername &".log")
			stream.WriteLine "install was unsuccessful"
			stream.Close
		end if
	Wscript.Echo "This is the Login Script running.. whether the install was success or not"	
	call loginscript
	else
	Wscript.Echo "Apparently, it is already installed"			
	call loginscript
	end if
		 						

else
Wscript.Echo "The user was not a member of the required group"
call loginscript
end if

sub loginscript()
	Wscript.Echo "This is the Login Script Running"
	Wscript.Quit(1)
end sub

Now, please don't make fun of this effort by a newbie. I'm sure that I could have done things much differently had I known better. But I don't :)

Anyways, I need a final peice of help. In this portion

Code:
do until str.AtEndofStream
			str.ReadLine	
			match=str.ReadLine
				if instr(match, "completed successfully.") = 0 then
				str.SkipLine
					else if	instr(match, "completed successfully.") <> 0 then
					status=1
					exit do
					end if					
				end if				
			loop
			end if

what I want to do is to scan each line of a log file looking for the string that lets me know the software install was cool. If the string is found, it sets status=1 and from there, I know what to put in the log file I create. Well, apparently I'm not doing this correctly because the log files say the install was not successfuly, but obviously I know it was. Can someone point me in the right direction? Thanks.


 
str.ReadLine
match=str.ReadLine

match is set only for half the lines as you read str twice ...
You may try something like this:
Do Until str.AtEndofStream
match=str.ReadLine
If inStr(match, "completed successfully.") > 0 Then
status = 1
Exit Do
End If
Loop

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Review the script that I wrote here to modify the 'boot.ini' files. Hope that this is of some help. I think I know what you're trying to do, but sometimes, it's nice to see some working code to give you a NUDGE.....

Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''
' +---------------------------------------------+
' | Modify the Boot.ini file			|
' +---------------------------------------------+
'''''''''''''''''''''''''''''''''''''''''''''''''''
' NT 4 = +S    +R
' 2K   = +S +H[COLOR=black]
wshshell.run("cmd /c attrib -s -r c:\boot.ini" ),,True

set BootINI = fso.openTextFile("c:\boot.ini",1,true)
set BootINInew = fso.openTextFile("c:\boot.ini.new",2,true)

do while not BootINI.atEndOfStream
	bootline = BootINI.readLine
	test = InStr(bootline,"timeout")
	if test > 0 then 
		BootINInew.writeline("timeout=1")
		else
		BootINInew.writeline(bootline)
	end if
loop

BootINI.close
BootINInew.close

wshshell.run("cmd /c copy c:\boot.ini.new c:\boot.ini & attrib +s +r c:\boot.ini & del c:\boot.ini.new" ),,True

-SWarrior
 
match is set only for half the lines as you read str twice ...

I don't understand. Can you please explain a bit more?
 
Have you tried my suggested code with only ONE str.ReadLine and NO str.SkipLine ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I just tried it. That does not do the trick. I've simpified the block of code to understand how to do what I want to do..

Code:
status=0
set fso = CreateObject("Scripting.FileSystemObject")
set stream = fso.OpenTextFile("C:\savinst.log")
do while not stream.AtEndofStream
	match=stream.ReadLine
	Wscript.Echo match
loop

 
I forgot to mention. When it echo's back the strings, the first string is a strange character. The others are all blank lines.
 
And this ?
status=0
set fso = CreateObject("Scripting.FileSystemObject")
set stream = fso_OpenTextFile("C:\savinst.log", 1)
do while not stream.AtEndofStream
match=stream.ReadLine
If InStr(1, match, "completed successfully", 1) > 0 Then
Wscript.Echo match
status = 1
Exit Do
End If
loop

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
the first string is a strange character. The others are all blank lines
Ah, UniCode ...
In my previous post, replace this:
set stream = fso_OpenTextFile("C:\savinst.log", 1)
By this:
set stream = fso_OpenTextFile("C:\savinst.log", 1, True)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
still not working. Here is the string that I know exists in the log file.

MSI (s) (80:88): Product: Symantec AntiVirus -- Installation operation completed successfully.
 
still not working
Even with the True parameter in the OpenTextFile method call ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
yes. even with the change..

status=0
set fso = CreateObject("Scripting.FileSystemObject")
set stream = fso_OpenTextFile("C:\savinst.log", 1, True)
do while not stream.AtEndofStream
match=stream.ReadLine
If InStr(1, match, "completed successfully", 1) > 0 Then
status = 1
Exit Do
End If
loop
Wscript.Echo status
 
OOps, my bad.
set stream = fso_OpenTextFile("C:\savinst.log", 1,[highlight] ,[/highlight] True)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top