Sign in to follow this  
Followers 0
imacrazyballoono

weird

15 posts in this topic

For some reason that I dont know, the filewrite part of this script will not work in a non admin account. Why?

$time = IniRead("C:\Program Files\Timer\config.txt", "default", "time", "0")
if $time = 0 then
    MsgBox(4096, "Result", "time not found")
endif
$file = fileopen("C:\Program Files\Timer\timer.txt", 2)
filewrite($file, $time)
fileclose($file)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

That's weird.

And just to make it a little shorter:

$time = IniRead("C:\Program Files\Timer\config.txt", "default", "time", "0")
If $time = 0 Then MsgBox(4096, "Result", "time not found")
$file = FileOpen("C:\Program Files\Timer\timer.txt", 2)
FileWrite($file, $time)
FileClose($file)
Edited by AutoItKing

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]

Share this post


Link to post
Share on other sites

just a limited user. I think that is the problem. When i run the script on my admin account, it works fine, but when i run the same one on the limited one, it gives an error.

Share this post


Link to post
Share on other sites

On your admin acct you can change the user permissions so that they can write to that folder. This would probably be easiest if you intend to keep running scripts on a limited acct. Or you could run the script as an admin from the limited acct using RunAs.


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I need this script to be run when the user logs in. I dont think its a permissions error. Ill go get the error right now.

EDIT:

Line 14 filewrite($file, $time)

error: invalid file handle used.

Edited by imacrazyballoono

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Check to make sure FileOpen() does not return -1.

$time = IniRead("C:\Program Files\Timer\config.txt", "default", "time", "0")
If $time = 0 Then MsgBox(4096, "Result", "time not found")
$file = FileOpen("C:\Program Files\Timer\timer.txt", 2)

If $file <> "-1" Then
       FileWrite($file, $time)
       FileClose($file)
Else
       MsgBox( 0, "", "Error opening the file" )
EndIf

That should tell you if there was an error openign the file itself.

EDIT: Fixed issue with code...

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

do you need an endif after the first, or only, if statement?

EDIT: it gave the error, does that mean it is a permission thing?

Edited by imacrazyballoono

Share this post


Link to post
Share on other sites

Now its just being stupid. I logged off the account and changed permissions on the file then logged back into it and it doesnt give the "error opening the file" error. I ran this script and it worked fine with not errors. Why is it not working??? The second script is the one that isn't workng

$time = IniRead("C:\Program Files\Timer\config.txt", "default", "time", "0")
if $time = 0 then
    MsgBox(4096, "Result", "time not found")
endif
$file = fileopen("C:\Program Files\Timer\timer.txt", 2)
filewrite($file, $time)
fileclose($file)

$time = IniRead("C:\Program Files\Timer\config.txt", "default", "time", "0")
If $time = 0 Then MsgBox(4096, "Result", "time not found")
$file = FileOpen("C:\Program Files\Timer\timer.txt", 2)

If $file <> "-1" Then
       FileWrite($file, $time)
       FileClose($file)
Else
       MsgBox( 0, "", "Error opening the file" )
EndIf

FileWrite($file, $time)
FileClose($file)

Share this post


Link to post
Share on other sites

See my modified post above, I included the FileWrite() twice. When you run the script do you get the MsgBox or does it try to write to the file?


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

I have no idea what I or you did, but it works now. My original script works. Thanks for your help.

Share this post


Link to post
Share on other sites

how are you INIreading a txt file?

Share this post


Link to post
Share on other sites

I'm not sure, but it works. Does the format matter of the file as long as the text inside the file is the same?

Share this post


Link to post
Share on other sites

no idea. but in the help file it said "The name of the .INI file you are reading" under INIread

Share this post


Link to post
Share on other sites

I should probably change it to an ini file just to make sure there are no repercussions.

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