Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I/O Error problems

Status
Not open for further replies.

Snaples

Programmer
May 7, 2007
16
IL
I made this program that downloads a small 5kb html file from the internet, reads from it and deletes it.

when i give it to other people to test the application on their computer, some of them (not all of them... on my computer it works perfectly fine) get an I/O error...(that they dont have the right access to the file blah blah blah).

in my program i use a file download from the internet :

"
function GetInetFile (const fileURL, FileName: String): boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
result := false;
sAppName := ExtractFileName(Application.ExeName) ;
hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
try
hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
try
AssignFile(f, FileName) ;
Rewrite(f,1) ;
repeat
InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ;
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f) ;
result := True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end;
GetInetFile := result ;
end;
"

and after the file is downloaded i use a regular AssignFile, Reset and Close commands to read from it...

How can I fix this problem?
Anyone familiar with this kind of error?

Help would be grately appreciated!!
Thanks a bunch in advance!
 
do these users have administrative rights?
if not do they have the permission to write/change this file at its location??

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
How do I check those things?
**Excuse me for being noobish**
 
if the user has no administrative rights (= restricted access) he can only create/modify/delete files at a certain location. try to save your file in this path:

C:\Documents and Settings\<username>\Local Settings\Application Data\<your application name>\

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
How can i get the username?
and im supposed to make the directory of my application?
if yes, then how?

Thank you so much for your help, it means the world!
 
How can i get the username?
Code:
function UserName : string;
const
  cnMaxLen=254;
var
  sUserName     : string;
  dwUserNameLen : DWord;
begin
  dwUserNameLen:=cnMaxLen-1;
  SetLength(sUserName, cnMaxLen);
  GetUserName(Pchar(sUserName), dwUserNameLen);
  SetLength(sUserName, dwUserNameLen);
  result:= sUserName;
  if dwUserNameLen = cnMaxLen-1 then
    result:='';
end;
and im supposed to make the directory of my application?
Yes, you should. Or at lease a location to download the file to. "C:\Documents and Settings\<user name>\Local Settings\Temp\" should also be a safe location where users have read/write/delete permissions.
if yes, then how?
Code:
  if ForceDirectories('"C:\Documents and Settings\' + UserName + '\Local Settings\Application Data\' + [red]<your application name goes here>[/red] + '\"') then 
    showmessage('directory created.')
  else
    showmessage('directory already exists or error occured.')

The double-quotes may or may not be required. I didn't test it but this should get you going.


Roo
Delphi Rules!
 
Wow, THANK YOU GUYS SOOOOOOOOOOOOOO MUCH!!!
this forum is awsome!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top