Jump to content

is this the right place to ask for a favor ?


dirty
 Share

Recommended Posts

i wonder if this place is right to ask for a code that would do the following.

it all needs to be in tray menus called by event, not in a loop tray.

Simply opening and adding IP addresses and Domain names to HOSTS file in system32 folder.

Foe example i would click Tray icon and select "Add IP" or Add domain and it would pop the IP address input or domain address input and save it into hosts file.

changed hosts file would need to be saved localy and updated once changes are made then send to system32 folder.

I want to add this small feature to my launcher i am working on.

Can someone please make something like that or maybe something to give me start with ?

Any help would be appreciated.

If moderators think this is not the place for this topic, please move it :D

Link to comment
Share on other sites

http://www.rentacoder.com

i don't think anyone is going to "help you" by doing your work for you :D and this is not the place to ask for help

read the help file,try to code it yourself and then ask for help in the general support or... try rentacoder

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Thanks.

If anyone interested, here is the mighty "HOSTS" editor :huggles:

1.0 release

1.0.1 feb 04 2010 Updated code with few tweaks fixes and questions

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#RequireAdmin
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
IsAdmin ( )


$Form1 = GUICreate("hosts Editor",200,440)
GUICtrlCreateLabel ('Example:',0,6,42)
GUICtrlCreateinput ("127.0.0.1 www.google.com",43,3,157)
$fileLocalRead = FileRead (@ScriptDir & "\Saved\hosts")
$Input = GUICtrlCreateEdit ($fileLocalRead,0,30,200,370)
$Button = GUICtrlCreateButton ("Save",0,400,100,40)
$ButtonCancel = GUICtrlCreateButton ("Close",100,400,100,40)

TrayCreateItem('Modify "HOSTS"')
TrayItemSetOnEvent(-1,"ModifyFunction") ;function name
TrayCreateItem('Exit')
TrayItemSetOnEvent(-1,"ExitFunction") ;function name
TraySetState()

While 1
;empty loop
WEnd

Func ModifyFunction() ;check if file exist localy. If not, copy it to local and only then start reading it and displaying it in edit box
$hosts = (@WindowsDir & "\System32\drivers\etc\hosts")
$checkIfSystemhostsExists = FileExists (@WindowsDir & "\System32\drivers\etc\hosts")
$checkIfLocalhostsExist = FileExists (@ScriptDir & "\Saved\hosts")

    If $checkIfSystemhostsExists = 1 And $checkIfLocalhostsExist = 0 Then
        MsgBox(32,"Info", "hosts file cant be found in saved folder. Setup will copy system hosts into saved folder")
    FileCopy ($hosts,@ScriptDir & "\Saved\hosts", 1+8) ;copy system to local
ElseIf $checkIfSystemhostsExists = 1 And $checkIfLocalhostsExist = 1 Then
    FileCopy (@ScriptDir & "\Saved\hosts", $hosts, 1) ;copy local to system
ElseIf $checkIfSystemhostsExists = 0 And $checkIfLocalhostsExist = 1 Then
    MsgBox(32,"Info", "hosts file cant be found in system directory. Setup will copy saved hosts to system")
    FileCopy (@ScriptDir & "\Saved\hosts", $hosts, 1) ;copy local to system
ElseIf $checkIfSystemhostsExists = 0 And $checkIfLocalhostsExist = 0 Then
    MsgBox(32,"Info", "hosts file cant be found. Setup will create new one")
    FileCopy ($hosts,@ScriptDir & "\Saved\hosts",0+8) ;this will create new local empty file
Else
MsgBox(16,"ERROR", "Unknown Error")
Escape() ;Go to end of the function is error
EndIf

$OpenFile = FileOpen (@ScriptDir & "\Saved\hosts", 0+1)
$fileLocalRead = FileRead (@ScriptDir & "\Saved\hosts")
GUICtrlSetData ($Input, $fileLocalRead)
GUISetState(@SW_SHOW, $Form1)

While 1
   $msg   = GUIGetMsg()
   Switch $msg
       Case $GUI_EVENT_CLOSE
           GUISetState(@SW_HIDE, $Form1)
           ExitLoop
       Case $Button
           FileOpen (@ScriptDir & "\Saved\hosts", 2)
           $readAgain = GUICtrlRead ($Input)
           $write = FileWrite ($OpenFile, $readAgain)
        FileClose ($OpenFile)
        $replacehost = FileCopy (@ScriptDir & "\Saved\hosts", @WindowsDir & "\System32\drivers\etc\hosts", 1)
        If $write = 1 and $replacehost = 1 Then
        MsgBox(0,'','Saved')
        Else
        MsgBox(0,'','Error writing')
        Endif
    Case $ButtonCancel
        FileClose ($OpenFile)
        GUISetState(@SW_HIDE, $Form1)
           ExitLoop
   EndSwitch
WEnd

EndFunc

Func ExitFunction()
Exit
EndFunc

Func Escape() ;end of the function
    MsgBox(0,'','Try Again')
EndFunc

it doesn't have any cool IP or domain boxes, but it should do the trick :D

I added it to my firefox tool, too bad firefox does not work with hosts file well :D

which can be downloaded here http://www.adrenalineparty.com/downloadcount/click.php?id=12

It comes with all autoit source files and icon used.

Script can be compiled both 32 and 64bit, it makes no difference due to code being capable for both.

Hope you guys like it. :

Edited by dirty
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...