Sign in to follow this  
Followers 0
Guest Py7|-|[]/\/

FileOpen Help

17 posts in this topic

Ok, I'm writing a script, (not done yet), to block specific internet websites. Here it is so far:

;Denies internet access to specific internet websites by blocking the internal system files.

$blocked = InputBox("Your input is required.", "Please enter the website name to block, type 'done' to exit.")

TrayTip("Opening file hosts.txt...", "Searching for file...", 5)
FileOpen("hosts.txt", 1)
TrayTip("Found file hosts.txt", "Beginning website blocking...", 10)

WinWaitActive("hosts - Notepad")
WinActivate("hosts - Notepad")

;Choses the website to block, then blocks it.

WinActivate("hosts - Notepad")
Sleep(1000)
Send("127.0.0.1 " & $blocked)
Sleep(1000)

While 1
   If $blocked = "done" Then
      FileClose($file)
      Exit
   EndIf
WEnd

TrayTip("Completed.", "Thanks for your time.", 5)

Now, the problem is... It will not open hosts.txt...

Another question... Does FileOpen() search the entire hard drive to find the specified file name? Or does it just search the desktop or something. Because the file I want to open, (hosts.txt) is located in C:\WINDOWS\SYSTEM32\DRIVERS\etc. Thanks for any and all help that you can give me.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

;Denies internet access to specific internet websites by blocking the internal system files.

$file = FileOpen("hosts.txt", 1)
$blocked = InputBox("Your input is required.", "Please enter the website name to block, type 'done' to exit.")

If $file = -1 Then
   Exit
EndIf

TrayTip("Commencing operation...", "Operation beginning now...", 5)

While 1
   FileWrite($file, "127.0.0.1 " & $blocked)
   Do 
  ;What I want to do is call the imput box that I have in the variable "$blocked", but it won't let me do that... How would I call the InputBox Function from my $blocked
  ;variable without having it like: "Do $blocked Until $blocked = "done"" because that obviously doesn't work.
   Until $blocked = "done"
   Sleep(10)
WEnd

TrayTip("Completed.", "The operation has been completed, thanks for your time.", 5)

Due to my lack of intelligence I have modified it slightly in hopes that it will accomplish what I want. The problem is, how do I call the $blocked function in the Do loop? Sorry if this is confusing.

Also: Here is what I am hoping to add to the hosts.txt file...

127.0.0.1 www.websitenamehere.com

127.0.0.1 www.anotherwebsitenamehere.com

127.0.0.1 www.etcetcetc.com

Edited by Py7|-|[]/\/

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

( a ) hosts does not have a .txt ending.

( b ) No, fileopen opens files in the current directory and path variable.

( c ) FileOpen(@SystemDir & "\Drivers\etc\hosts")

( d ) You don't use fileopen to open notepad.

( e ) You use filewriteline to append to a file without opening it.

( f ) You haven't read the helpfile thoroughly, or else you would know that

( g ) -=+-[]}\|

( h ) Sorry, I'm too tired to tell you the other numerous mistakes you have made in this script alone

( i ) I will not do this for you

( j ) Think before posting

( k ) Read the manual

( l ) You are still writing the word "done" in the hosts

( m ) You should have put the whole thing in a loop

( n ) Do not post any "fixed" code until you make an honest effort to fix it yourself

( o ) Don't open notepad anyway for creating text files

( p ) Winactivate is redundant after winwaitactive (if it was activated, it is active)

( q ) You should have an if @error after inputbox instead of making the user type "done"

( r ) If you had read the helpfile on inputbox, you would have known that.

( s ) If you make any more stupid mistakes, I will not be as lenient with you next time

EDIT: You have already posted more completely useless code, each with its own mistakes. READ CAREFULLY my comments that actually only pertain to the code at the top of the page.

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

FileWrite

--------------------------------------------------------------------------------

Append a line of text to the end of a previously opened text file.

Quoted from the helpfile. This is just one reason why I thought I needed FileOpen first.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Where did I mention FileWrite?

( g ) Would be the equivalent of an IQ test to Python... I am sure he will spend more time trying to see what that says than actually reading the rest of the clearly plainly written english. (no offense, man, just being funny)

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

( e ) You use filewriteline to append to a file without opening it.

Didn't misread anything :)

Edited by Py7|-|[]/\/

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

:) I rest my case :)

Just wondering, how long did you spend on ( g ) ?

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

Just wondering, but how many posts do you get from flaming people? Read Private Message.

Share this post


Link to post
Share on other sites

Ahh. Interestingly enough... Here is another quote from the helpfile. Does this clear up anything this-is-me?

FileWriteLine

--------------------------------------------------------------------------------

Append a line of text to the end of a previously opened text file.

Yes, that's right... Even FileWriteLine says "a previously opened text file." No wonder one such as myself could be so mislead into believing that one should use FileOpen before calling FileWriteLine and therefore be flamed by one who was wrong in assuming that one misread a previous post.

Share this post


Link to post
Share on other sites

;Denies internet access to specific internet websites by blocking the internal system files.

$blocked = InputBox("Your input is required.", "Please enter the name of the website you wish to block.")

TrayTip("Beginning...", "The file you wish to block will shortly be blocked.", 5)

FileWriteLine("hosts.txt", "# Copyright (c) 1993-1999 Microsoft Corp.")
FileWriteLine("hosts.txt", "#")
FileWriteLine("hosts.txt", "# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.")
FileWriteLine("hosts.txt", "#")
FileWriteLine("hosts.txt", "# This file contains the mappings of IP addresses to host names. Each")
FileWriteLine("hosts.txt", "# entry should be kept on an individual line. The IP address should")
FileWriteLine("hosts.txt", "# be placed in the first column followed by the corresponding host name.")
FileWriteLine("hosts.txt", "# The IP address and the host name should be separated by at least one")
FileWriteLine("hosts.txt", "# space.")
FileWriteLine("hosts.txt", "#")
FileWriteLine("hosts.txt", "# Additionally, comments (such as these) may be inserted on individual")
FileWriteLine("hosts.txt", "# lines or following the machine name denoted by a '#' symbol.")
FileWriteLine("hosts.txt", "#")
FileWriteLine("hosts.txt", "# For example:")
FileWriteLine("hosts.txt", "#")
FileWriteLine("hosts.txt", "#      102.54.94.97     rhino.acme.com          # source server")
FileWriteLine("hosts.txt", "#       38.25.63.10     x.acme.com              # x client host")
FileWriteLine("hosts.txt", "")
FileWriteLine("hosts.txt", "127.0.0.1       localhost")
FileWriteLine("hosts.txt", "127.0.0.1 " & $blocked)
Sleep(1000)
FileCopy("C:\Documents and Settings\Owner.ADMIN\Desktop\hosts.txt", "C:\WINDOWS\SYSTEM32\DRIVERS\etc\hosts.txt", 1)

TrayTip("Ending...", "The files you wish to block have been blocked, thank you for your time.", 5)

Ok, here is an updated version of my original script. It works fine... The only problem is that I need to change it to a Windows File type instead of a .txt, is this possible? By doing this I can just overwrite the original file. Thanks.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Here's another quote, since you are only too willing to quote the non-read helpfile anyway:

If a filename is given rather than a file handle, the file will be opened and closed during the function call

EDIT: FileCopy("C:\Documents and Settings\Owner.ADMIN\Desktop\hosts.txt", "C:\WINDOWS\SYSTEM32\DRIVERS\etc\hosts", 1)

THERE IS NO EXTENSION!!! THERE IS NO WINDOWS FILE TYPE!!! EDIT: there is no spoon...

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

Sorry, a little late on my edit...


Who else would I be?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Disregard that last PM I sent you. Was AFK and returned your PM before reading the topic.

Thanks for all of your help! I appreciate all of it!

It works. Thanks again!

Edited by Py7|-|[]/\/

Share this post


Link to post
Share on other sites

You gotta love a guy that admits when he doesn't know anything, and still thanks you for "flaming" him with help...


Who else would I be?

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You don't understand what I mean when I supposedly "insult" another internet user. It isn't meant to be taken literally, but more as a general "go-with-the-flow" type statement. In reality I appreciate all responses to my posts and appreciate even flames.

Edit: Much like the way that (I think) you mean when you flame.

Edited by Py7|-|[]/\/

Share this post


Link to post
Share on other sites

btw I read the hosts file all the time:

$file="C:\WINNT\system32\drivers\etc\hosts"
$x=fileread($file,Filegetsize($file))
msgbox(1,"Hosts file",$x)

Gets a bit tricky when using non standard extentions with windows, like .htacess and .htpasswd


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
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
Sign in to follow this  
Followers 0