Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag 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

SOLUTION
Avatar of Sinistra_D32
Sinistra_D32

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Sinistra_D32
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.
Avatar of bsharath

ASKER

Thanks

I want to install if the 3 criterias ore not met...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial