Sunday, June 22, 2008

Shutdown your PC using a Cellphone / Telephone


Main Title: Modem Interface
Project: Shutdown PC using a phone
Developer: Md. Redwanur Rahman
Location: Dhaka, Bangladesh.
Date: 19 September, 2007

Just share programming knowledge to the world

Aim of this project:
Shutdown PC using a phone

Needed components:
Modem, a telephone set

Program code

Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type

Private Const WM_COMMAND = &H111
Private Const WM_USER = &H400
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

'These 4 APIs jointly can used to find Class Name of your required Application
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const SW_RESTORE = 9
Private Const SW_NORMAL = 1
Private Const SW_SHOW = 5
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

'keybd_event API call constants
Private Const VK_SHIFT = &H10
Private Const VK_LSHIFT = &HA0
Private Const VK_RSHIFT = &HA1
Private Const VK_RCONTROL = &HA3
Private Const VK_CONTROL = &H11
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

'user defined type required by Shell_NotifyIcon API call
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type

'constants required by Shell_NotifyIcon API call:
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

Private nid As NOTIFYICONDATA
Dim tm As Long

Private Sub Combo1_Click()
On Error GoTo ER:
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = Combo1.ListIndex + 1
MSComm1.PortOpen = True
Exit Sub
ER:
MsgBox Err.Description
End Sub

Private Sub Form_Load()
Dim portNum As Integer
portNum = CInt(GetSetting("CallMon", "General", "Port", 1))
Dim txt
txt = GetSetting("CallMon", "AppClasses", "Class" & 100)
With MSComm1
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
End With
With Combo1
.AddItem "COM 1"
.AddItem "COM 2"
.AddItem "COM 3"
.AddItem "COM 4"
.AddItem "COM 5"
.AddItem "COM 6"
.AddItem "COM 7"
.AddItem "COM 8"
.ListIndex = portNum - 1
End With

'Used for minimising application to System Tray as an Icon
With nid
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = "Call Monitor" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub

Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then Me.Hide
End Sub

Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
SaveSetting "CallMon", "General", "Port", CStr(Combo1.ListIndex + 1)
End Sub

Private Sub mnuExit_Click()
Unload Me
End Sub

Private Sub MSComm1_OnComm()
Dim rcv As String
If MSComm1.CommEvent = comEvReceive Then
rcv = MSComm1.Input
If rcv = vbCrLf + "RING" + vbCrLf Then
If Timer1.Enabled = False Then
Call Turnoff
Timer1.Enabled = True
End If
tm = 0
End If
End If
End Sub

Private Sub Timer1_Timer()
tm = tm + 1
If tm > 10 Then
Me.Icon = Image1.Picture
nid.hIcon = Me.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
End Sub

Private Sub Turnoff()
List1.AddItem "CALL @” & Time
Label3.Caption = Date & Time
Label3.Caption = "Your Computer is shutting down"
Shell "shutdown -s -f -t 0" ‘windows xp
'Shell "c:windowsrundll.exe user.exe,exitwindows" ‘windows 98
End Sub

Download this Project: www.geocities.com/redu0007

Operation:
Install modem in your computer than connect your telephone wire to modem. Develop the following program in visual basic or download the program and run it in your PC then call from another telephone to your connected modem phone. Computer will be shutdown. Check code, there is a difference between windows XP, Windows 98 codes for shutdown

Conclusion:
I developed this program that published by Computer JAGAT in Bangladesh, September 2007.

No comments: