Lazarus
Miscellaneous => Other => Topic started 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.
-
Good show. Hopefully it's gonna be a fun ride for you :D
A couple of hints:
- Do not use redundant local variables for TListBox.ItemIndex (SelectIDX ; I remember seeing this also in some other thread recently). Just check ItemIndex when applicable (or use a function that will always give you the most recent and correct result). Do check when clicking buttons if this value by any chance is < 0.
- Use form local variables instead of global variables (move HostsFile to the private section of your form).
- Have a look at TActionList. That component can help you centralizing actions for reuse in other controls.
-
Hi thanks for the info eny will try and look into that today.
-
HI this is a new update of my hosts editor some of the new features are below:
- Added Add Comment
- Added Add Edit Line
- Added Add Blank line
- Added Copy Line to clipboard
- Added Save as option
- Added help file in pdf format
-
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:
1 24 "manifest.xml"
that refers to manifest.xml, an example - you can modify some fields; the important line is the one containing requestedExecutionLevel :
<?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
{$R manifest.rc}
to your code, e.g. under the
{$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
-
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
-
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?
-
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)
-
Thanks BigChimp for the info I will look into them and try to include them in my next update.
-
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...
-
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...
-
Thanks to the reply
-
Just curious: What does "elevation" means? :-[
-
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...
-
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?
-
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 :)
-
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.
-
thanks this will be handy for blocking unwanted sites on my workplace :)