Lazarus

Miscellaneous => Other => Topic started by: BenJones on June 22, 2011, 09:35:45 pm

Title: My Hosts File Editor
Post by: BenJones on June 22, 2011, 09:35:45 pm
Hi all this is my second project I made in Lazarus since I found this wonderfull tool. This a basic Hosts file edtor for the little host files it very basic to use I have commented the code so it easy to understand anyway hope you like it, Been tested on Win2000 and above. I am not sure about lower versions of windows. Hope you like the code comments are welcome.
Title: Re: My Hosts File Editor
Post by: eny on June 22, 2011, 10:27:11 pm
Good show. Hopefully it's gonna be a fun ride for you  :D

A couple of hints:
Title: Re: My Hosts File Editor
Post by: BenJones on June 23, 2011, 08:30:44 am
Hi thanks for the info eny will try and look into that today.
Title: Re: My Hosts File Editor V1.0
Post by: BenJones on June 25, 2011, 07:14:21 pm
HI this is a new update of my hosts editor some of the new features are below:

Title: Re: My Hosts File Editor
Post by: BigChimp on June 26, 2011, 10:54:00 am
Hi Ben,

Nice program & good that you include a help file! I know my second project in Lazarus was not as good by far.

Some remarks on usage:
1. The add blank line button adds the line at the end of the host file. Perhaps you want to comment some existing entry; in this case it makes sense to insert the line at the cursor position.
2. If you delete a line, you only get a prompt that asks if you are sure you want to delete this line? You could add the content of the line and/or its position to clarify/confirm to the user which line is going to be deleted.
3. On Vista and up, this program won't save because it needs elevation. One way to do this is to add a manifest.rc resource script:
Code: [Select]
1 24 "manifest.xml"that refers to manifest.xml, an example - you can modify some fields; the important line is the one containing requestedExecutionLevel :
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
 <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="CompanyName.ProductName.YourApp" type="win32"/>
 <description>Remote support help tool.</description>
 <dependency>
  <dependentAssembly>
   <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
  </dependentAssembly>
 </dependency>
 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
   <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
   </requestedPrivileges>
  </security>
 </trustInfo>
</assembly>

Finally you'd have to make sure that this manifest.xml is included as a resource in your app: add
Code: [Select]
{$R manifest.rc}
to your code, e.g. under the
Code: [Select]
{$R *.lfm}line in your unit1.pas

NOTE: Forgot to mention that this conflicts with the "Use manifest file to enable themes (Windows only" option in Project Options/Application. If you have that one switched on, the Lazarus-generated manifest will override our own.

BigChimp
Title: Re: My Hosts File Editor
Post by: fabienwang on June 26, 2011, 12:33:34 pm
Nice program.
wow BigChimp nice one i didn't know that we could ask for elevation i thought it would be a win32 api call xD
Title: Re: My Hosts File Editor
Post by: marcov on June 26, 2011, 01:08:05 pm
BigChimp: does such manifest work if the program is not installed by an installer ?

Or must it be installed by an (vista aware) installer to work?
Title: Re: My Hosts File Editor
Post by: BigChimp on June 26, 2011, 02:10:18 pm
Nope, works without an installer.

I used it in my CheckRide wrapper for UltraVNC which requires admin/elevated access to install a service required by UltraVNC:

https://bitbucket.org/reiniero/checkride
 (https://bitbucket.org/reiniero/checkride)
Title: Re: My Hosts File Editor
Post by: BenJones on June 26, 2011, 07:50:25 pm
Thanks BigChimp for the info I will look into them and try to include them in my next update.
Title: Re: My Hosts File Editor
Post by: BigChimp on June 27, 2011, 09:39:54 am
Forgot to mention that this conflicts with the "Use manifest file to enable themes (Windows only" option in Project Options/Application. If you have that one switched on, the Lazarus-generated manifest will override our own.
Sorry, BenJones, you had that setting switched on in your project, so it wouldn't work.

Attached the files changed from BenJones' 25th of June release for elevation. Let me know if it doesn't work...
Title: Re: My Hosts File Editor
Post by: BigChimp on June 27, 2011, 12:49:07 pm
In reply to a PM - in case people encounter this in future: if you try run the code inside the Lazarus IDE/debugger, this will not work as the app requires elevation. Solution: run Lazarus.exe/Startlazarus.exe as administrator (=with elevation), then debug...
Title: Re: My Hosts File Editor
Post by: BenJones on June 27, 2011, 03:48:11 pm
Thanks to the reply
Title: Re: My Hosts File Editor
Post by: Ñuño_Martínez on June 28, 2011, 04:06:32 pm
Just curious:  What does "elevation" means? :-[
Title: Re: My Hosts File Editor
Post by: BigChimp on June 28, 2011, 04:15:37 pm
In older version of Windows, you have various privileges; there was e.g. a distinction between regular/normal users, power users and administrators (comparable to Linux/OSX root).

Although users were encouraged to use regular user accounts, not admin accounts, on Windows NT and later, a lot of users kept using admin accounts => malware risk.

Trying to reduce this threat, Microsoft decided that an admin account.... does not have admin permissions by default (e.g. may not change clock time or format a disk or ...).
Whenever you want that, you require elevation: temporary extra privileges that allow the full range of admin priviliges just like in earlier versions of Windows.

This started after Windows XP, in Vista...
Title: Re: My Hosts File Editor
Post by: Ñuño_Martínez on June 29, 2011, 01:41:01 pm
Thanks for the explanation.  I didn't know about it because I always created two users on Windows (admin and user).  So it's similar than Ubuntu's "sudo" and the "sudoer" userlist, isn't it?
Title: Re: My Hosts File Editor
Post by: BigChimp on June 29, 2011, 02:07:44 pm
That's a very good analogy.

Both sudo and elevation let you do things you normally are not allowed to.
Sudo does this by temparily impersonating another account (e.g. root), while elevation gives you access to privileges that are in your own acccount, though normally not available.

In practice, I'd prefer if Microsoft had just implemented sudo - makes it easier to understand for me :)
Title: Re: My Hosts File Editor V1.1
Post by: BenJones on July 01, 2011, 02:32:56 pm
Hi agian this is a new updated version to v1.1 of my hosts editor see the new chnages below:

*Updated Add Comment, Add blank line data is now added at the cursor position.
*Updated delete line Now shows you the line that will be deleted.
*Updated GUI to new version.
*Updated help file.

#Fixed problem with crash bug when not run as admin on Vista and Windows 7, Thanks to BigChimp.

-Removed menu items you have now got all the buttons in the new UI.

+Added option to set HOST file to read-only or writeable
+Added option to create new default host file. This file uses HOSTS.default in the program folder.

Hope you like the new update.

Title: Re: My Hosts File Editor
Post by: j0x on August 07, 2011, 03:55:01 am
thanks this will be handy for blocking unwanted sites on my workplace  :)
TinyPortal © 2005-2018