Avatar of bsharath
bsharath
Flag for India asked on

Install script. I want it to run only if 3 conditions are correct.

hi,

Install script. I want it to run only if 3 conditions are correct.
At present as it checks for a file if not available it installs. I want 2 more files or folders to be checked. If not there only then install

C:\Program files\Sophos
C:\Program files\123
Only if the abive 2 and the one file check in the below code is not there then install. Else do nothing

Can anyone help with this

Regards
Sharath

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
 
Const intForAppending = 8

'Log path
 
strLogFile = "\\indsm\Logs\AVInstallation.log"
 
'If we are using as a startup script then change the "Alsvc.e1xe" to "Alsvc.exe"
'it checks for the path if not available reinstall's the Sophos or install if not already there

If objFSO.FileExists ("C:\Program Files\Sophos\AutoUpdate\ALsv1c.exe") then
	strResults =  Now & " - " & objNetwork.ComputerName & ": Already installed."
Else
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
	Set colSystemInfo = objWMIService.ExecQuery _
	    ("Select Caption from Win32_OperatingSystem",,48)
	For Each objItem In colSystemInfo
		strOS_Caption = objItem.Caption
	Next
	 
	If InStr(strOS_Caption, "Windows NT") = 0 Then
'Need to change the Sid path as per version. Silently uninstall the old ver and do not restart
		objShell.Run ("MsiExec.exe /X {034759DA-E21A-4795-BFB3-C66D17FAD183} /QN /NORESTART"), 1, True
'Install from the below path
'Username and password mentioned
	objShell.Run("\\IND\SophosUpdate\CIDs\S000\SAVSCFXP\Setup.exe -s " & _
			"-updp ""\\IND\SophosUpdate\CIDs\S000\SAVSCFXP"" " & _
			"-user ""emr2"" " & _
			"-pwd ""ab23"" " & _
			"-mng yes"),1,True
		strResults = Now & " - " & objNetwork.ComputerName & ": Installed version for all other OS's"
	Else
		objShell.Run("\\IND\SophosUpdate\CIDs\S000\ESNT\Setup.exe -s"), 1, True
		strResults = Now & " - " & objNetwork.ComputerName & ": Installed Windows NT version"
	End If
End If
 
Set objLogFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
objLogFile.WriteLine strResults
objLogFile.Close

Open in new window

Programming Languages-OtherScripting LanguagesVB Script

Avatar of undefined
Last Comment
kemot1000

8/22/2022 - Mon
SOLUTION
Sinistra_D32

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
markdmac

Sinistra, Maybe I am misunderstanding but I believe your code will execute if any of those folders exist.  If the desire is to only execute when all folders are present you would need to replace OR with AND.
If object.FolderExists("C:\Program files\Sophos") And object.FolderExists("C:\Program files\123") And objFSO.FileExists ("C:\Program Files\Sophos\AutoUpdate\ALsv1c.exe") Then 
        'All three conditions met
Else 
		'Conditions not met, take corrective action
End If

Open in new window

Sinistra_D32

Only if the abive 2 AND the one file check in the below code is not there then install

So none of them should exist to install. Or the problem is not built correctly.
bsharath

ASKER
Thanks

I want to install if the 3 criterias ore not met...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
markdmac

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
markdmac

kemot1000

try this. Not to pretty but will work for sure
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
 
Const intForAppending = 8

'Log path
 count = 0
If objFSO.FolderExists(C:\Program files\Sophos) Then 
count = count +1 
End If 

If objFSO.FolderExists(C:\Program files\123) Then 
count = count +1 
End If 



strLogFile = "\\indsm\Logs\AVInstallation.log"
 
'If we are using as a startup script then change the "Alsvc.e1xe" to "Alsvc.exe"
'it checks for the path if not available reinstall's the Sophos or install if not already there

If objFSO.FileExists ("C:\Program Files\Sophos\AutoUpdate\ALsv1c.exe") then

        count = count + 1 
Else
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
        Set colSystemInfo = objWMIService.ExecQuery _
            ("Select Caption from Win32_OperatingSystem",,48)
        For Each objItem In colSystemInfo
                strOS_Caption = objItem.Caption
        Next
       
       
       If count = 3 Then 
       
			        If InStr(strOS_Caption, "Windows NT") = 0 Then
			'Need to change the Sid path as per version. Silently uninstall the old ver and do not restart
			                objShell.Run ("MsiExec.exe /X {034759DA-E21A-4795-BFB3-C66D17FAD183} /QN /NORESTART"), 1, True
			'Install from the below path
			'Username and password mentioned
			        objShell.Run("\\IND\SophosUpdate\CIDs\S000\SAVSCFXP\Setup.exe -s " & _
			                        "-updp ""\\IND\SophosUpdate\CIDs\S000\SAVSCFXP"" " & _
			                        "-user ""emr2"" " & _
			                        "-pwd ""ab23"" " & _
			                        "-mng yes"),1,True
			                strResults = Now & " - " & objNetwork.ComputerName & ": Installed version for all other OS's"
			        Else	
			
			                objShell.Run("\\IND\SophosUpdate\CIDs\S000\ESNT\Setup.exe -s"), 1, True
			                strResults = Now & " - " & objNetwork.ComputerName & ": Installed Windows NT version"
			        End If
        
        Else 
        
        			        strResults =  Now & " - " & objNetwork.ComputerName & ": Already installed."
        
        End If 
        
End If
 
Set objLogFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
objLogFile.WriteLine strResults
objLogFile.Close

Open in new window

kemot1000

Forgot quotes:

If objFSO.FolderExists("C:\Program files\Sophos") Then
count = count +1
End If

If objFSO.FolderExists("C:\Program files\123") Then
count = count +1
End If
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
kemot1000

corrected it because I added Eaquals to (=)  insted of NOT Equal to (<>)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
 
Const intForAppending = 8

'Log path

count = 0
If objFSO.FolderExists("C:\Program files\Sophos") Then 
count = count +1 
End If 

If objFSO.FolderExists("C:\Program files\123") Then 
count = count +1 
End If 



strLogFile = "\\indsm\Logs\AVInstallation.log"
 
'If we are using as a startup script then change the "Alsvc.e1xe" to "Alsvc.exe"
'it checks for the path if not available reinstall's the Sophos or install if not already there

If objFSO.FileExists ("C:\Program Files\Sophos\AutoUpdate\ALsv1c.exe") then

        count = count + 1 
Else
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
        Set colSystemInfo = objWMIService.ExecQuery _
            ("Select Caption from Win32_OperatingSystem",,48)
        For Each objItem In colSystemInfo
                strOS_Caption = objItem.Caption
        Next
       
       
       If count <> 3 Then 
       
                                If InStr(strOS_Caption, "Windows NT") = 0 Then
                        'Need to change the Sid path as per version. Silently uninstall the old ver and do not restart
                                        objShell.Run ("MsiExec.exe /X {034759DA-E21A-4795-BFB3-C66D17FAD183} /QN /NORESTART"), 1, True
                        'Install from the below path
                        'Username and password mentioned
                                objShell.Run("\\IND\SophosUpdate\CIDs\S000\SAVSCFXP\Setup.exe -s " & _
                                                "-updp ""\\IND\SophosUpdate\CIDs\S000\SAVSCFXP"" " & _
                                                "-user ""emr2"" " & _
                                                "-pwd ""ab23"" " & _
                                                "-mng yes"),1,True
                                        strResults = Now & " - " & objNetwork.ComputerName & ": Installed version for all other OS's"
                                Else    
                        
                                        objShell.Run("\\IND\SophosUpdate\CIDs\S000\ESNT\Setup.exe -s"), 1, True
                                        strResults = Now & " - " & objNetwork.ComputerName & ": Installed Windows NT version"
                                End If
        
        Else 
        
                                        strResults =  Now & " - " & objNetwork.ComputerName & ": Already installed."
        
        End If 
        
End If
 
Set objLogFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
objLogFile.WriteLine strResults
objLogFile.Close

Open in new window

ASKER CERTIFIED SOLUTION
kemot1000

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.