' ***********************************************************
' Create Date:	    1/12/2009
' Created By:		Levon Kemkemian
' Version:			1.2
' Purpose:          Automated system audit
' Updated v1.1: Adobe search for speed/ updated office search, now iwll detect mulitple versions.
' Updated v1.2: Added the option not to send the email at the end
' Updated v1.3: Added resolves ms office build number to year and service pack, word startup path, temp dir path
' Updated v1.4: Added Office 2010 Detection (23/08/2010)
' ***********************************************************


' ------ SCRIPT CONFIGURATION ------
strComputer = "."   
' ------ END CONFIGURATION ---------
 

'------------------- sub to send email ------------------

Sub SendMailOutlook(aTo, Subject, TextBody, aFrom)
  
  'Create an Outlook object
  Dim Outlook 'As New Outlook.Application
  Set Outlook = CreateObject("Outlook.Application")
  
  'Create e new message
  Dim Message 'As Outlook.MailItem
  Set Message = Outlook.CreateItem(olMailItem)
  With Message
    'You can display the message To debug And see state
    '.Display
    
    .Subject = Subject
    .Body = TextBody
    
    'Set destination email address
    .Recipients.Add (aTo)
    
    'Set sender address If specified.
    Const olOriginator = 0
    If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator
    
    'Send the message
    .Send
  End With
End Sub


'Alert the user to let them know we have started.

'wscript.echo "The system audit is about to start . . . . Please click ok to continue."
MsgBox "The system audit is about to start . . . . Please click ok to continue." 



Dim message
Dim servername
servername = "Localhost"

set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
Set colItems = objWMI.ExecQuery("Select * from Win32_Processor")
for each objOS in colOS


   message = "Computer Name: " & objOS.CSName & vbCrLf
   message = message & "Operating System: " & objOS.Caption & vbCrLf
   message = message & "Total Memory (RAM): " & _ 
                round(objOS.TotalVisibleMemorySize / 1024) & " MB" & vbCrLf
  ' message = message & "System Manufacturer: " & objoS.Manufacturer & vbCrLf

next

On Error Resume Next

For Each objItem in colItems

    message = message & "Name of Processor: " & objItem.Name & vbCrLf
    message = message & "Processor Speed: " & objItem.MaxClockSpeed & " Mhz" & vbCrLf

next

On Error Resume Next

set colCSs = objWMI.InstancesOf("Win32_ComputerSystem")
for each objCS in colCSs
	message = message & "Brand: " & objcS.Manufacturer & vbCrLf
	message = message & "Model: " & objcS.Model & vbCrLf & vbCrLf
next


			message = message & "Hard Drive Information:" & vbCrLf 
			'message = message & "=======================" & vbCrLf 
			For Each objHDInfo In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_DiskDrive")
				'message = message & " Hard Drive Model: " & objHDInfo.Model & vbCrLf
				'message = message & " Hard Drive Size: " & clng(objHDInfo.Size/1024/1024/1024) & " GB" & vbCrLf
				'message = message & " # of Partitions: " & objHDInfo.Partitions & vbCrLf
				message = message & " Hard Drive Type: " & objHDInfo.InterfaceType & vbCrLf
				'wscript.echo ""
			Next
			'wscript.echo ""
			set objHDinfo = nothing
					
			For Each objDisk In GetObject("winmgmts:{impersonationLevel=impersonate}\\" & servername & "\root\cimv2").InstancesOf("Win32_LogicalDisk Where DriveType = '3'")
				freespace = left(objDisk.freespace/1024/1024/1024,4)
				totalspace = left(objDisk.size/1024/1024/1024,4)
				usedspace = left(totalspace/freespace,4)
				freeperct = left(100/usedspace,2)
				message = message & vbCrLf & " Drive: " & objDisk.deviceid & vbCrLf
				'message = message & " Used Space: " & usedspace & " GB" & vbCrLf
				message = message & " Free Space: " & freespace & " GB" & vbCrLf
				message = message & " Total Space: " & totalspace & " GB" & vbCrLf
				'message = message & " Free: " & freeperct & "%" & vbCrLf
				'wscript.echo ""
			next
			set objDisk = nothing

'------------------------ .net framework -----------------------------

set shell = WScript.CreateObject("WScript.Shell")
sysRoot = shell.ExpandEnvironmentStrings("%systemroot%")
' sysRoot = shell.ExpandEnvironmentStrings("%windir%")

path = sysRoot + "\Microsoft.NET\Framework"
dim X86path

x86path = "c:/Program Files (x86)"

set fs = CreateObject("Scripting.FileSystemObject")

GotDotNet2 = False
GotDotNet = False
GotDotNet35 = False
GotDotNet3 = False
programx86 = False

On Error Resume Next

set folder = fs.GetFolder(path)

If Err = 0 Then
Set re = new regexp

re.Pattern = "^v2"

For each item in folder.SubFolders

If re.Test(item.Name) Then
GotDotNet2 = True
' Msgbox item.Name
End If
Next
End If

If Err = 0 Then
Set re = new regexp

re.Pattern = "^v1.1.4322"

For each item in folder.SubFolders

If re.Test(item.Name) Then
GotDotNet = True
' Msgbox item.Name
End If
Next
End If

If Err = 0 Then
Set re = new regexp

re.Pattern = "^v3.0"

For each item in folder.SubFolders

If re.Test(item.Name) Then
GotDotNet3 = True
' Msgbox item.Name
End If
Next
End If


If Err = 0 Then
Set re = new regexp

re.Pattern = "^v3.5"

For each item in folder.SubFolders

If re.Test(item.Name) Then
GotDotNet35 = True
' Msgbox item.Name
End If
Next
End If

'Msgbox GotDotNet2

message = message & vbCrLf

if GotDotNet then
message = message & "Microsoft .NET 1.1.4322 Installed" & vbCrLf
end if

if GotDotNet2 then
message = message & "Microsoft .NET 2.0 Installed" & vbCrLf
end if

if GotDotNet3 then
message = message & "Microsoft .NET 3.0 Installed" & vbCrLf
end if

if GotdotNet35 then
message = message & "Microsoft .NET 3.5 Installed" & vbCrLf
end if


' ---------------------- Is 64bit attempt --------------------
set folder = fs.GetFolder(x86path)

If Err = 0 Then
Set re = new regexp

re.Pattern = "Common Files"

For each item in folder.SubFolders

If re.Test(item.Name) Then
programx86 = True
' Msgbox item.Name
End If
Next
End If

if programx86 then
message = vbCrLf & message & vbCrLf & "A 64 Bit Version of Windows has been Detected" & vbCrLf 
end if
'message =  message & vbCrLf & "A 64 Bit Version of Windows has been Detected" & vbCrLf 

Dim officepath
Dim fso
Dim returnstring
Dim findexe

returnstring = ""

message = message & vbCrLf & "Office Versions" & vbCrLf

Set objFSO = CreateObject("Scripting.FileSystemObject")



'-------------------- MS Word 2010 ---------------------------------

returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office14\WINWORD.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE14\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "winword.exe")
'wscript.echo "Word version " & returnstring & " detected"
message = message & "Word 2010 Version:" & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- MS Outlook 2010 ----------------------------------

returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office14\OUTLOOK.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE14\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "outlook.exe")
message = message & "Outlook 2010 Version:" & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- MS Excel 2010 ------------------------------------

returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office14\EXCEL.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE14\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "EXCEL.exe")
message = message & "Excel 2010 Version:" & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- Detect MS 2007 word if path exists --------------------
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office12\WINWORD.EXE") then
officepath = "C:\Program Files\Microsoft Office\Office12\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "winword.exe")

message = message & "Word Version "

if (strcomp(returnstring, "12.0.4518.1014"))=0 then
message = message & "2007 No Service Pack " 
end if

if (strcomp(returnstring, "12.0.6211.1000"))=0 then
message = message & "2007 SP1 " 
end if

if (strcomp(returnstring, "12.0.6425.1000"))=0 then
message = message & "2007 SP2 " 
end if

 message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- Detect MS 2007 outlook if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE") then
officepath = "C:\Program Files\Microsoft Office\Office12\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "OUTLOOK.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"

message = message & "Outlook Version "

if (strcomp(returnstring, "12.0.4518.1014"))=0 then
message = message & "2007 No Service Pack " 
end if

if (strcomp(returnstring, "12.0.6212.1000"))=0 then
message = message & "2007 SP1 " 
end if

if (strcomp(returnstring, "12.0.6423.1000"))=0 then

message = message & "2007 SP2 " 
end if

 message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- Detect MS 2007 Excel if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\Office12\EXCEL.EXE") then
officepath = "C:\Program Files\Microsoft Office\Office12\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "EXCEL.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"

message = message & "Excel Version "

if (strcomp(returnstring, "12.0.4518.1014"))=0 then
message = message & "2007 No Service Pack " 
end if

if (strcomp(returnstring, "12.0.6214.1000"))=0 then
message = message & "2007 SP1 " 
end if

if (strcomp(returnstring, "12.0.6425.1000"))=0 then
message = message & "2007 SP2 " 
end if

message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- Detect MS 2003 word if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE11\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "winword.exe")
'wscript.echo "Word version " & returnstring & " detected"

message = message & "Word Version "

if (strcomp(returnstring, "11.0.5604.0"))=0 then
message = message & "2003 No Service Pack " 
end if

if (strcomp(returnstring, "11.0.6359.0"))=0 then
message = message & "2003 SP1 "
end if

if (strcomp(returnstring, "11.0.7969.0"))=0 then
message = message & "2003 SP2 "
end if

if (strcomp(returnstring, "11.0.8173.0"))=0 then
message = message & "2003 SP3 " 
end if

 message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2003 outlook if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE11\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "OUTLOOK.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"

message = message & "Outlook Version "

if (strcomp(returnstring, "11.0.5510.0"))=0 then
message = message & "2003 No Service Pack " 
end if

if (strcomp(returnstring, "11.0.6353.0"))=0 then
message = message & "2003 SP1 " 
end if

if (strcomp(returnstring, "11.0.7969.0"))=0 then
message = message & "2003 SP2 " 
end if

if (strcomp(returnstring, "11.0.8173.0"))=0 then
message = message & "2003 SP3 " 
end if

message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2003 Excel if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE11\EXCEL.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE11\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "EXCEL.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"

message = message & "Excel Version "

if (strcmp(returnstring, "11.0.5612.0"))=0 then
message = message & "2003 No Service Pack "
end if

if (strcmp(returnstring, "11.0.6355.0"))=0 then
message = message & "2003 SP1 " 
end if

if (strcmp(returnstring, "11.0.7969.0"))=0 then
message = message & "2003 SP2 "
end if

if (strcmp(returnstring, "11.0.8173.0"))=0 then
message = message & "2003 SP3 " 
end if

 message = message & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF



'------------------- Detect MS 2002 word if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE10\WINWORD.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE10\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "winword.exe")
'wscript.echo "Word version " & returnstring & " detected"
message = message & "Word Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2002 outlook if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE10\OUTLOOK.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE10\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "OUTLOOK.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"
message = message & "Outlook Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2002 Excel if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE10\EXCEL.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE10\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "EXCEL.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"
message = message & "Excel Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2000/1997 word if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE\WINWORD.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "winword.exe")
'wscript.echo "Word version " & returnstring & " detected"
message = message & "Word Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2000/1997 outlook if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE\OUTLOOK.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "OUTLOOK.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"
message = message & "Outlook Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS 2000/1997 Excel if path exists --------------------
returnstring = ""
If objFSO.FileExists("C:\Program Files\Microsoft Office\OFFICE\EXCEL.exe") then
officepath = "C:\Program Files\Microsoft Office\OFFICE\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "EXCEL.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"
message = message & "Excel Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF


'------------------- Detect MS word startup path --------------------

Set objWord = CreateObject("Word.Application")
message = message & vbCrLf &  "Word Startup Path: " & objWord.StartupPath & vbCrLf


'------------------- Detect adobe reader version --------------------
'Dim AdobeReaderName, AdobeReaderVersion  
  
'Dim objWMI, colSoftware, objSoftware  
  
'AdobeReaderName = ""  
'AdobeReaderVersion = "0"  

'Set objWMI = GetObject("winmgmts:root\cimv2")    
'Set colSoftware = objWMI.ExecQuery("SELECT * FROM Win32_Product")  
  
'For Each objSoftware In colSoftware  
'If InStr(UCase(objSoftware.Name), "ADOBE READER") >= 1 Then  
'AdobeReaderName = objSoftware.Name  
'AdobeReaderVersion = objSoftware.Version  
'End If  
'Next  

'message = message & vbCrLf & "Adobe Version" & vbCrLf
  
'If AdobeReaderVersion >= "6" Then  
'message = message & AdobeReaderName & " is installed." & vbCrLf
'Else  
'message = message & "Adobe Reader 6 or later is NOT installed." & vbCrLf
'End If  

'--------------- faster Method for detecting adobe version --------------

On Error Resume Next 

ShowFolderList("C:\Program Files\Adobe\") 

'wscript.echo "starting . . ."

Function ShowFolderList(folderspec) 
Dim fso, f, f1, s, sf 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set f = fso.GetFolder(folderspec) 
Set sf = f.SubFolders 
For Each f1 in sf 
ShowFolderList(f1.path) 
ShowFileList(f1.path) 
Next 
End Function 

returnstring = ""

Function ShowFileList(folderspec) 
Dim fso, f, f1, fc, s 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set f = fso.GetFolder(folderspec) 
Set fc = f.Files 
For Each f1 in fc 
if strcomp(f1.name,"AcroRd32.exe") = 0 then 
'wscript.echo "version true"
'wscript.echo f1.path
message = message & vbCrLf & "Adobe Version" & vbCrLf
returnstring = fso.getfileversion (f1.path)
message = message & "Adobe Reader Version " & returnstring & " Detected" & vbCrLf
Exit For 
Exit Function 
end if 
Next 
End Function 





'------------------- Detect Internet Explorer version --------------------

returnstring = ""
If objFSO.FileExists("C:\Program Files\Internet Explorer\iexplore.exe") then
officepath = "C:\Program Files\Internet Explorer\"
set fso = createobject("scripting.filesystemobject")
returnstring = fso.getfileversion(officepath & "IEXPLORE.EXE")
'wscript.echo "Outlook version " & returnstring & " detected"
message = message & vbCrLf & "Internet Explorer Version " & returnstring & " Detected" & vbCrLf
set fso = nothing
END IF

'------------------- Detect temp directory path --------------------

message = message & vbCrLf & "%TEMP% DIR path: " & CreateObject("WScript.Shell").ExpandEnvironmentStrings("%Temp%") & vbCrLf


'------------------------ Detect if Myob installed  ---------------------------
'returnstring = ""
'If objFSO.FileExists("C:\Program Files\Internet Explorer\iexplore.exe") then
'officepath = "C:\Program Files\Internet Explorer\"
'set fso = createobject("scripting.filesystemobject")
'returnstring = fso.getfileversion(officepath & "IEXPLORE.EXE")
''wscript.echo "Outlook version " & returnstring & " detected"
'message = message & vbCrLf & "Internet Explorer Version " & returnstring & " Detected" & vbCrLf
'set fso = nothing
'END IF



'---------------------- Send Email --------------------------------

'wScript.Echo message

'alert user, what information is being sent
MsgBox "The following information will be sent via email: " & vbCrLf & vbCrLf & message

Dim sendemail
sendemail = MsgBox("Would you like to send the email now ?",4,"LEAP")

'wscript.echo sendemail

if sendemail = 6 then

Dim bTo
Dim bSubject
Dim bFrom
Dim cSubject

bSubject = ""
cSubject = "" 
bTo = "techhelp@leap.com.au"

bSubject = InputBox("Please enter your Firm Name")
do while bSubject = "" 
bSubject = InputBox("Please enter your Firm Name")
loop

do while cSubject = "" 
cSubject = Inputbox("Is this a Workstation or The Server")
loop

bSubject = bSubject & " - " & cSubject
bSubject = "Automated Client Audit Sheet: " & bSubject
'bFrom = "levon.kemkemian@leap.com.au"

SendMailOutlook bTo, bSubject, message, bFrom

'wscript.echo "Message sent"
MsgBox "Message sent","LEAP"

end if 