Options

Close Navision (My session)

luisantonioalvarezluisantonioalvarez Member Posts: 5
Hi,

I need to close my session (ALT+F4(to close Nav) or F4 in session list (but with my session=true)) with code in a form.

But I can do it with a function witch send keys (ALT+F4) because my customer dislike it.

Someone now another trip to close Navision?

Thanks,

Tony.

Comments

  • Options
    matttraxmatttrax Member Posts: 2,309
    The "X" in the upper right hand corner? Or do these users have some special permissions that don't let them close a window?
  • Options
    luisantonioalvarezluisantonioalvarez Member Posts: 5
    My problem is that i have to call a form with an URL to do a task in Nav but i need to close the program automaticly when the task end to not use the session all the time.

    I was thinking to call a imput of ALT+F4 but my boss dislike it, i try to close Nav colapsing it filling the memory but this is not a good idea :P., at last, I try to close it calling a *.bat whith a task kill but they not enjoy it,...

    Now i don´t have more ideas,...

    Thank for the reply.
  • Options
    kinekine Member Posts: 12,562
    You can try to create automation which will close the application for you...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    luisantonioalvarezluisantonioalvarez Member Posts: 5
    Ok, what can i do to close the aplication,...?

    It´s possible that we have a user in the computer or not. If there is a user, he can open another window while the task is executing, so an alt+F4 emulation will try to close the active wnidow and not the Nav one.

    And in the task manager i can have several Nav open and i want to close only the one who is executing my task, but all the tasks are named as Fin.exe and i can´t identify which one is mine.

    Now i´m working whith the Alt + F4 emulating but i need another solution.

    Tanks for all!!!!

    Tony.
  • Options
    kinekine Member Posts: 12,562
    You can use this code snippet to create own automation to close the NAV which will call the function...
                public const int WM_CLOSE = 0x0010;
                public const int WM_QUIT = 0x0012;
                [DllImport("User32.dll", CharSet = CharSet.Auto)]
                internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
    ...
            void CloseNAVWindow()
            {
                IntPtr handle;
                handle = GetNAVHandle();
                if (handle != IntPtr.Zero)
                {
                    SendMessage(handle, WM_QUIT, 0, 0);
                    SendMessage(handle, WM_CLOSE, 0, 0);
                }
            }
    
            IntPtr GetNAVHandle()
            {
                System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
                if (!process.MainWindowTitle.Contains("Logo")) //ignore NAV logo window on start-up
                {
                   return process.MainWindowHandle;
                }
                return null;
            }
    
    You can try it, it will send same messge to the application like when you press the Alt+F4.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    luisantonioalvarezluisantonioalvarez Member Posts: 5
    It´s just what i was searching!!!!!!!! It´s perfect.

    Thank you so much!!!!!!

    Bye,

    Tony.
  • Options
    kinekine Member Posts: 12,562
    You are welcome... do not forget, that sometime NAV will ask if you really want to close the client (mainly because modal form is displayed...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    johannajohanna Member Posts: 369
    kine wrote:
    You can use this code snippet to create own automation to close the NAV which will call the function...
                public const int WM_CLOSE = 0x0010;
                public const int WM_QUIT = 0x0012;
                [DllImport("User32.dll", CharSet = CharSet.Auto)]
                internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
    ...
            void CloseNAVWindow()
            {
                IntPtr handle;
                handle = GetNAVHandle();
                if (handle != IntPtr.Zero)
                {
                    SendMessage(handle, WM_QUIT, 0, 0);
                    SendMessage(handle, WM_CLOSE, 0, 0);
                }
            }
    
            IntPtr GetNAVHandle()
            {
                System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
                if (!process.MainWindowTitle.Contains("Logo")) //ignore NAV logo window on start-up
                {
                   return process.MainWindowHandle;
                }
                return null;
            }
    
    You can try it, it will send same messge to the application like when you press the Alt+F4.

    Hi Kine,

    I want to try your codes above in C/AL Code Navision, but still confuse to implement that codes. What automation server do you using? Your codes above are not in C/AL Code language, aren't? How could I close Navision automatically using C/AL Code ?
    Thank you.
    Best regards,

    Johanna
  • Options
    kinekine Member Posts: 12,562
    The code is in C# and you need to create automation with this. You cannot close NAV from C/AL by default. You can only try to send Ctrl+F4 key through SendKeys functionality, but still it is not granted that NAV will close. Why you need that?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    johannajohanna Member Posts: 369
    Hi Kine,

    Thank you for your information.
    I want to close Navision automatically because I don't want the user who is not authorized can login to Navision.
    I have tried to use ERROR to terminate application, but after the ERROR message is appeared, the menusuite is still opened, so I think the other way is close the Navision.
    Do you have another way to prevent user access Navision when this user ID is not authorized?
    Please advice. Thank you :)
    Best regards,

    Johanna
  • Options
    SogSog Member Posts: 1,023
    What is stopping you from using a NAS (and no I do not mean a network attached storage device)?
    Tasks that should run on the background are usually solved by the NAS.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Options
    kinekine Member Posts: 12,562
    johanna wrote:
    Hi Kine,

    Thank you for your information.
    I want to close Navision automatically because I don't want the user who is not authorized can login to Navision.
    I have tried to use ERROR to terminate application, but after the ERROR message is appeared, the menusuite is still opened, so I think the other way is close the Navision.
    Do you have another way to prevent user access Navision when this user ID is not authorized?
    Please advice. Thank you :)

    This was already solved in another post. You can use SQL stored procedure for that if you are on SQL. If not, you can use another way - you need to use SendKeys to close the comany after you will find out that the user do not have permissions to login.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    DakkonDakkon Member Posts: 192
    If you are doing all of this just to run a specific task at certain times, I would recommend what Sog said and just use a Nas. This way you could setup a specific user ID just to run this process, give it appropriate permissions and then the windows service would take care of running your task :)
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • Options
    johannajohanna Member Posts: 369
    @sog & dakkon : thank you for your reply. I don't need to run task in background process. I need to prevent some user from accessing navision when they login..

    @kine : thank you for your suggestion. I have using SQL as my database. I have tried to use sendkeys as below but it did not work.
      var  
      wsShell - Automation - 'Windows Script Host Object Model'.WshShell  
    
      Codeunit 1 add : 
      CREATE(wsShell);
      wsShell.SendKeys('%{F4}');
      CLEAR(wsShell);
    

    I have searched the SQL Stored Procedure, but I just found the procedure to kill session idle user and prevent multiple access from 1 user. I cannot find the procedure to close navision or prevent user to access navision. Could you give me the link about the procedure to close navision or prevent user to access navision? Thank you :)
    Best regards,

    Johanna
  • Options
    kinekine Member Posts: 12,562
    but I just found the procedure to kill session idle user and prevent multiple access from 1 user

    What is the difference between "prevent multiple access" and "prevent access"? It is doing same thing, only with different conditions. You can modify it as you wish... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kinekine Member Posts: 12,562
    And of course, why you just do not disable their permissions to access NAV?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    johannajohanna Member Posts: 369
    Kine, you are right :thumbsup:
    I just modified the query to prevent multiple user so the query can be used to prevent user who is not authorized from accessing Navision.
    Case is closed. Using the stored procedure in SQL is the solution.
    Thank you so much Kine. :)
    Best regards,

    Johanna
  • Options
    kinekine Member Posts: 12,562
    You are welcome! But still, I think that proper solution is to set the permissions correctly for the user to prevent him to login... (or disable his account).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.