Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application developed in asp.net. Here i am trying to send data from my application to Catia application (server machine). Its was working fine in visual studio development server, but getting access was not sucessed while running from hosted application on IIS (server machine). Below is my code:

C#
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]



        public static extern long FindWindow(StringBuilder lpClassName, StringBuilder lpWindowName);
        F_hwnd = 0; //Reset Form Handler 
            r_count = 0; //Reset retry count

            if (myCommand == "STL Import") //because the window name is Import
            {
                myCommand = "Import";
            }

    StringBuilder mc = new StringBuilder(myCommand);
    catiaCore.GetSetCatia.StartCommand(myCommand);


            //Searching for Import window 
    while (!(F_hwnd != 0 || (r_count == Retry_fail)))
            {
                F_hwnd = FindWindow(null, mc);//get Import window handler – If Import window is found F_hwnd!=0

        catiaCore.GetSetCatia.ActiveWindow.ActiveViewer.Update();//!
                r_count = r_count + 1;
            }


What I have tried:

I have tried to add Network service, IUSER and IISIUSERS full access rights to Windows/System32 folder where is User32.dll file located, but many errors were appeared. Finally, these users somehow appear as like they have full access rights. I also add full access rights to folder where Catia was installed and enabled 32-bit Application in my Application Pool settings. I also tried to enable 32-bit applications in my Application Pool settings and to define Application Pool Identity, but without results.
Posted
Updated 25-Nov-22 2:15am
v3
Comments
RickZeeland 11-Nov-22 15:29pm    
Are you using multiple monitors maybe? then SendKeys won't work.
Vanja Lukovic 14-Nov-22 5:53am    
Thank you for your commment. No, I don't use multiple monitors at all. Everything is working fine, before I hosted my application on IIS.
RickZeeland 14-Nov-22 6:39am    
Sadly I'm not an ASP.NET developer, but maybe it could be a security thingy?
Vanja Lukovic 16-Nov-22 9:55am    
I suppose also that it is security thingy, but I can't solve it.

Ummm... SendKeys will not work in an ASP.NET application. That code runs entirely on the server, not the client. When you use SendKeys, it's sending the keystrokes to a non-existent window on the server, not the client.

WHen you wrote the code, the server and client were running on the same machine, giving you the illusion of it "working". Once you deployed the code to the production server, the code is running on the server, separate from the client.

Basically, you cannot use SendKeys, and you haven't said why you're trying to use it. You cannot "remote control" an application running on the client from your web app code on the server, nor can you do it from javascript code running in the browser.
 
Share this answer
 
Comments
Vanja Lukovic 23-Nov-22 16:45pm    
Thank you very much for the response, but I am not sure that you understood me. I try to send keys from the Asp. Net application which resides on the server to Catia application which is also on the server maschine. Is it possible or not?
Dave Kreskowiak 23-Nov-22 16:50pm    
Oh I understood.

The reason it will not work, even if both apps are on the same machine is because the web application is running as a service on a completely different desktop than the Catia application. SendKeys will not cross Desktop and Workstation boundaries.

Vanja Lukovic 24-Nov-22 11:16am    
Thank you for the explanation. Do you have an idea, what can I do at all?
I also tried to run the application hosted on IIS on the server machine. I wonder why it didn't also work, even on the same server machine and desktop.
Dave Kreskowiak 24-Nov-22 11:21am    
I already told you why it didn't work, and will never work.

You cannot remotely control a desktop application from a web application. Period. End of story.
Vanja Lukovic 24-Nov-22 14:31pm    
Thank you for the response.
Maybe the suggestions by one of our highly regarded CodeProject members will give you a clue: Sendkeys not working when hosted in IIS[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900