In this article I will explain how to write a program that check the disk space
If the disk space is less than specific percentage the program will send an email
to specific key users.
This program will send an email in case that disk "C:\" has free disk
space less than 10% ,of course you can modify
the program so it will get the drive , percent ,email list from set up file.
Lets start to explain how the program work
1:- We have to import Net mail by using the following command
Imports System.Net.Mail
2:- Declare the following varibles outside the procedures and function so allways we can access them
2.1: FreeSize the total free size in disk in bytes.
2.2: TotalSize total disk size in bytes.
2.3: perln free disk space prcent * 100
By dividing this number by 100 I will get
precent with just two digits after point.
2.4 per the precent of disk space
Dim FreeSize, TotalSize, perln As Long
Dim per As Double
3:- We will write function to check the disk space
Private function ChkDsk() As Boolean
'******* Declare var info varibale
Dim cdrive As System.IO.DriveInfo
'******* init our varibale to check disk c
Dim cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
'******* Get free disk space in bytes
FreeSize = cdrive.TotalFreeSpace
'******* Get total disk space
TotalSize = cdrive.TotalSize
'******* Get free disk space pecent * 100
perln = (UsedSize / TotalSize) * 10000
'******* Divide prcent by 100 to get free disk space
'******* In format ##.##%
per = perln / 100
******** Return true if free disk space less than 10%
If per < 10 then Return True else Return False
End
=======================================================
4:- Write a function that send mail to key users
This function receive 2 parameters
- Mail from (email address of the "sender")
- Mai to (users that will receive email addresses separated by ";")
For example user1@yourcompany.com ; user2@yourcompany.com
Our function should look like this
Private function SndWarnMsg(ByVal efromas As String, ByVal eto As _
String) As Boolean
Dim Mail As New MailMessage
Dim S, MailS As String
Dim Ar
Dim I as integer
Try
'********* Our mail message subject
Mail.Subject = "Low disk space in Server"
'********* Split to mail address
ar = Split(eto, ";")
'********* Add to mail address
For i = 0 To UBound(ar)
MailS = Trim(ar(i))
Mail.To.Add(MailS)
Next
'********* Our mail sender
Mail.From = New MailAddress(efromas)
'********* This varibale contains our mail message
S = "This is an automatic message from Server _
because of low disk space" + vbCrLf
S =S + "The free disk percentage is : " & per & "%" &vbCrLf
'********* Our mail message
Mail.Body = S
'********* SMTP server info/Account info/Port info
Dim SMTP As New SmtpClient(Your Mail Server/or Mail server IP)
SMTP.EnableSsl = False
SMTP.Credentials = New System.Net.NetworkCredential(sender mail user , mail pwd)
SMTP.Port = 25 'Mail port uusually 25
'********* Send mail
SMTP.Send(Mail)
Return true
Catch ex As Exception
return false '****** return false In case that error ocur
End Try
End function
5:- Put all togther
In page load event we will run ChkDsk function if it return true then we will send message
by using SndWarnMsg
the next step to stop this program by using end statment.
Actually i will add this program to the Scheduled Tasks to check the disk every day
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sts as boolean
if ChkDsk=true then
sts=SndWarnMsg("youremail","email1;email2;email3......")
if sts=true then end Else msgbox("Error ocur while sending mail")
End Sub =================================================================================== ===================================================================================
Actually you can change the program to use data file that contains program setting It is recommended to
get the following variables fro setting file
1:-Disk to checked "C:\ , D:\ ,E:\..................."
2:-Disk space percentage to start warn user that there is a problem (10%,9%........)
3:-Mail sender
4:-Receivers mail address separated by ";"
5:-Error message text
Finally add this program to the Scheduled Tasks to check the disk every day or every
some hours.
Sunday, May 26, 2013
Sunday, May 12, 2013
SQL –Ignore and remove undesirable characters using Sql. statement.
I wrote a portal for our customers.
Using this portal they can follow-up their orders status.
Our data base contain our item number and our customer
item number.
Usually when our customer want information about specific
product they use their item code.
One of our customers has not consistently codes for his items.
His items look as follow :
Y-55121 Y 55122 Y55131 55141Y,55141 Y ,55145-Y.
Actually he add Y to his item code to indicate who is the
supplier of this item.
He added Y to his code because our company name start with Y.
This customer want to query our database by using his item code.
i.e. the number without addition 55141,55121 …
for instance.
How to make this search ?
It is imposible to perfom search for every combination because
we have many combinations and also it is very hard to perfom
search from item to item
For example :
Our search is: From 5513 To 5514 and our database contains the following Items:
Y55134 ,Y-55136 ,Y 55133 ,55131Y ,55135 Y,55132-Y
All these items should appear in our search.
The best way is to ignore the 'Y' and '-' and perform search by
numbers only.
How to do it?
1:- I will replace the 'Y' by *blank using replace function.
2:- Replace '-' by *blank using replace function.
3:- Remove blanks from the field in section 2.
4:- Perfom serach by Item number.
Actually we can make it using one SQL statement as follow
For SQL400
Select * from MyTable where
trim(replace(replace(CusItno,'Y',' '),'-',' '))>='5133' and
trim(replace(replace(CusItno,'Y',' '),'-',' '))<='5134'
For SQL server
Select * from MyTable where
ltrim(rtrim(replace(replace(CusItno,'Y',' '),'-',' ')))>='5133' and
ltrim(rtrim(replace(replace(CusItno,'Y',' '),'-',' ')))<='5134'
PS: In SQL400 we can use trim function to remove blanks from right and left
However there is no such function in SQL Server that’s why we
replace it with 2 functions ltrim that remove blanks from left and
rtrim that remove blanks from right
Monday, October 22, 2012
Using the viewport meta tag to control layout on mobile browsers.
The upcoming release of Mobile Firefox (Fennec) 1.1 features improved support for the tag. Previous versions of Fennec supported the width, height, and initial-scale viewport properties, but had problems with some sites designed for iPhone and Android browsers. We now support the same properties Mobile Safari does, and we also changed Fennec to render mobile sites more consistently on screens of different sizes and resolutions
Read this article
Read this article
Wednesday, October 20, 2010
Running Classic ASP Applications on IIS 7.0 and IIS 7.5
This article covers the folowing topics:
- Classic ASP Applications on IIS 7.0 and IIS 7.5 Overview
- Classic ASP Not Installed by Default on IIS 7.0 and IIS 7.5
- Classic ASP Script Error Messages No Longer Shown in Web Browser by Default
- Using Failed Request Tracing to troubleshoot
- Classic ASP errorsClassic ASP parent paths are disabled by default
- Using Classic ASP with Microsoft Access Databases on IIS 7.0 and IIS 7.5
- APPL_PHYSICAL_PATH Server Variable on Windows Vista RTM
Registering 32-bit DLL on Windows Server SBS 2008 64-bit
Recently I'm installing a 32-bit application on a fresh installed Windows Server SBS 2008 which only comes in 64-bit version.
This application that I'm installing is requiring a DLL file to be registered on the registry using the regsvr32 command.
Here comes the problem with registering 32-bit DLL since 32-bit application see different "system32" in Windows Server 64-bit. 32-bit application will see %windir%\syswow64 as their "system32" directory in 64-bit OS, while 64-bit application will use the
%windir%\system32.
So to register the 32-bit DLL on 64-bit
Windows Server we need to call the 32-bit version of regsvr32 which located on
%windir%\syswow64, for
example:
C:\Windows\SysWOW64\regsvr32.exe.dll
Resource : Markus Blog What’s going on Internet?
This application that I'm installing is requiring a DLL file to be registered on the registry using the regsvr32 command.
Here comes the problem with registering 32-bit DLL since 32-bit application see different "system32" in Windows Server 64-bit. 32-bit application will see %windir%\syswow64 as their "system32" directory in 64-bit OS, while 64-bit application will use the
%windir%\system32.
So to register the 32-bit DLL on 64-bit
Windows Server we need to call the 32-bit version of regsvr32 which located on
%windir%\syswow64, for
example:
C:\Windows\SysWOW64\regsvr32.exe
Resource : Markus Blog What’s going on Internet?
Monday, October 11, 2010
How To Execute DB2 SQL Parameterized Stored Procedures from a Visual Basic .NET Application Using StarSQL
How To Execute DB2 SQL Parameterized Stored Procedures from a Visual Basic .NET Application Using StarSQL
Abstract
This document describes how to execute DB2 SQL parameterized stored procedures from a Visual Basic .NET application using the StarSQL software and the Microsoft .NET Framework Data Provider for ODBC.
Abstract
This document describes how to execute DB2 SQL parameterized stored procedures from a Visual Basic .NET application using the StarSQL software and the Microsoft .NET Framework Data Provider for ODBC.
Read this article Read this article Read this article Read this article
Sunday, June 6, 2010
Download Free E-Book Introducing Windows Server 2008 R2 From Microsoft
Microsoft has released yet another free e-book named Introducing Windows Server 2008 R2 and the book is available to download via Microsoft Download Center
This book covers every aspect of Windows Server 2008 R2 in nine chapters and approximately 200 pages.
Go to download page
Also you can view this book an diwnload it from this link
Subscribe to:
Posts (Atom)