Sunteți pe pagina 1din 4

Student Conference on Research and Development (SCOReD) 2003 Proceedings, Putraiaya, Malaysia

. .
GUI for PC Auto-Shutdown
Mohd. Liakot Ali, Fatimah bt Othtnan
Department of Electrical and Electronic Engineering
Faculty of Erigiginiering, Universiti Puba Malaysia
43400 UPM Serdang, Selangor, Malaysia
e-mad: liakot(ii!enfi.opm.edu.mv, fatimah o@inailcity.com

Abstract- This paper presents the development of 11. PROCESS TO DEVELOP


graphical user interface (GUI) for auto-shutdown of SOFTWARE
personal Computer using Microsoft Visual Basic 6.0. The
software monitors the status of power supply of the Learn how to use Visual Basic 6.0 and be familiar
Personal Computer through peripherals device such as with it.
unintempted power supply (UPS). When the power goes * Collect information and data of the PC and
out, the U P S will supply the power to the PC for a limited
period of time. Before the UPS reaches its limit it will
send a signal to the PC h o u g h Rs-232 serial port and the
. peripherals.
Design / draft the required software.
Develop the program by using Visual Basic 6.0.
software will detect the signal and executes for saving all Test the software in the PC with a signal.
the programs opened by user and give the PC auto- Make sure the program will operate with the
shutdown. An application programming interface ( M I ) peripheral’s signal.
h c t i o n is.used in the Visual Basic program, The
Analyze the operations and suggest
s o h a r e developed in this project is capable of saving a11
recommendations.
the programs opened by the users and shutdown the PC
safely when the power goes out. It saves from corruption
111. SYSTEM SOFTWARE
of all software and hardware in the PC.
Below is the process on how the system software works:
Keywords
Graphical User Interface (GUI), application
UPS sends a signal to the PC through RS-232 cable.
programming interface (API), RS-232 serial port,
MSComm control, privileges. .. All the files that are running in the windows are
enumerated.
I. INTRODUCTION The Visual Basic application will restore and
minimized.
Personal Computer (PC) is a machine is found at home, The mouse pointer is hide to the bottom of the
office, school, and factory. The rapid spread of
computer in society nowadays has both simplified and
complicated our lives. Whether a PC at work or come in
. screen.
All programs opened will be closed and virtual key
will be sent to save all the files.
contact with one for other reasons can be rely on, most When complete, the PC will shutdown.
of us have used a PC at one point or another. If suddenly
there is a power failure for the PC, normally the unsaved IV. METHODS FOR CLOSING
file will be closed and the PC is shutdown forcefully APPLlCATION
and the PC will be corrupted.
There are two methods to let the application shutdown
This project consisted of developing a program of a properly before the operating system power off, If.it
graphical user interface GUI for data communication doesn’t shutdown properly the application may not
between personal computer (PC) and unintempted release system resources and the operating system will
power supply Cups) through RS-232. The Visual Basic not shut down. Users will have to use Ctd-Alt-Del to
program accepts signal from one of several data zap the application. [I].
communications included with the source code or from
the UPS at run time for full compile. The intents were to Method 1: A sub class is created that will monitor the
provide a GUI that would simplify the program system level messages from the operating system. The
execution for the user. In the event of a blackout, this shutdown message is trapped and all database
software will: connections and open file handles are closed. A proper
Save open files, and close applications app close and exit are done. But if the have to worked
Shut down Windows with sub-classes there will be a very big problem

Method 2: The sinvle but effective method. Hidden


form is created, which will be the startup object. In the
load event of this form it is called Sub Main 0. In

0-7803-8173-4/03/$17.00 02003 IEEE. 3 72

Authorized licensed use limited to: Sri Sivasubramanya Nadar College of Engineering. Downloaded on January 7, 2009 at 06:01 from IEEE Xplore. Restrictions apply.
unload or terhinate event of :this form it is cal!ed a Signal Common ..(pin 5 ) : This line brings the
shutdown procedure that will orderly close all interconnecting devices to the same point of reference
connections, open file handles etc. The operating system for zero volts.
sends a shutdown message to the application's main
form when it is about to reboot, which will trigger the RTS Request To Send (pin 7) - Request to Send is a
form's unload/texminate events. The few seconds data-flow control output that connects to the connecting
between that and the actual attempted zapping of the device's Clear to Send (CTS) input. Typically, RTS and
application by the operating system is enough time to CTS are used to implement a hardware data-flow
orderly close everything. control. If used for flow control, the computer (DTE)
places the RTS in the mark state, indicating to the
V.' VISUAL BASIC REVIEWS remote device that it's ready to receive data. If the
receive buffer of the DTE should be come full, a space
Visual Basic objects have properties, method and is asserted on RTS instructing the interconnecting
events. Properties define the identity and state of an device to temporarily stop sending data.
object. Methods and events define the behavior of a n
object 121. CTS Clear To Send (pin 8) - Clear to Send is a data-
Property: A named attribute of an object. Properties flow control input that is wired to the RTS of the
define object-oriented characteristics, such as size, interconnecting device. CTS are a data-flow control
color, screen location, or whether the object is companion to RTS. If a mark is asserted on CTS, the
eibled. Every Visual Basic object has a property DTE wiIl continue to transmit data. Data transmission
called name. will be temporarily halted if a space i s detected on C T S .
Event: An action recognized by an object, such as
clicking the mouse or pressing a key. Code can be VIII, ;MS COMM CONTROL
'
written to respond to events,
Method A Subroutine or Function that operates on The MSComm control comes with Visual Basic. This
an object. one came with VISUAL BASIC 6.0. The MSComm
control provides. serial communications for an
VI.API application by allowing the transmission and reception
. .
. . _.- . of data through a serial port [4].
API (Advanced Programmers Interface) is a set of
predefined Windows functions used to control the Event-driven communications is a very powerful
a p p e h n c e and behavior of every Windows element method for 'handling serial port interactions. In many
(from the outlook of the desktop window to the situations notify the moment an event takes place, such
allocation of memory f0r.a new process). Every user as when a character arrives or a change occurs in the
action causes the execution of several or more API Carrier Detect (CD) or Request To Send (RTS) lines. In
function telling Windows whafs happened. such cases, use the MSComm control's OnComm event
to trap and handle these communications events. The
It is the codes that act as a shell to provide an automated OnComm event also detects and handles
and easier way to access MIS.It has completely hidden communications errors. For a list of all possible events
the MIS and provided a quite different approach for and communications errors, see the C o d v e n t
programming under Windows. Every line of code in property.
Visual Basic is being translated by Visual Basic into
API function and sent to Windows (either written in a Each MSComm control corresponds to one serial port.
code, or taken by some defaults). If needed to access more than one serial port in an
application, use more than one MSComm control. The
vD[. Rs-232 SERIAL PORT port address and intenupt address can be changed fiom
the Windows Control Panel.
T h e pins and associated fimctions foi a 9-pin D-type
, RS-232connector are illustrated above [3]. IX. SHUTDOWN WINDOWS
WIN CONNECTOR
On 9x machines shutting down Windows is as simple as
calling the ExitWindowsEx function and passing it a
DATACARRIER DETECT (WO)
flag telling Windows how to shut down. Windows can
RECEWE DATA UNE (RD) ' DATA SET READY (DSRJ be instructed to shut down in a number of ways
REQUEST TO SEND (RTS)
TFlMSMIT DATALtNE (TO) '
including shutting down all processes running and
DATATERMINALREADY (OTR) CLEAR TO SEND ICTS)
RING INOICATElRll logging off the user (EWX-LOGOFF), shut down and
GROUND
restart the system (EWX-REBOOT), forcibly shut
down the system without closing files resulting in
possible data loss (EWX-FORCE) and shut down the
Fig. 1. RS-2329-Pin Connector Layout

373

Authorized licensed use limited to: Sri Sivasubramanya Nadar College of Engineering. Downloaded on January 7, 2009 at 06:01 from IEEE Xplore. Restrictions apply.
system to a point where it is safe to turn off the system
(EWX-SHUTDOWN).

On Windows NT and 2000 machines shutting .down


windows is more involved. We must get thk$&ess
token of the current process with the privilegeb of
querying the access token and adjusting its privileges.
The GetCurrentProcess h c t i o n returns the current
process while the OpenProcessToken h c t i o n and
TOKEN-ADJUST-PRIVILEGES and
TOKEN-QUERY flags do the rest.
Next we need to get the locally unique identifier (LUID)
that represents the shutdown privilege. This is
accomplished with the LookupPrivilegeValue function
passing it the &quo;SeShutdownPrivilege" string. Once Fig. 2. PC Power Status Monitor
we have the locally unique identifier we can populate a
Token-Privileges structure. We must allow the process When the power goes out, the UPS will supply the
to shut down the computer by setting the structure's power to the PC for a limited period of time. At the
Privi1eges.Attributes field to same time the UPS will send a signal to the PC through
SE-PRIVILEGE-ENABLED. A call to
an RS-232 serial port. The software will get this signal
AdjustTokenPrivileges passing it the newly populated and a waming will be shown that the PC will be
Token-Rrivileges structure gives the application the shutdownas shown in Fig. 3. Once the signal is detected
right to shut down Windows. this software is minimized so that it will not be the top
of the window and it will not closed first. The mouse
Finally, all that remains is a call to ExitWindowsEx as
cursor too will be restricted to the bottom of the window
described above [ 5 ] . . for the same purpose.
X. RESULTS AND DISCUSSION

Fig. 2 below shows that the Visual Basic application in


a standby modes. It monitors the power status of the PC
and standby for a signal from UPS through RS-232
serial port. Notice that apart from i t detects the version
of the operating system; it aIso detects the number of
files that are all opened by the user and the files that are
running in the windows like anti-virus, system utility,
system tray, etc. This number of opened windows is
detected every 1000 interval i.e. every 1 second.

Let an application of Microsoft Word be an example for


this project. When the user opens this Microsoft Word
application, the number of opened windows will be
added to the label that is provided in the Visual Basic
application. The Fig. 2 shows that the user has typed Fig. 3. Shutdown Dialog
something in the word document. If suddenly there is a
power failure for the PC, normally the unsaved file will Then the execution of the file saving will begin. The
be closed and the PC is shutdown forcefidly and the PC word application, which is the top of the window, will
will be corrupted. But with this software presented in be closed. Then a dialog window is shown asking for
this project, it will saves the file and close the Windows save the changes made as shown in Fig. 4. Most of the
safely. dialog window has a default behavior of Enter or Esc.
An Enter key is send virtually and the word application
is saved. This close and save are repeated until all the
running application is closed.

3 74

Authorized licensed use limited to: Sri Sivasubramanya Nadar College of Engineering. Downloaded on January 7, 2009 at 06:01 from IEEE Xplore. Restrictions apply.
XI.. .CONCLUSION

The development of a GUI for auto-saving and auto-


shutdown PC is presented in this project. This software
is developed using Microsoft Visual Basic under
Windows Environment, In a Microsoft Visual Basic 6.0
program, a Microsoft Windows application
programming interface (API) function is used to shut
down the computer system. This project explains how to
quit Windows and shut down the computer system. This
software package uses MSComm component and a port
of RS-232. MSComm is a user knowledge database.
Through MSComm the engineers can simulate and
study the computer system protection. This program can
be tested with UPS and any other peripherals and can be
Fig. 4. Saving the Applications generalized to monitor for all the activities done in the
Personal Computer.
When all the &g application is closed, the Windows
is safely shutdown. The Windows is shutdown XT. REFERENCE
automaticalIy with the default Enter key as shown in
Fig. S. [ I ] Jack van Niekerk, “Let your application close
orderly before the system reboot. Avoid hanging
the O/S while‘your application is running and the
user want’s to reboot”.
[2] J. Dukovic and D. Joyce, “An Evaluation of Object-
Based Programming with Visual Basic”, IEEE
[3] Thomas E. Leonik, Home Automation Basics:
Practical Applications using Visual Basic 6.0, IN:
Indianapolis-Prompt, 2000
[4] ONTRAK Control System, “Serial Data
Acquisition & Control Interfaces”, www.ontrak.net,
1999.
[SI The Scarms...“Visual Basic Code Library”,
www.TheScarms.com.
[6] DeitellDeitel, Visual Basic Programming, IDG
Books Worldwide, 1998.
.,1
t-
-
- [7] Jan Axelson, Serial Port Complete: Programming
Fig. 5. Shutdownthe Wmdows . ~
! ’ t
: and Circuits for RS-232 and RS-485 Links and
Networks, USA: Lakeview Research, 1998.
Fig. 6 shows the saved application when the power of
the PC is back on and the Windows is running.

L,
Fig. 6. Saved Application

375

Authorized licensed use limited to: Sri Sivasubramanya Nadar College of Engineering. Downloaded on January 7, 2009 at 06:01 from IEEE Xplore. Restrictions apply.

S-ar putea să vă placă și