Declare Function GetCurrentProcessId Lib "kernel32" Alias "GetCurrentProcessId" () As Long;
Declare Function GetModuleFileNameEx Lib "psapi.dll" Alias "GetModuleFileNameExA" (hProcess As Long, hModule As Long, lpFilename As Long, nSize As Long) As Long;
Declare Function OpenProcess Lib "kernel32" (dwDesiredAccess As Long, bInheritHandle As Long, dwProcessId As Long) As Long;
Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Long;

Sub Main()
End sub

Sub Restart_PcVue()

      Dim SvProjectsPath as str;
      Dim SvProjectPath as str;
      Dim SvProjectName as str;
      Dim SvPath As Str   ;        'Path of sv32.exe
      Dim SvRestartPath As Str ;     'Path of SvRestart.exe
      Dim CommandLine As Str ;      'Shell Command line
      Dim Args As Str;             'Arguments for SvRestart.exe
      Dim MyId As Long ;          'Process Id of Pcvue32 get by system Dll
      Dim i as integer;
      dim sMsg as str;			'Message to display

      MyId = GetCurrentProcessId() ;

      SvProjectPath = GETPROJECTDIR();
      SvPath =ADDSTRING (  "\"" ,  ADDSTRING (     GetSvPath ( MyId )   ,   "\"") );

      While (    ASC(  Right(  SvProjectPath , i++)  )  !=   ASC("\\")   )
      Wend

      SvProjectName = ADDSTRING ("|"  ,  ADDSTRING (Right( SvProjectPath , i - 2)  ,   "|" ))  ;
      SvProjectsPath = ADDSTRING ("|"  ,  ADDSTRING  (Left ( SvProjectPath , LEN (SvProjectPath ) - LEN (ADDSTRING ("USR" , SvProjectName))) , "|" )) ;
      SvRestartPath = ADDSTRING (SvProjectPath  , "\\TP\\svrestart.exe" );

      Args = ADDSTRING ( " "  ,  TOC(MyId) );
      Args = ADDSTRING (Args , ADDSTRING (  " "         , SvPath              )  );
      Args = ADDSTRING (Args , ADDSTRING (  " \"-b "  , SvProjectsPath  ));
      Args = ADDSTRING (Args , ADDSTRING (  " -p "     , SvProjectName )  );
      Args = ADDSTRING (Args ,   "\""   );

     sMsg = ADDSTRING (" Restart via SCADA Basic: Project " , SvProjectName );
     sMsg = ADDSTRING ( " \""   ,   ADDSTRING (sMsg ,   "\"" ) ) ;

     APPLICATION("LOAD", SvRestartPath, ADDSTRING   ( Args, sMsg ) );
    SYSTEM("EXIT");

end sub

 

 

'Function that returns SvPath according to SvProcessId

Sub GetSvPath(ProcessID)

      dim lBufProc as long;
      dim lBufName as long;
      dim lMaxSize as long;
      dim sRet as str;

      lMaxSize = 255;
      lBufName  = ALLOC_BUFFER( lMaxSize );
      lBufProc  = OpenProcess(  1040 , 0  , ProcessID );
      GetModuleFileNameEx(   lBufProc , 0, lBufName  , lMaxSize );
      CloseHandle( lBufProc  );
      sRet = LTRIM (CGET_BUFFER( lBufName  , 0, lMaxSize ));

      FREE_BUFFER (lBufName);
      Return ( sRet );

end sub

 


















