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.
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
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.
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.