Home » Category » Software & Application Miscellaneous

Software & Application Miscellaneous: ZwOpenFile helppppppppp

205| Tue, 20 May 2008 08:03:00 GMT| anonymous| Comments (5)
Hi all !
I must Open a file in my Driver , The fragment code as below . But it always can not be opened .. Pls tell me why '
Thanks in advance !

HANDLE fileOpen;
OBJECT_ATTRIBUTES objAttr;
UNICODE_STRING sLinkName;
#define FILE_NAME L"C:\\test.out"
RtlInitUnicodeString( &sLinkName, FILE_NAME);

KIRQL oldIrql,
newIrql = PASSIVE_LEVEL;
KeRaiseIrql(newIrql,&oldIrql);
InitializeObjectAttributes(
&objAttr,
&sLinkName,
OBJ_KERNEL_HANDLE,
NULL,
NULL);

LARGE_INTEGER nSize;
IO_STATUS_BLOCK ioStat;

NTSTATUS statusOpen = ZwOpenFile(
OUT &fileOpen,
IN FILE_READ_DATA | FILE_WRITE_DATA,
IN &objAttr,
OUT &ioStat,
IN FILE_SHARE_READ,
IN FILE_NON_DIRECTORY_FILE
);

Keywords & Tags: zwopenfile, helppppppppp, software, application

URL: http://software.itags.org/software-application/240742/
 
«« Prev - Next »» 5 helpful answers below.
Alex
You did not specify how exactly did the ZwOpenFile failed, more details could be useful..
You cannot access files with this path, try \\'\\C:\\test.out
Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you aren't already ther
you should not try to use the ZwOpenFile

G

anonymous | Tue, 20 May 2008 08:05:00 GMT |

Thank you so much ! Gram !
In fact , I must Open COM port in my driver , but I tried to open a normal
file first, and have not openned it . So I do not understand why .
I have deleted the lines KeRaiseIrdl . And tried with path
\\'\\C:\\test.out . and always get errors. Maybe in
InitializeObjectAttrbutes'
If you have any idea about openning COM port , pls help me directly with COM
. I am now very confuse .
Waiting for help from you !
Thank you so much !

HANDLE fileOpen;
OBJECT_ATTRIBUTES objAttr;
UNICODE_STRING sLinkName;
#define COM_NAME L"\\'\\C:\\test.out"
RtlInitUnicodeString( &sLinkName, COM_NAME);

InitializeObjectAttributes(
&objAttr,
&sLinkName,
OBJ_EXCLUSIVE,
NULL,
NULL);

LARGE_INTEGER nSize;
IO_STATUS_BLOCK ioStat;

NTSTATUS statusOpen = ZwOpenFile(
OUT &fileOpen,
IN FILE_READ_DATA | FILE_WRITE_DATA,
IN &objAttr,
OUT &ioStat,
IN FILE_SHARE_READ,
IN FILE_NON_DIRECTORY_FILE
);

DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=C000000D.

"Gram" <anonymous...discussions.microsoft.com> wrote in message
news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
> Alex,
> You did not specify how exactly did the ZwOpenFile failed, more details
could be useful...
> You cannot access files with this path, try \\'\\C:\\test.out.
> Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
aren't already there
> you should not try to use the ZwOpenFile?
> G.
>

alex | Tue, 20 May 2008 08:06:00 GMT |

NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"

So, double check your parameters, re-read the ddk documentation for
ZwOpenFile, and, don' use something you don't understand or didn't check out
in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?

Did you looked in DDK what OBJ_EXCLUSIVE is used for?

"Alex" <Chipheo2k...hotmail.com> wrote in message
news:ujGwCnvREHA.3660...tk2msftngp13.phx.gbl...

> Thank you so much ! Gram !
> In fact , I must Open COM port in my driver , but I tried to open a
normal
> file first, and have not openned it . So I do not understand why .
> I have deleted the lines KeRaiseIrdl . And tried with path
> \\'\\C:\\test.out . and always get errors. Maybe in
> InitializeObjectAttrbutes'
> If you have any idea about openning COM port , pls help me directly with
COM
> . I am now very confuse .
> Waiting for help from you !
> Thank you so much !
> HANDLE fileOpen;
> OBJECT_ATTRIBUTES objAttr;
> UNICODE_STRING sLinkName;
> #define COM_NAME L"\\'\\C:\\test.out"
> RtlInitUnicodeString( &sLinkName, COM_NAME);
> InitializeObjectAttributes(
> &objAttr,
> &sLinkName,
> OBJ_EXCLUSIVE,
> NULL,
> NULL);
> LARGE_INTEGER nSize;
> IO_STATUS_BLOCK ioStat;
>
> NTSTATUS statusOpen = ZwOpenFile(
> OUT &fileOpen,
> IN FILE_READ_DATA | FILE_WRITE_DATA,
> IN &objAttr,
> OUT &ioStat,
> IN FILE_SHARE_READ,
> IN FILE_NON_DIRECTORY_FILE
> );
>
> DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> C000000D.
>
>
>
> "Gram" <anonymous...discussions.microsoft.com> wrote in message
> news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
> > Alex,
> > You did not specify how exactly did the ZwOpenFile failed, more details
> could be useful...
> > You cannot access files with this path, try \\'\\C:\\test.out.
> > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
> aren't already there
> > you should not try to use the ZwOpenFile?
> >
> > G.
> >
>

alex | Tue, 20 May 2008 08:07:00 GMT |

Thank Alex!
So which value must be used for it ?
For a normal file ( text file ) , and for a Device ( Comm Port ) . I only
tried to pass different values to get true result . In DDK wrote nothing
about it !
damm ..

"Alex the 1'ts" <AlX...a> wrote in message
news:OrgLnzxREHA.2496...TK2MSFTNGP11.phx.gbl...
> NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"
> So, double check your parameters, re-read the ddk documentation for
> ZwOpenFile, and, don' use something you don't understand or didn't check
out
> in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?
> Did you looked in DDK what OBJ_EXCLUSIVE is used for?
>
> "Alex" <Chipheo2k...hotmail.com> wrote in message
> news:ujGwCnvREHA.3660...tk2msftngp13.phx.gbl...
> > Thank you so much ! Gram !
> > In fact , I must Open COM port in my driver , but I tried to open a
> normal
> > file first, and have not openned it . So I do not understand why .
> > I have deleted the lines KeRaiseIrdl . And tried with path
> > \\'\\C:\\test.out . and always get errors. Maybe in
> > InitializeObjectAttrbutes'
> > If you have any idea about openning COM port , pls help me directly with
> COM
> > . I am now very confuse .
> > Waiting for help from you !
> > Thank you so much !
> >
> > HANDLE fileOpen;
> > OBJECT_ATTRIBUTES objAttr;
> > UNICODE_STRING sLinkName;
> > #define COM_NAME L"\\'\\C:\\test.out"
> > RtlInitUnicodeString( &sLinkName, COM_NAME);
> >
> > InitializeObjectAttributes(
> > &objAttr,
> > &sLinkName,
> > OBJ_EXCLUSIVE,
> > NULL,
> > NULL);
> >
> > LARGE_INTEGER nSize;
> > IO_STATUS_BLOCK ioStat;
> >
> >
> > NTSTATUS statusOpen = ZwOpenFile(
> > OUT &fileOpen,
> > IN FILE_READ_DATA | FILE_WRITE_DATA,
> > IN &objAttr,
> > OUT &ioStat,
> > IN FILE_SHARE_READ,
> > IN FILE_NON_DIRECTORY_FILE
> > );
> >
> >
> > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> > C000000D.
> >
> >
> >
> >
> >
> >
> > "Gram" <anonymous...discussions.microsoft.com> wrote in message
> > news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
> > > Alex,
> > > You did not specify how exactly did the ZwOpenFile failed, more
details
> > could be useful...
> > > You cannot access files with this path, try \\'\\C:\\test.out.
> > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
you
> > aren't already there
> > > you should not try to use the ZwOpenFile?
> > >
> > > G.
> > >
> >
> >
>

alex | Tue, 20 May 2008 08:08:00 GMT |

> > > InitializeObjectAttributes(
> > > &objAttr,
> > > &sLinkName,
> > > OBJ_EXCLUSIVE,
> > > NULL,
> > > NULL);

Why do you use OBJ_EXCLUSIVE? This flas IS documented in the DDK, did you
look at it?

> > >
> > > LARGE_INTEGER nSize;
> > > IO_STATUS_BLOCK ioStat;
> > >
> > >
> > > NTSTATUS statusOpen = ZwOpenFile(
> > > OUT &fileOpen,
> > > IN FILE_READ_DATA | FILE_WRITE_DATA,
> > > IN &objAttr,
> > > OUT &ioStat,
> > > IN FILE_SHARE_READ,
> > > IN FILE_NON_DIRECTORY_FILE
> > > );

ZwOpenFile IS well documented in the DDK, did you read the documentation
carefully? Even at a glance I can see a wrong parameter.
If the OS tells you, you used same invalid parameters, you better belive it.
Now, why don't you look in the DDK and see for yourself?

> > >
> > >
> > > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=> > > C000000D.
> > >
> > >
> > >
> > >
> > >
> > >
> > > "Gram" <anonymous...discussions.microsoft.com> wrote in message
> > > news:FF8EF646-4089-4998-B330-E7F53392341E...microsoft.com...
> > > > Alex,
> > > > You did not specify how exactly did the ZwOpenFile failed, more
> details
> > > could be useful...
> > > > You cannot access files with this path, try \\'\\C:\\test.out.
> > > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
> you
> > > aren't already there
> > > > you should not try to use the ZwOpenFile?
> > > >
> > > > G.
> > > >
> > >
> > >
> >
> >
>

alex | Tue, 20 May 2008 08:09:00 GMT |

Software & Application Miscellaneous Hot Answers

Software & Application Miscellaneous New questions

Software & Application Miscellaneous Related Categories