How to close Navision Application through code

Hi, Does anybody know how to close Navision Application through code. Is there anyway we can write some code in Codeunit 1. Please help if anybody has some idea. Thanx in advance. Vijay

Hi Vijay, You could create an error which crashes Navision consistently… And call this error when you want to close Navision. [8D]. Or call a program like enditall which can end the application.

In Navision 3.70 (SQL only) and in Navision 4.0 (SQL and C/Side) you can at least kill the current session (meaning kicking you out of the database). To kill your database session just set a filter to the “My Session” field in the Session table and delete the record. That’s it. to kill Navision client as an application you would need to send a WM_Close command to the Navision Application. The problem with “crashing” the client to close Navision is that the session will remain active and still consume a user.

quote:

The problem with “crashing” the client to close Navision is that the session will remain active and still consume a user.

Whoops… [:I] Sorry for the wrong advice. Although it was kind of a joke. [;)]

maybe you could use the “Windows Scripting Host” to send a “Alt+F4” & stuff … Or you could kill the NAVISION process e.g. by executing “TaskTerminator” (http://www.zeasoft.com/products/taskterm.htm) via SHELL command …

quote:

maybe you could use the “Windows Scripting Host” to send a “Alt+F4” & stuff …

This might cause problems (depending in what window the user is currently. If you just want to prevent a user from signing in a second time, this works perfectly. If you want to kill Navision at a later point and you have a modal window running you will get an error message when pressing Alt+F4 (or sending it to the keyboard buffer). So in this case you need to send some Esc before. If no window is open, it is no problem for Navision to receive Escape.

Firstly why do you want to do this? If its because you don’t want to train your users how to corectly use Navision, then look at the expandit soution, this seems to work well.

This will work just nice. Call it (together with some other code) in cu1.LoginStart CREATE(WindowsShell); WindowsShell.SendKeys(’%{F4}’); CLEAR(WindowsShell); This will end the client. It’s quite useful in some situations to control no. of sessions.

Thanx Lars for your piece of code. It meets the user requirement. Thanx once again…

hi i hope u can close NAS throu a Batch file or you can write a Windows Script to close that windows service. now you can execute that script in Codeunit 1 by using Shell Function of navision. i hope this will work

Hi,

I’m new in c/al programming.

Can you tell me which globals or/and locals I need to create for this piece of code ?

Thx

Locutus

hi Lars,

Could you please Explain in Detail how to do this ?

WindowsShell is which type variable and when should write code.

Please Reply as Soon as Possible.

Thanks

Dipak

hi Lars,

Could you please Explain in Detail how to do this ?

WindowsShell is which type variable and when should write code.

Please Reply as Soon as Possible.

Thanks

Dipak

Hi

Go to View C/AL Globals & the create a Variable

Varaible DataType Subtype

WindowsShell Automation ‘Windows Script Host Object Model’.WshShell

For searching subtype ( you have to drill down & in Automation server select Windows Script Host Object Model from drill down & after that you will find WshShell.

Hope it’s help you