Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
7.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. startafp.cxx
  7. This file contains the code for starting the AFP Service
  8. FILE HISTORY:
  9. NarenG 14-Oct-1992 Stole from srvsvc.cxx in server manager.
  10. */
  11. #define INCL_NET
  12. #define INCL_NETLIB
  13. #define INCL_WINDOWS
  14. #define INCL_WINDOWS_GDI
  15. #define INCL_NETERRORS
  16. #define INCL_DOSERRORS
  17. #include <lmui.hxx>
  18. #define INCL_BLT_WINDOW
  19. #define INCL_BLT_DIALOG
  20. #define INCL_BLT_CONTROL
  21. #define INCL_BLT_CLIENT
  22. #define INCL_BLT_EVENT
  23. #define INCL_BLT_MISC
  24. #define INCL_BLT_MSGPOPUP
  25. #define INCL_BLT_TIMER
  26. #define INCL_BLT_CC
  27. #include <blt.hxx>
  28. #if defined(DEBUG)
  29. static const CHAR szFileName[] = __FILE__;
  30. #define _FILENAME_DEFINED_ONCE szFileName
  31. #endif // DEBUG
  32. #include <uiassert.hxx>
  33. #include <lmsvc.hxx>
  34. #include <lmosrv.hxx>
  35. #include <svcman.hxx> // service controller wrappers
  36. #include <dbgstr.hxx>
  37. extern "C"
  38. {
  39. #include <winsvc.h> // service controller
  40. #include <afpmgr.h>
  41. #include <macfile.h>
  42. #include <mnet.h>
  43. }
  44. #include <startafp.hxx>
  45. /*******************************************************************
  46. NAME: SERVICE_WAIT_DIALOG::SERVICE_WAIT_DIALOG
  47. SYNOPSIS: constructor for SERVICE_WAIT
  48. HISTORY:
  49. ChuckC 07-Sep-1991 Created
  50. ********************************************************************/
  51. SERVICE_WAIT_DIALOG::SERVICE_WAIT_DIALOG( HWND hWndOwner,
  52. LM_SERVICE * plmsvc,
  53. const TCHAR * pszDisplayName )
  54. : DIALOG_WINDOW(MAKEINTRESOURCE( IDD_SERVICE_CTRL_DIALOG),
  55. hWndOwner),
  56. _timer( this, TIMER_FREQ, FALSE ),
  57. _plmsvc(plmsvc),
  58. _progress( this,
  59. IDSC_PROGRESS,
  60. IDI_PROGRESS_ICON_0,
  61. IDI_PROGRESS_NUM_ICONS ),
  62. _sltMessage( this, IDSC_ST_MESSAGE ),
  63. _pszDisplayName( pszDisplayName ),
  64. _nTickCounter( TIMER_MULT )
  65. {
  66. UIASSERT( pszDisplayName != NULL );
  67. if ( QueryError() != NERR_Success )
  68. {
  69. return ;
  70. }
  71. //
  72. // set the message.
  73. //
  74. ALIAS_STR nlsServer( pszDisplayName );
  75. UIASSERT( nlsServer.QueryError() == NERR_Success );
  76. RESOURCE_STR nlsMessage( IDS_STARTING_AFPSERVER_NOW );
  77. APIERR err = nlsMessage.QueryError();
  78. if( err == NERR_Success )
  79. {
  80. ISTR istrServer( nlsServer );
  81. istrServer += 2;
  82. err = nlsMessage.InsertParams( nlsServer[istrServer] );
  83. }
  84. if( err != NERR_Success )
  85. {
  86. ReportError( err );
  87. return;
  88. }
  89. _sltMessage.SetText( nlsMessage );
  90. //
  91. // set polling timer
  92. //
  93. _timer.Enable( TRUE );
  94. }
  95. /*******************************************************************
  96. NAME: SERVICE_WAIT_DIALOG::~SERVICE_WAIT_DIALOG
  97. SYNOPSIS: destructor for SERVICE_WAIT_DIALOG. Stops
  98. the timer if it has not already been stopped.
  99. HISTORY:
  100. ChuckC 07-Sep-1991 Created
  101. ********************************************************************/
  102. SERVICE_WAIT_DIALOG::~SERVICE_WAIT_DIALOG( void )
  103. {
  104. _timer.Enable( FALSE );
  105. }
  106. /*******************************************************************
  107. NAME: SERVICE_WAIT_DIALOG::OnTimerNotification
  108. SYNOPSIS: Virtual callout invoked during WM_TIMER messages.
  109. ENTRY: tid - TIMER_ID of this timer.
  110. HISTORY:
  111. KeithMo 06-Oct-1991 Created.
  112. ********************************************************************/
  113. VOID SERVICE_WAIT_DIALOG :: OnTimerNotification( TIMER_ID tid )
  114. {
  115. //
  116. // Bag-out if it's not our timer.
  117. //
  118. if( tid != _timer.QueryID() )
  119. {
  120. TIMER_CALLOUT :: OnTimerNotification( tid );
  121. return;
  122. }
  123. //
  124. // Advance the progress indicator.
  125. //
  126. _progress.Advance();
  127. //
  128. // No need to continue if we're just amusing the user.
  129. //
  130. if( --_nTickCounter > 0 )
  131. {
  132. return;
  133. }
  134. _nTickCounter = TIMER_MULT;
  135. //
  136. // Poll the service to see if the operation is
  137. // either complete or continuing as expected.
  138. //
  139. BOOL fDone;
  140. APIERR err = _plmsvc->Poll( &fDone );
  141. if (err != NERR_Success)
  142. {
  143. //
  144. // Either an error occurred retrieving the
  145. // service status OR the service is returning
  146. // bogus state information.
  147. //
  148. Dismiss( err );
  149. return;
  150. }
  151. if( fDone )
  152. {
  153. //
  154. // The operation is complete.
  155. //
  156. Dismiss( NERR_Success );
  157. return;
  158. }
  159. //
  160. // If we made it this far, then the operation is
  161. // continuing as expected. We'll have to wait for
  162. // the next WM_TIMER message to recheck the service.
  163. //
  164. } // SERVICE_WAIT_DIALOG :: OnTimerNotification
  165. /*******************************************************************
  166. NAME: StartAfpService
  167. SYNOPSIS: Starts the Afp Service on the local machine.
  168. ENTRY: hWnd - "Owning" window handle.
  169. pszComputerName - name of machine to start service on
  170. RETURNS: APIERR - Any error encountered.
  171. HISTORY:
  172. NarenG 1-Oct-1992 Stole from original.
  173. ********************************************************************/
  174. APIERR StartAfpService( HWND hWnd, const TCHAR * pszComputerName )
  175. {
  176. AUTO_CURSOR AutoCursor;
  177. LM_SERVICE * psvc = new LM_SERVICE( pszComputerName,
  178. (const TCHAR *)AFP_SERVICE_NAME );
  179. APIERR err = ( psvc == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  180. : psvc->QueryError();
  181. if (err == NERR_Success)
  182. {
  183. //
  184. // Initiate the Start
  185. //
  186. err = psvc->Start( NULL, POLL_TIMER_FREQ, POLL_DEFAULT_MAX_TRIES );
  187. if ( err == NERR_Success )
  188. {
  189. UINT errDlg = NERR_Success;
  190. //
  191. // Invoke the wait dialog.
  192. //
  193. SERVICE_WAIT_DIALOG * pDlg = new SERVICE_WAIT_DIALOG(
  194. hWnd,
  195. psvc,
  196. pszComputerName );
  197. err = ( pDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  198. : pDlg->Process( &errDlg );
  199. if( err == NERR_Success )
  200. {
  201. delete pDlg;
  202. err = (APIERR)errDlg;
  203. }
  204. delete psvc;
  205. }
  206. }
  207. return err;
  208. } // StartAfpService
  209. /*******************************************************************
  210. NAME: IsAfpServiceRunning
  211. SYNOPSIS: Checks to see if the AfpService is running on a given
  212. machine.
  213. ENTRY: hWnd - "Owning" window handle.
  214. RETURNS: APIERR - Any error encountered.
  215. HISTORY:
  216. NarenG 1-Oct-1992 Stole from original.
  217. ********************************************************************/
  218. APIERR IsAfpServiceRunning( const TCHAR * pszComputer, BOOL * fIsAfpRunning )
  219. {
  220. LPSERVICE_INFO_1 psvci1;
  221. DWORD err;
  222. SERVER_1 Server1( pszComputer );
  223. if ( ( err = Server1.GetInfo() ) != NERR_Success )
  224. {
  225. return err;
  226. }
  227. if ( !(Server1.QueryServerType() & SV_TYPE_NT ) )
  228. {
  229. return IDS_NOT_NT;
  230. }
  231. //
  232. // Find out if the AFP service is running on the given machine
  233. //
  234. err = ::MNetServiceGetInfo( pszComputer,
  235. (const TCHAR *)AFP_SERVICE_NAME,
  236. 1,
  237. (BYTE **)&psvci1 );
  238. if ( err == NERR_BadServiceName )
  239. {
  240. return IDS_MACFILE_NOT_INSTALLED;
  241. }
  242. if( err != NERR_Success )
  243. {
  244. return err;
  245. }
  246. *fIsAfpRunning = (BOOL)(psvci1->svci1_status & SERVICE_INSTALLED);
  247. ::MNetApiBufferFree( (BYTE **)&psvci1 );
  248. return err;
  249. }