|
|
 |
 |
|
|
 |
 |
|
Join the Discussion
|
"Post your views, comments, questions and doubts to this article."
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
Article submitted by Nicolae Bogdan for the Delphi Programming Quickies Contest.
Hosts
Many administrators need to have better control when configuring workstations. A method of increasing network performance is through the file called "hosts" which keeps mappings of IP addresses to host names or URL's. On Windows XP systems, this file is located under "\Windows\System32\Drivers\Etc". To manage the "hosts" file, if it isn't already available on the computer, you have to create it and edit manually. My simple program automates completely this task with detection of the existence of the "hosts" file.
I have included 2 versions: one includes confirmation dialogs at start, open file, create file, user exit; the other one displays a dialog only when you need to create the hosts file. This program works from local workstation on Windows platforms.
If you use a share name as the first parameter you can modify the hosts file of another computer which is very useful. Be warned that you need write permissions to be able to modify a file on another computer.
Download FULL code, code sample:
begin
{$I-}
reset(f);
closefile(f);
{$I+}
if ioresult <> 0 then
if MessageBox
(0,
pchar('Create "' + s2 + '" file?'),
'Create "hosts" file ?',
mb_yesno)=6 then
begin
rewrite(f);
closefile(f);
ShellExecute(0,
'open',
pchar(s1),
pchar(s2),
nil,
1);
if (GetWinVersion=wvWin95) or
(GetWinVersion=wvWin98) then
ShellExecute(0,
'open',
pchar(s1),
pchar(windir+'\hosts'),
nil, 1);
end
else
MessageBox(0,
'File doesn''t exists! ',
'File "hosts" not created',
mb_ok)
else
ShellExecute(0,
'open',
pchar(s1),
pchar(s2),
nil,
1)
end
|
Basically, this is entry level Delphi programming. The program's size is optimized according to the article: "Your first raw API Delphi program" and "Get Windows version". I hope this program will be helpful for true beginners to understand Delphi/Pascal instructions.
Don't miss: Delphi Programming Quickies Contest!
|