' (c) Microsoft Corporation 1997-2003
'
'
' File Name:	MBSAScan.wsf
' Version:	1.0
'
'本指令碼針對 MBSACLI.EXE 工具提供一個簡易的包裝函式，以便更輕易地產生報告。
'本指令碼會針對 MBSACLI.EXE 編寫一些命令列選項程式碼，並將這些額外的命令列參數
'傳送到 MBSACLI.EXE。
'本指令碼中編寫的 -HF 命令列參數，表示本指令碼將只支援 HFNetChk 模式的 MBSACLI.EXE 
'所支援的命令列參數。
'若無提供其他命令列參數，MBSACLI.EXE 將僅在本機用戶端上執行。
'This script provides a simple wrapper to the MBSACLI.EXE tool to make generating reports easier.
'The script hard codes some command line options for MBSACLI.EXE, and also passes additionally provided
'command line arguments to MBSACLI.EXE.
'The script has the -HF command line argument hard coded, which means the script will only support those
'command line arguments supported by MBSACLI.EXE in HFNetChk mode.
'If no additional command line arguments are provided MBSACLI.EXE will be run against the local client.
'
'
'
' Release History
' 0001	-	Original	June 30, 2003

<?xml version="1.0" ?>
<package>
	<comment>
	Primalscript wizard generated file.
	</comment>
	<job id="Job1">
		<script id="mbsascan" language="VBScript">
<![CDATA[

Option Explicit
On Error goto 0

'if MBSA is installed in a location other than the default location, this constant will need to be changed
Const C_MBSA_PATH = "c:\program files\microsoft baseline security analyzer\mbsacli.exe"

Sub Scan
	Dim i					'used in loop when processing arguments
	Dim sOutputFile			'name of the output file
	Dim dtNow				'used in creation of output file name
	Dim sTimeStamp			'used in creation of output file name
	Dim sCommand			'exact command line called when executing MBSACLI.EXE
	Dim objShell			'used to execute command line specified by sCommand

	'first need to generate an output file name in the format of YYYYMMDD_HHMMSS.txt
	dtNow = Now()
	sTimeStamp = DatePart("yyyy",dtNow) &  Right("00" & DatePart("m",dtNow),2)
	sTimeStamp = sTimeStamp & Right("00" & DatePart("d",dtNow),2) & "_" & _
		Right("00" & DatePart("h",dtNow),2) & Right("00" & DatePart("n",dtNow),2) & _
		Right("00" & DatePart("s",dtNow),2)

	'full path of output file is determined by current location of this script
	'also put quotes around output file name to account for embedded spaces
	sOutputFile = Chr(34) & Left(WScript.ScriptFullName,InStrRev(WScript.ScriptFullName,"\")) & sTimeStamp & ".txt" & Chr(34)

	'base command line called will generate a tab separated file with the correct name
	sCommand = Chr(34) & C_MBSA_PATH & Chr(34) & " -hf -o tab -f " & sOutputFile

	'any arguments supplied to this script are passed to MBSACLI.EXE
	For I = 0 to objArgs.Count - 1
		'need to put quotes around any arguments that have an embeded space. These quotes are stripped out by the 
		'script engine when reading the arguments in.
	   If InStr(objArgs(I)," ") Then
		   sCommand = sCommand & " " & Chr(34) & objArgs(I) & Chr(34)
	   Else
		   sCommand = sCommand & " " & objArgs(I)
	   End If
	Next

	'echo the command line used out to the console to show user what is being called
	Wscript.Echo "Command line executed -> " & sCommand
	
	'use the WSH Shell object to run MBSACLI.EXE with appropriate options
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run(sCommand)

	WScript.Echo "Done"
End Sub

Sub Usage
	WScript.Echo
	WScript.Echo "This script will call MBSACLI.EXE with the following arguments:"
	WScript.Echo "  -hf         -> places MBSACLI.EXE in HFNetChk mode"
	WScript.Echo "  -o tab      -> output of the scan is formated into a tab delimited text file" 
	WScript.Echo "  -f filename -> output file name is auto generated based on timestamp when run"
	WScript.Echo
	WScript.Echo "This script will pass any addition command line arguments to MBSACLI.EXE"
	WScript.Echo "Run MBSACLI.EXE -HF -? for a complete list of scanning options"
	WScript.Echo
End Sub

'Script Starts Here
Dim objArgs				'used to retrieve command line arguments passed to this script 
Set objArgs = WScript.Arguments

'check to see if only one command line arg is passed, and if so display usage for this script if needed
'no arguments indicates a local scan on the computer running the script
If objArgs.Count Then
	If InStr(objArgs(0),"?") Then
		Call Usage
	Else
		Call Scan
	End If
Else
	Call Scan
End if
]]>
		</script>
	</job>
</package>
