Category Archives: Scripts

Exchange 2003 information

Another interesting script to get information exchange 2003 mailboxes, useful in audits, reports, etc …

'==========================================================================
' NAME   : Exchange Mailbox Stats Dumper
' AUTHOR : Brian Desmond' DATE   : 12/28/2005
' COMMENT: This script requires Exchange 2003. It will dump information
'   about each mailbox on the mailbox servers specified
'
' Version  Date  Author   Note
' -----------------------------------------------------------------
' 1.0   28Nov05  Brian Desmond Initial Version
' 1.1   03Sep06  Brian Desmond 
' 1.2   13Dec08  Brian Desmond Fixed array sizing bug,
'           Added error handling note
'           Added TODOs
'           Moved configurable items up
'==========================================================================
Option Explicit
' Note this script currently uses On Error Resume Next
' this isn't best practice - in reality this should be tightly 
' wrapped around the WMI connection logic in the loop rather
' than up here.
On Error Resume Next
' TODO: Configure this
' This is the total number of servers which you
' will specify for inventory
Const TOTAL_SERVERS = 1
Dim strComputer()
ReDim strComputer(TOTAL_SERVERS)
' TODO: Populate this array
' Enter each server name below as an entry in the array
' starting with zero
strComputer(0) = "xxb01"
strComputer(1) = "xmb02"
strComputer(2) = "xmb03"
'==========================================================================
Dim objWMIService
Dim colItems
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fil
Set fil = fso.CreateTextFile("mailboxes.txt")
Dim objItem
Dim line
Dim i
' Write a header row to the CSV
fil.WriteLine """Server"",""Storage Group"",""Mail Store"",""Mailbox GUID"",""Display Name"",""LegacyDN"",""Size"",""Item Count"",""Associated Content Count"",""Deleted Message Size"",""Date Absent"",""Storage Limit Level"""
For i = 0 To TOTAL_SERVERS - 1
 Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer(i) & _
         "\ROOT\MicrosoftExchangeV2")
  
 Set colItems = objWMIService.ExecQuery _
     ("Select * from Exchange_Mailbox")
  
 For Each objItem in colItems
  line = """" & objItem.ServerName & """"
  line = line & ","
  line = line & """" & objItem.StorageGroupName & """"
  line = line & ","
  line = line & """" & objItem.StoreName & """"
  line = line & ","
  line = line & """" & objItem.MailboxGUID & """"
  line = line & ","
  line = line & """" & objItem.MailboxDisplayName & """"   
  line = line & ","
  line = line & """" & objItem.LegacyDN & """"
  line = line & ","
  line = line & """" & objItem.Size & """"
  line = line & ","
  line = line & """" & objItem.TotalItems & """"
  line = line & ","
     line = line & """" & objItem.AssocContentCount & """"
     line = line & ","
     line = line & """" & objItem.DeletedMessageSizeExtended & """"
     line = line & ","
     line = line & """" & objItem.DateDiscoveredAbsentInDS & """"
     line = line & ","
     line = line & """" & objItem.StorageLimitInfo & """"
      
     fil.WriteLine line 
     'WScript.Echo line 
 Next
Next
fil.Close
Set fso = Nothing
Set objWMIService = Nothing
Facebooktwitterredditpinterestlinkedinmail

Read More ...

PHP authentication system

Here’s an example of controlling access to private pages through php, a class Authorization :

    ////////////////////////////////////////////////////////////////////    
    //Authorization class to maintain security of access to admin tool    
    class Authorization    
    {    
		public function grant()    
		{    
			$_SESSION['auth'] = true;    
			unset($_SESSION['locked']);    
			unset($_SESSION['tries']);    
		}    
		public function revoke()    
		{    
			unset($_SESSION['auth']);    
		}    
		public function fail()    
		{    
			if(!isset($_SESSION['tries']))    
				$_SESSION['tries'] = 1;    
			else    
				$_SESSION['tries']++;    
				
			if($_SESSION['tries'] >= 6)    
				$_SESSION['locked'] = true;    
		}    
		public function isAuthorized()    
		{    
			return isset($_SESSION['auth']);    
		}    
		public function isLocked()    
		{    
			return isset($_SESSION['locked']);    
		}    
		public function getAttempts()    
		{    
				if(isset($_SESSION['tries']))    
					return $_SESSION['tries'];    
				else    
					return 0;    
		}    
    }
	

then at the main code of the webpage, we can put the max attemps and block the connection if you do more than this.

    session_start();    
    $maxAttempts = 3; //maximum number of password attempts    
    $password="xxx"    
         
    $auth = new Authorization(); //create authorization object    
         
    if(isset($_POST['logout'])) //user has attempted to log out    
    {    
		$auth->revoke();    
    }    
    else if(isset($_POST['login'])) //user has attempted to log in    
    {    
		if($_POST['password']==$password)    
			$auth->grant();    
		else    
			$auth->fail();    
    }    
         
    if(!$auth->isAuthorized())    
    {    
		echo "<div id='loginBox'>";    
		echo "<h1>SQLite3Admin</h1>";    
		echo "<h2>".$DBFilename."</h2>";    
		if($auth->isLocked())    
		{    
			echo "Unfortunately, you have entered an incorrect password too many times. You <span style="white-space: pre;"> </span>are locked out. Sorry.";    
		}    
		else    
		{    
			$lock = $auth-&gt;getAttempts();    
			if($lock&gt;0)    
			echo $lock." attempts out of ".$maxAttempts.".&lt;br/&gt;&lt;br/&gt;";    
			echo "&lt;form action='".$thisName."' method='post'&gt;";    
			echo "Password: &lt;input type='password' name='password'/&gt;";    
			echo "&lt;input type='submit' value='Log In' name='login'/&gt;";    
			echo "&lt;/form&gt;";    
		}    
		echo "&lt;/div&gt;";    
    }    
    
Facebooktwitterredditpinterestlinkedinmail

Read More ...

Install printers

Many times we have the perennial problem in Active Directory environments that occasionally a user session on a machine that is not his usual, this causes without designated network printers to install printers, you can use this script:
one file instalar.bat that installs the printer, use the microsoft script prnmngr.vbs , first check that the printer is not connected in this case\\servidor\impressorared, if there is then installed on another call at the same script
Finally use the scriptdefprinter.vbs, establishing it as the default

 REM ***** Check and Install Copier*****
cscript prnmngr.vbs -l | find "Printer name \\servidor\impressorared"
IF ERRORLEVEL 1 ( cscript prnmngr.vbs -ac -p "\\servidor\impressorared"
echo "\\iocor\fax installed"
)
cscript defprinter.vbs \\servidor\impressorared

the script defprinter.vbs:

Option Explicit
dim objArgs
Set objArgs = WScript.Arguments
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter objArgs(0)
' End of example VBScript
Facebooktwitterredditpinterestlinkedinmail

Read More ...

Automated users creation

This simple script (useful for workgroup environments), is useful for generating users have in a text file users.txt this file has the following 2 fields for each line are separated by commas: user, password, example would be this::
pepito,passworddepepito
jaimito,passworddejaimito
joselito,passworddejoselito
….
the script reads the file and generates the user adds them to the Administrators group and sets the password expiration to never.

' get local computer name
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("usuarios.txt", ForReading)
Do Until objTextFile.AtEndOfStream
  strNextLine = objTextFile.Readline
  arrServiceList = Split(strNextLine , ",")
  strAccount=arrServiceList(0)
  strPswd=arrServiceList(1)
  ' check if local account already exists
  intExists = 0
  Set colAccounts = GetObject("WinNT://" &amp; strComputer &amp; "")
  colAccounts.Filter = Array("user")
  For Each objUser In colAccounts
    If objUser.Name = strAccount Then
       intExists = 1
    End If
Next
If intExists = 0 Then
  ' create local user
  Set colAccounts = GetObject("WinNT://" &amp; strComputer &amp; "")
  Set objUser = colAccounts.Create("user", strAccount)
  ' set pswd
  objUser.SetPassword strPswd
  objUser.SetInfo
  ' set pswd never expires
  Set objUser = GetObject("WinNT://" &amp; strComputer &amp; "/" &amp; strAccount &amp; ",User")
  objUserFlags = objUser.Get("UserFlags")
  objPasswordExpirationFlag = objUserFlags Or ADS_UF_DONT_EXPIRE_PASSWD
  objUser.Put "userFlags", objPasswordExpirationFlag
  objUser.SetInfo
  ' add to local admins group
  Set objGroup = GetObject("WinNT://" &amp; strComputer &amp; "/Administradores,group")
  Set objUser = GetObject("WinNT://" &amp; strComputer &amp; "/" &amp; strAccount &amp; ",user")
  objGroup.Add(objUser.ADsPath)
End If
Loop
Facebooktwitterredditpinterestlinkedinmail

Read More ...

Outlook , select olContact and send a new mail

This simple macro, use the selection object of current window Application.ActiveExplorer.Selection and in case of a selection of contacts olContact ,
creates a blank message olMailItem and fill in the Bcc field: (BCC:) with 3 e-mail contact, also can use the To: field (To:), works in Outlook 2003, 2007, 2010….

Here: link you have more information to create a button and link the macro

Sub ContactsSelected_to_CCO()
Dim olkItm As Object, olkRcp As Outlook.Recipient, olkLst As Outlook.DistListItem
 Select Case TypeName(Application.ActiveWindow)
	Case "Explorer"
		Set olkItm = Application.ActiveExplorer.Selection(1)
End Select
If TypeName(olkItm) &lt;&gt; "Nothing" Then
	Select Case olkItm.Class
		'If	 the source item is a contact or list of contacts
		Case olContact
			'Create a new Mail
			Set olmail1 = Application.CreateItem(olMailItem)
			' variable to add email address
			msgtxt = ""
			With olmail1
				Set myOlSel = Application.ActiveExplorer.Selection
				' for each selected contact adds email
				' if email 2 or email 3 are filled , add to bcc too.
				For x = 1 To myOlSel.Count
					msgtxt = msgtxt &amp; myOlSel.Item(x).Email1Address &amp; ";"
					If Trim(myOlSel.Item(x).Email2Address) &lt;&gt; "" Then
						msgtxt = msgtxt &amp; myOlSel.Item(x).Email2Address &amp; ";"
					End If
					If Trim(myOlSel.Item(x).Email3Address) &lt;&gt; "" Then
						msgtxt = msgtxt &amp; myOlSel.Item(x).Email3Address &amp; ";"
					End If
				Next x
				'put selected emails to BCC
				.BCC = msgtxt
				' display de message
				.Display
			End With
		End Select
	End If
	Set olkItm = Nothing
End Sub
Facebooktwitterredditpinterestlinkedinmail

Read More ...

Categories

Subscribe to my Newsletter




By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close