Dim oSQL,oSEC, AuthMode
on Error Resume Next
Set authArgs = WScript.Arguments
If authArgs.Count <> 1 Then
        WScript.Echo " This file must be run from a command prompt!" & vbcrlf & vbcrlf & " Parameter Options: 1) status   2) mixed   3) nt" & vbcrlf & vbcrlf & " Example: SQLMode status"
        WScript.Quit(1)
End If

'Extract command line parameters into variables
AuthMode = authArgs(0)
Set oSQL = CreateObject("SQLDMO.SQLServer")

oSQL.Name = "127.0.0.1\MAILMAX5"
oSQL.LoginSecure = True
oSQL.LoginTimeout = 30

err.Clear
oSQl.Connect

if err then
	WScript.Echo "Failed to connect to the MailMax5 database."
else
	Set oSEC = oSQL.IntegratedSecurity

	if ( UCase( AuthMode ) = "STATUS" ) then

		if ( oSEC.SecurityMode = 1 ) then

			WScript.Echo " Current Authentication Status: NT Authentication Mode"
			
		elseif ( oSEC.SecurityMode = 2 ) then
			WScript.Echo " Current Authentication Status: Mixed Mode Authentication"
			
		end if
		
	elseif ( UCase ( AuthMode ) = "MIXED" ) then
		if ( oSEC.SecurityMode = 1 ) then

			'Set security mode to mixed
			oSEC.SecurityMode = 2
			WScript.Echo " Successfully changed to Mixed Mode Authentication Mode (Previously set to NT Authentication Mode)" & vbcrlf & vbcrlf & "           ** You must restart the MSSQL$MAILMAX5 service for this change to take affect** "
		elseif ( oSEC.SecurityMode = 2 ) then
			WScript.Echo " Your authentication mode is already set to Mixed Mode"
		end if
	elseif ( UCase ( AuthMode ) = "NT" ) then
		if ( oSEC.SecurityMode = 1 ) then
				WScript.Echo " Your authentication mode is already set to NT Authentication mode"
		elseif ( oSEC.SecurityMode = 2 ) then
			'Set security mode to mixed
			oSEC.SecurityMode = 1
			WScript.Echo " Successfully changed to NT Authentication Mode (Previously set to Mixed Mode Authentication)" & vbcrlf & vbcrlf & "         ** You must restart the MSSQL$MAILMAX5 service for this change to take affect **"
		end if
	else
		WScript.Echo " Invalid Parameter Entered" & vbcrlf & vbcrlf & " Parameter Options: 1) status   2) mixed   3) nt" & vbcrlf & vbcrlf & " Example: SQLMode status"
	end if
	
	oSQL.DisConnect
	Set oSEC =nothing
end if
'Clean up
Set oSQL =nothing

