Home All Groups Group Topic Archive Search About

NTFS File Access in VB6

Author
10 Mar 2006 5:51 PM
playwin
If user X tries to open foo.txt(path), which he does not have access, with
the following routine:

    Open path For Binary Access Read As 1
    Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
    Close #1

he(and the app) gets:

Runtime Error: Bad file name or number (Error 52)


I think this can be handled as:

On Error GoTo er
.....
.....
er:
if Err.Number=52 Then etc.

Are there any better way?...
--
playwin

Author
10 Mar 2006 6:54 PM
Robert Ellis
Hi,

    I think what you have just there is fine. Why change it?

    If you need to determine explicitly whether or not the security context
in which your application is running has permissions to read a particular
file, there are probably APIs you could use somewhere. But... I doubt it's
worth the effort.

    Robert



Show quoteHide quote
"playwin" <dicussi***@microsoft.com> wrote in message
news:%23BtF8tGRGHA.3916@TK2MSFTNGP11.phx.gbl...
> If user X tries to open foo.txt(path), which he does not have access, with
> the following routine:
>
>    Open path For Binary Access Read As 1
>    Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
>    Close #1
>
> he(and the app) gets:
>
> Runtime Error: Bad file name or number (Error 52)
>
>
> I think this can be handled as:
>
> On Error GoTo er
> ....
> ....
> er:
> if Err.Number=52 Then etc.
>
> Are there any better way?...
> --
> playwin
>
Author
11 Mar 2006 2:52 AM
playwin
Hi,

Thanks, yes I think same there is no need to involve API(if any).

--
playwin

Show quoteHide quote
"Robert Ellis" <robe_2k5.n0s***@hotmail.co.uk> wrote in message
news:ulP6FQHRGHA.1608@TK2MSFTNGP09.phx.gbl...
> Hi,
>
>    I think what you have just there is fine. Why change it?
>
>    If you need to determine explicitly whether or not the security context
> in which your application is running has permissions to read a particular
> file, there are probably APIs you could use somewhere. But... I doubt it's
> worth the effort.
>
>    Robert
>
>
>
> "playwin" <dicussi***@microsoft.com> wrote in message
> news:%23BtF8tGRGHA.3916@TK2MSFTNGP11.phx.gbl...
>> If user X tries to open foo.txt(path), which he does not have access,
>> with the following routine:
>>
>>    Open path For Binary Access Read As 1
>>    Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
>>    Close #1
>>
>> he(and the app) gets:
>>
>> Runtime Error: Bad file name or number (Error 52)
>>
>>
>> I think this can be handled as:
>>
>> On Error GoTo er
>> ....
>> ....
>> er:
>> if Err.Number=52 Then etc.
>>
>> Are there any better way?...
>> --
>> playwin
>>
>
>
Author
10 Mar 2006 6:55 PM
Larry Serflaten
Show quote Hide quote
"playwin" <dicussi***@microsoft.com> wrote
> If user X tries to open foo.txt(path), which he does not have access, with
> the following routine:
>
>     Open path For Binary Access Read As 1
>     Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
>     Close #1
>
> he(and the app) gets:
>
> Runtime Error: Bad file name or number (Error 52)
.........
> Are there any better way?...


First step, isolate the command that gives you the error.

If its the Open command, be sure the path exists, and
read about (and use) FreeFile to get an appropreate file
handle.

If it errors on the InputB line, break that up into individual
steps (read to an array, then convert the array) until you can
determine exactly which command is giving you problems.

After doing that, if you can't fix the error yourself from there,
post back with the new information - Which line, which command
which error, etc...

LFS
Author
11 Mar 2006 2:55 AM
playwin
Show quote Hide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:uAahlQHRGHA.1688@TK2MSFTNGP11.phx.gbl...
>
> "playwin" <dicussi***@microsoft.com> wrote
>> If user X tries to open foo.txt(path), which he does not have access,
>> with
>> the following routine:
>>
>>     Open path For Binary Access Read As 1
>>     Text1.Text = StrConv(InputB$(LOF(1), 1), vbUnicode)
>>     Close #1
>>
>> he(and the app) gets:
>>
>> Runtime Error: Bad file name or number (Error 52)
> ........
>> Are there any better way?...
>
>
> First step, isolate the command that gives you the error.
>
> If its the Open command, be sure the path exists, and
> read about (and use) FreeFile to get an appropreate file
> handle.
>
> If it errors on the InputB line, break that up into individual
> steps (read to an array, then convert the array) until you can
> determine exactly which command is giving you problems.
>
> After doing that, if you can't fix the error yourself from there,
> post back with the new information - Which line, which command
> which error, etc...
>
> LFS
>

Hi Larry,

I think you misunderstood a bit, no there is no coding error, I just wanted
to know are there any better ways to handle file >security access.<

--
playwin