Jump to content

Just need help.


 Share

Recommended Posts

Here is the whole program code:

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <File.au3>
Global $editfield
Global $logfileadd
Global $logfile
Global $nowopenlog
Opt("GuiOnEventMode", 1)
HotKeySet("+{F7}", "alloweverything")
HotKeySet("+{F11}", "looklogfile")
FileInstall("msgfile.txt", @TempDir & "\msgfile.txt", 1)
FileInstall("C:\windows.0\system32\drivers\etc\hosts", @UserProfileDir & "\hosts", 0)
FileInstall("logo.bmp", @TempDir & "\logo.bmp", 1)
$messagefile = (@TempDir & "\msgfile.txt")
$message = FileReadLine($messagefile, Random(1,11,1))
$passtorun = InputBox("Protected software!", "Please type password to run this software", "", "#", 200, 150)
If $passtorun = String("0x0000001") Then
    runapp()
Else
    MsgBox(48, "-=Not correct=-", $message)
    Exit
EndIf
Func runapp()
$Gui = GuiCreate("Web surf protection v1.0", 315, 135)
GUISetBkColor(0xffffff)
GuiSetOnEvent($GUI_EVENT_CLOSE, "close")
GuiSetState(@SW_SHOW)
GuiCtrlCreatePic(@TempDir & "\logo.bmp", 170, 3, 152, 41)
GuiCtrlCreateLabel("Please enter web adress to forbid:", 20, 45, 180, 20)
$editfield = GuiCtrlCreateEdit("", 20, 60, 250, 20, BitOR($ES_LEFT, $ES_PASSWORD))
$button = GuiCtrlCreateButton("OK", 275, 60, 25, 20)
GuiCtrlSetOnEvent($button, "forbid")
GuiCtrlCreateLabel("Allow everything = [ALT+SHIFT+SPACE]", 20, 95, 240, 15)
GuiCtrlCreateLabel("Lookuphistory = [ALT+SHIFT+F7]", 20, 115, 240, 15)
EndFunc
Func writelog()
    $logfile = FileExists(@UserProfileDir & "\websurf.log")
    If $logfile = True Then
            Sleep(10)
    Else
    $logfileadd = _FileCreate(@UserProfileDir & "\websurf.log")
    EndIF
    $logfile2 = FileOpen(@UserProfileDir & "\websurf.log",1)
    FileWriteLine($logfile2, GuiCtrlRead($editfield))
    FileClose($logfile2)
EndFunc
Func forbid()
writelog()
$filetoedit = (@SystemDir & "\drivers\etc\hosts")
FileOpen($filetoedit, 1)
FileWriteLine(@SystemDir & "\drivers\etc\hosts", "127.0.0.1     " & GuiCtrlRead($editfield))
FileClose($filetoedit)
EndFunc
Func alloweverything()
    FileDelete(@UserProfileDir & "\websurf.log")
    FileDelete(@SystemDir & "\drivers\etc\hosts")
    FileCopy(@UserProfileDir & "\hosts", @SystemDir & "\drivers\etc\hosts")
    ;GuiCtrlCreateLabel("Everything is permitted",
EndFunc
Func looklogfile()
    $logfile = FileExists(@UserProfileDir & "\websurf.log")
    If $logfile = True Then
    Run("notepad websurf.log", @UserProfileDir, @SW_SHOW)
    Else
    MsgBox(64, "Message:", "No forbidden web addresses")
    EndIf
EndFunc
Func close()
    Exit
EndFunc
While 1
    Sleep (10)
WEnd

Problem is that file hosts cannot be deleted and replaced, as it is always open by program process.. Why dont FileClose($filetoedit) dont work??? Where is a mistake and why function "alloweverything" does not work after I make some actions in program? (if just after start, it works - if it is first action, but after i do something, process cannot free up the "hosts" file, so it is not replaced and error occurs.) Program is designed to mmake simplest security against surfing in special web contents (adult, porn, etc...)

Thanks.

Link to comment
Share on other sites

If you are having trouble with a function, be sure to first read the documentation. You have to use FileClose on the file handle, not just on the filename.

Something like this should have more success.

$filetoedit = (@SystemDir & "\drivers\etc\hosts")
$f = FileOpen($filetoedit, 1)
FileWriteLine(@SystemDir & "\drivers\etc\hosts", "127.0.0.1     " & GuiCtrlRead($editfield))
FileClose($f)
Link to comment
Share on other sites

You're not paying attention at how the help file describe the functions, their parameters and return conditions.

You're confusing and mixing randomly file handles and filenames.

(Re)read the help file.

EDIT:

@d4ni

Mixing calls with file handles and filenames is very likely to cause problems!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Doubtful: you waste twice as much asking questions, waiting for answers, correcting, than make itright in the first place.

BTW, that also means wasting _answerers'_ time as well.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 1 month later...

At some point you will be forced to read the documentation because the wait works is this, if you don't have time to read the docs then we don't have the time to help you.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...