How to Restart NAS through CodeUnit

ckndr47ckndr47 Member Posts: 100
Hi everybody,

Just wanted to know; is there any way to restart NAS service from codeunit. If yes then please guide me up;

i have another query as well; i am reading an XML message from MSMQ through NAS and then i m writing tht XML to a file; suddenly due to any error the process gets terminated and file gets locked; now the next time when i would run that file it gives me that LOCKING error. I dont know whts the work around of tht issue.

Thanks in Advance,
Regards

Comments

  • krikikriki Member, Moderator Posts: 9,110
    -run "net stop yournasservice" and then "net start yournasservice".

    -or you can use pskill (www.sysinternals.com) to kill the nas. And if you put in the services properties that the service must be restarted if killed, it will restart automatically after the kill.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ckndr47ckndr47 Member Posts: 100
    Thanks Kirki,

    I know how to restart service from Windows run :) , but i want to restart that service from Navision Codeunit, i hope you getting me.

    Thanks in Advance,
    Regards
  • amunozsuamunozsu Member Posts: 30
    Try with:

    SHELL(TXTCOMANDO, TXTPARAMETRO);

    Where TXTCOMANDO = "%systemroot%\system32\Command.com" and TXTPARAMETRO = "/c Net start NASNAME" or "/c Net stop NASNAME"

    -- Alejandro --
  • krikikriki Member, Moderator Posts: 9,110
    Check also this link for the doscommand:
    http://www.mibuso.com/forum/viewtopic.php?t=12417
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ckndr47ckndr47 Member Posts: 100
    Thanks amunozsu and kriki. Its working now.
  • MiniMini Member Posts: 17
    Hi,

    I used this code to re-start NAS automatically. But I was getting the message "For security reason you are not allow to run following executabels in the shell function when it is passed as a variable".

    I am not sure if I have to do or write some other code to run this command.

    Please suggest.

    Regards
    Mini
  • garakgarak Member Posts: 3,263
    Sorry, but the "Net Start" / "Net Stop" Command works only, on the same machine.

    So a little tip&trick:
    If your NAS is on a other machine and you need to stop him from a other machine which runs the Codeunit, like a Client, you can use the psservice.exe. Also if the nas is on the same machine i use psservice to query the state ...

    So, with following little code you can start / stop / ask for state a service.
    .....
    //01 SysTools Garak +++++++
    ....
    GlobServiceName := ServiceName;
    Command := PSToolPath + '\\' + DNSNameOfServerWhereServiceRun + ' start ' + ServiceName; //start, stop, query
    ServiceStatus := ExecPSTool();
    //here you can create a loop if the Service will be stopped, so you ask, for example 10times the state. If the Service isn't stoped after 10 minutes you can send an error to abort ..
    //01 SysTools Garak -------
    
    //01 SysTools Garak +++++++
    ExecPSTool() : Text[30]
    
    GetService := FALSE;
    
    IF ISCLEAR(WshShell) THEN
      CREATE(WshShell);
    
    WshExec := WshShell.Exec(Command);
    WSHTextStream := WshExec.StdOut;
    
    i := 0;
    CLEAR(State);
    
    WHILE NOT WSHTextStream.AtEndOfStream DO BEGIN
      i := WSHTextStream.Line;
      Line := WSHTextStream.ReadLine();
    
      IF (STRPOS(Line,'SERVICE_NAME: ') <> 0) THEN BEGIN
        LServName := COPYSTR(Line,STRPOS(Line,':') + 2,STRLEN(Line) - STRPOS(Line,':') + 2);
        GetService := LServName = GlobServiceName;
      END;
      
      IF GetService THEN BEGIN
        IF (STRPOS(Line,'STATE') <> 0) THEN BEGIN
          State := COPYSTR(Line,STRPOS(Line,':') + 5,STRLEN(Line) - STRPOS(Line,':') + 4);
        END;
      END;
    
    END;
    CLEAR(WshShell);
    EXIT(State);
    //01 SysTools Garak -------
    

    Regards
    Do you make it right, it works too!
Sign In or Register to comment.