I try to invoke a few win32 APIs in an ASP.net page. But came across some problems.
I am using C#, .net 2.0 and Visual Studio 2005 on WinXP system. The IIS version is 5.1.
In the Page_Load() function, I invoke win32 API FindWindow() to get a window's handle.
When running the page with the Visual Studio Web Server, everything goes fine. But when running it under IIS, FindWindow() fails to get the handle. The error code returned by GetLastError() is 1008. After some googling, I added AspCompat="true" to @Page. Then, the error code changed to 997, which is ERROR_IO_PENDING. I have no idea what's going on here.
I think this is related to privilege problem. So I tried to add this line to the Web.config file: <identity impersonate="true" userName="myuser" password="password" />. And System.Security.Principal.WindowsIdentity.GetCurrent().Name returns the correct username. But still got the same error. Have I missed something??
And from that I have the following question: under IIS, even provided with full access permission, for example impersonating administrator, I can not do anything I like, is that true??
Or put it in another way, as long as the codes can work in Visual Studio Web Server, they will work in IIS if given enough privileges, is that true??
Someone who knows about this please help me. Thanks a lot!!