Run cmd line as admin

manthonylugomanthonylugo Member Posts: 46
edited 2020-02-20 in NAV Three Tier
Hi Expert,

Am trying to run net stop && net start for restarting NavInstance but I always encountered error "Access is Denied". Does anyone tried doing this successfully?

Here are my codes:

Process := Process.Process;
Process.StartInfo.UseShellExecute := FALSE;
Process.StartInfo.FileName := 'cmd.exe';
Process.StartInfo.Arguments := '/c NET STOP MicrosoftDynamicsNavServer$InstanceName && NET START MicrosoftDynamicsNavServer$InstanceName';
Process.StartInfo.CreateNoWindow := TRUE;
Process.StartInfo.RedirectStandardError := TRUE;
Process.Start();
ErrMsg := Process.StandardError.ReadToEnd();
IF ErrMsg <> '' THEN
ERROR(ErrMsg)
ELSE BEGIN
Result := Process.StandardOutput.ReadToEnd();
END;
CLEAR(Process);

3wicbluzin0p.png

Is there a way to run this as an admin?

Thank you,
Marc

Answers

  • edoderooedoderoo Member Posts: 89
    I created a *.bat file on the application server (where the service tiers are running).
    I would not suggest to run this out of NAV itself, if it was only because the connection will close anyways when the service tier is restarted.
    IF User.Loves('Edo') THEN ok() ELSE currReport.genSkip;
  • manthonylugomanthonylugo Member Posts: 46
    Hi Edo,

    Thanks for your reply! Am fully aware on that, Reason why I want to do it on NAV is I want to restart the services with a certain condition and have it run on the Job queue. I tried it also to put the command line in the batch file and call it NAV but still getting the same error :'(
  • edoderooedoderoo Member Posts: 89
    Windows (server) has an excellent scheduler. My service tiers reboot/restart every night at 4:00 AM.
    The good thing about restarting them regularly, is that you are sure that all events are up and running. In theory this should not be necessary, but that is just theory. Events every now and then "collapse", a restart will fire them up again.
    IF User.Loves('Edo') THEN ok() ELSE currReport.genSkip;
  • manthonylugomanthonylugo Member Posts: 46
    > @edoderoo said:
    > Windows (server) has an excellent scheduler. My service tiers reboot/restart every night at 4:00 AM.
    > The good thing about restarting them regularly, is that you are sure that all events are up and running. In theory this should not be necessary, but that is just theory. Events every now and then "collapse", a restart will fire them up again.

    Agreed, but having it run on windows scheduler would means I will lose control on restarting of services, it will just keep restarting and restarting.. What am planning was when NAV finds an over due InProcess in Job queue logs it will marked it as an error then that's the time system will call the restarting of services (This process will run on job queue). Unless I could enable/disable the windows scheduler? That would solve my problem.. 🤔🤔🤔 Maybeeee, that could work let me look into that also. lol!
  • edoderooedoderoo Member Posts: 89
    when you want to kill a certain process, you can look for the session in the session table (somewhere over 2.000.000.000 as table number) and delete the corresponding record there.
    IF User.Loves('Edo') THEN ok() ELSE currReport.genSkip;
  • JuhlJuhl Member Posts: 724
    StartInfo.Verb = ‘runas’;
    Follow me on my blog juhl.blog
Sign In or Register to comment.