Leaked source code of windows server 2003
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.

794 lines
28 KiB

  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. '-------------------------------------------------------------------------
  5. 'services.asp: Serves in Displaying the Server appliance managed services
  6. '
  7. ' Copyright (c) Microsoft Corporation. All rights reserved.
  8. '
  9. ' Date Description
  10. ' 12-mar-2001 Creation date
  11. ' 15-mar-2001 Modified date
  12. '-------------------------------------------------------------------------
  13. %>
  14. <!-- #include virtual="/admin/inc_framework.asp" -->
  15. <!-- #include virtual="/admin/ots_main.asp" -->
  16. <!-- #include file="loc_services.asp" -->
  17. <%
  18. '-------------------------------------------------------------------------
  19. ' Global Constants
  20. '-------------------------------------------------------------------------
  21. Dim SOURCE_FILE
  22. SOURCE_FILE = SA_GetScriptFileName()
  23. 'constant to get the services from the container
  24. Const CONST_SERVICES_CONTAINER = "SERVICES"
  25. Const CONST_OTS_COLUMN_ALIGN = "left"
  26. Const CONST_REFRESH_INTERVAL = 30
  27. '-------------------------------------------------------------------------
  28. ' Global Variables
  29. '-------------------------------------------------------------------------
  30. Dim rc 'Return value for CreatePage
  31. Dim page 'Variable that receives the output page
  32. 'frame work variables for sorting
  33. Dim g_iSortCol
  34. Dim g_sSortSequence
  35. '======================================================
  36. ' Entry point
  37. '======================================================
  38. ' Create Page
  39. rc = SA_CreatePage( L_SERVICES_OTS_TABLE_CAPTION, "", PT_AREA, page )
  40. ' Show page
  41. rc = SA_ShowPage( page )
  42. '---------------------------------------------------------------------
  43. ' Function name: OnInitPage
  44. ' Description: Called to signal first time processing for this page.
  45. ' Input Variables: oPageIn and oEventArg
  46. ' Output Variables: oPageIn and oEventArg
  47. ' Return Values: TRUE to indicate initialization was successful. FALSE to indicate
  48. ' errors. Returning FALSE will cause the page to be abandoned.
  49. ' Global Variables: None
  50. ' Called to signal first time processing for this page. Use this method
  51. ' to do first time initialization tasks.
  52. '---------------------------------------------------------------------
  53. Public Function OnInitPage(ByRef oPageIn, ByRef oEventArg)
  54. 'Set the page refresh interval to 30sec
  55. Call SA_SetPageRefreshInterval(page, CONST_REFRESH_INTERVAL)
  56. 'Check for service task requested - enable or disable
  57. Call ServiceTaskClick()
  58. Call SA_TraceOut(SOURCE_FILE, "OnInitPage")
  59. ' Set default values
  60. '
  61. ' Sort first column in ascending sequence
  62. g_iSortCol = 1
  63. g_sSortSequence = "A"
  64. OnInitPage = TRUE
  65. End Function
  66. '---------------------------------------------------------------------
  67. ' Function name: OnServeAreaPage
  68. ' Description: Called when the page needs to be served.
  69. ' Input Variables: oPageIn, oEventArg
  70. ' Output Variables: oPageIn and oEventArg
  71. ' Return Values: TRUE to indicate no problems occured. FALSE to indicate errors.
  72. ' Returning FALSE will cause the page to be abandoned.
  73. ' Global Variables: In:g_bPageChangeRequested,g_sPageAction,
  74. ' g_bSearchRequested,g_iSearchCol,g_sSearchColValue
  75. ' In:L_(*)-Localization Strings
  76. ' Called when the page needs to be served. Use this method to serve content.
  77. '---------------------------------------------------------------------
  78. Public Function OnServeAreaPage(ByRef oPageIn, ByRef oEventArg)
  79. 'getting the managed services that are installed in the system
  80. '(intersection of wmi and registry)
  81. OnServeAreaPage = GetServices()
  82. End Function
  83. '---------------------------------------------------------------------
  84. ' Function: OnSortNotify()
  85. ' Description: Sorting notification event handler.
  86. ' Input Variables: oPageIn,oEventArg,sortCol,sortSeq
  87. ' Output Variables: oPageIn,oEventArg
  88. ' Return Values: Always returns TRUE
  89. ' Global Variables: G_*
  90. '---------------------------------------------------------------------
  91. Public Function OnSortNotify(ByRef oPageIn, _
  92. ByRef oEventArg, _
  93. ByVal iSortCol, _
  94. ByVal sSortSeq )
  95. OnSortNotify = TRUE
  96. Call SA_TraceOut(SOURCE_FILE, "OnSortNotify")
  97. g_iSortCol = iSortCol
  98. g_sSortSequence = sSortSeq
  99. End Function
  100. '-------------------------------------------------------------------------
  101. ' Function name: GetServices
  102. ' Description: Gets the services and displays the
  103. ' services onto the page
  104. ' Input Variables: None
  105. ' Output Variables: None
  106. ' Return Values: Returns collection of elements under the container
  107. ' Global Variables: G_*,L_*
  108. '-------------------------------------------------------------------------
  109. Function GetServices()
  110. Err.Clear
  111. On Error resume next
  112. Dim tableServices 'table object
  113. Dim nReturnValue 'return value
  114. Dim objElement 'variable for reg element
  115. Dim objManagedServices 'object for getting services
  116. Dim objServiceSet 'services list
  117. Dim arrManagedServices() 'array for getting the services from system
  118. Dim nServiceCount 'count variable
  119. Dim strWMIpath 'wmi path
  120. Dim i 'count
  121. Dim intcount 'count variable
  122. Dim intArrIndex 'index variable
  123. Dim arrServices() 'array for getting the services from registry
  124. Dim colFlags 'variable to define column types
  125. Dim objWMIService 'wmi connection object
  126. Dim objService 'service object
  127. Dim sTaskURL 'Holds the URL for the task button
  128. 'variables for getting service properties
  129. Dim strArrServiceName
  130. Dim strArrServiceDisplayName
  131. Dim strArrServiceStatus
  132. Dim strArrServiceStartupType
  133. Dim strArrServiceDescription
  134. Dim strArrNonlocalisedServiceStatus
  135. Dim strArrNonlocalisedServiceStartupType
  136. Dim strReturnTo
  137. 'variables for dynaminc tasks
  138. Dim rows
  139. Dim tasks
  140. 'constants used for string comparisions.
  141. Const CONST_STOPPED = "stopped"
  142. Const CONST_RUNNING = "running"
  143. Const CONST_PAUSED = "paused"
  144. Const CONST_STOPPENDING = "stop pending"
  145. Const CONST_STARTPENDING = "start pending"
  146. Const CONST_MANUAL = "manual"
  147. Const CONST_AUTOMATIC = "auto"
  148. Const CONST_DISABLED = "disabled"
  149. 'initialisation
  150. intArrIndex = 0
  151. intcount= 0
  152. nServiceCount = 0
  153. 'WMI path
  154. strWMIpath = "select * from Win32_Service where "
  155. 'getting the services
  156. Set objManagedServices = SA_GetElements(CONST_SERVICES_CONTAINER)
  157. For Each objElement In objManagedServices
  158. redim preserve arrManagedServices(6, nServiceCount)
  159. 'In 2.1 on XPE, there is only one website. We won't display the shared http protocol.
  160. if Ucase(objElement.GetProperty("ServiceName")) <> "W3SVC" Or _
  161. CONST_OSNAME_XPE <> GetServerOSName() Then
  162. arrManagedServices(0, nServiceCount) = objElement.GetProperty("ServiceName")
  163. arrManagedServices(1, nServiceCount) = objElement.GetProperty("URL")
  164. arrManagedServices(2, nServiceCount) = objElement.GetProperty("ServiceNameRID")
  165. arrManagedServices(3, nServiceCount) = objElement.GetProperty("ServiceDescRID")
  166. arrManagedServices(4, nServiceCount) = objElement.GetProperty("Source")
  167. arrManagedServices(5, nServiceCount) = objElement.GetProperty("NotDisable")
  168. nServiceCount = nServiceCount + 1
  169. End If
  170. Next
  171. For i= 0 to nServiceCount -1
  172. strWMIpath = strWMIpath & "Name=" & chr(34) & arrManagedServices(0,i) & chr(34) & " OR "
  173. next
  174. strWMIpath = Left(strWMIpath,len(strWMIpath)-3)
  175. 'connecting to WMI
  176. Set objWMIService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  177. Set objServiceSet = objWMIService.ExecQuery(strWMIpath,"WQL",0,null)
  178. If Err.number <> 0 then
  179. SA_ServeFailurepage L_FAILEDTOGETSRVOBJ_ERRORMESSAGE
  180. End If
  181. ' For each installed Service--check for service installed
  182. For i= 0 to nServiceCount - 1
  183. for each objService in objServiceSet
  184. If IsSameElementID(arrManagedServices(0,i), objService.Name) Then
  185. redim preserve arrServices(6, intArrIndex)
  186. ' If service is managed, add it to the array "arrServices"
  187. 'service name
  188. arrServices(0,intArrIndex)=objService.Name & "~" & arrManagedServices(5,i)
  189. 'getting localised name and description
  190. arrServices(1,intArrIndex) = SA_GetLocString(arrManagedServices(4,i), arrManagedServices(2,i), "")
  191. arrServices(4,intArrIndex) = SA_GetLocString(arrManagedServices(4,i), arrManagedServices(3,i), "")
  192. 'service state
  193. 'getting the localised string for service state
  194. Select case Ucase(objService.State)
  195. Case Ucase(CONST_STOPPED)
  196. arrServices(2,intArrIndex) = L_STOPPED_TEXT
  197. Case Ucase(CONST_STOPPENDING)
  198. arrServices(2,intArrIndex) = L_SERVICES_STATUS_STOP_PENDING
  199. Case Ucase(CONST_RUNNING)
  200. arrServices(2,intArrIndex) = L_RUNNING_TEXT
  201. Case Ucase(CONST_STARTPENDING)
  202. arrServices(2,intArrIndex) = L_SERVICES_STATUS_START_PENDING
  203. Case Ucase(CONST_PAUSED)
  204. arrServices(2,intArrIndex) = L_SERVICES_STATUS_PAUSED
  205. End Select
  206. 'service startup type
  207. Select case Ucase(objService.StartMode)
  208. Case Ucase(CONST_MANUAL)
  209. arrServices(3,intArrIndex) = L_MANUAL_TEXT
  210. Case Ucase(CONST_AUTOMATIC)
  211. arrServices(3,intArrIndex) = L_AUTOMATIC_TEXT
  212. Case Ucase(CONST_DISABLED)
  213. arrServices(3,intArrIndex) = L_DISABLED_TEXT
  214. End Select
  215. 'non localised values - WMI retrieves in English
  216. 'state
  217. arrServices(5,intArrIndex) = Ucase(objService.State)
  218. 'startup type
  219. arrServices(6,intArrIndex) = Ucase(objService.StartMode)
  220. intArrIndex = intArrIndex + 1
  221. End If
  222. next
  223. next
  224. ' Create the table
  225. tableServices = OTS_CreateTable("", L_SERVICES_OTS_TABLE_DESCRIPTION)
  226. ' Create columns and add them to the table
  227. 'hidden column- for services name that has to be passed to the next page.
  228. colFlags = (OTS_COL_FLAG_KEY OR OTS_COL_FLAG_HIDDEN)
  229. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICENAME, _
  230. CONST_OTS_COLUMN_ALIGN, _
  231. colFlags))
  232. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  233. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  234. GetServices = false
  235. Exit Function
  236. End IF
  237. ' Is the Name column selected as the sort column
  238. colFlags = OTS_COL_SORT
  239. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICENAME, _
  240. CONST_OTS_COLUMN_ALIGN, _
  241. colFlags ))
  242. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  243. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  244. GetServices = false
  245. Exit Function
  246. End IF
  247. ' Is the status column selected as the sort column
  248. colFlags = OTS_COL_SORT
  249. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICESTATUS, _
  250. CONST_OTS_COLUMN_ALIGN, _
  251. colFlags))
  252. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  253. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  254. GetServices = false
  255. Exit Function
  256. End IF
  257. 'service type column
  258. colFlags = OTS_COL_SORT
  259. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICESTARTUPTYPE, _
  260. CONST_OTS_COLUMN_ALIGN, _
  261. colFlags))
  262. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  263. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  264. GetServices = false
  265. Exit Function
  266. End IF
  267. 'service description column
  268. colFlags = OTS_COL_SORT
  269. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn( L_SERVICES_OTS_COLUMN_SERVICEDESC, _
  270. CONST_OTS_COLUMN_ALIGN, _
  271. colFlags))
  272. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  273. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  274. GetServices = false
  275. Exit Function
  276. End IF
  277. 'hidden column for the non localised service status value retrieved from WMI in english
  278. colFlags = (OTS_COL_FLAG_HIDDEN)
  279. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICESTATUS, _
  280. CONST_OTS_COLUMN_ALIGN, _
  281. colFlags))
  282. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  283. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  284. GetServices = false
  285. Exit Function
  286. End IF
  287. 'hidden column for the non localised service startup type value retrieved from WMI in english
  288. colFlags = (OTS_COL_FLAG_HIDDEN)
  289. nReturnValue=OTS_AddTableColumn(tableServices, OTS_CreateColumn(L_SERVICES_OTS_COLUMN_SERVICESTARTUPTYPE, _
  290. CONST_OTS_COLUMN_ALIGN, _
  291. colFlags))
  292. If nReturnValue <> OTS_ERR_SUCCESS Or Err.number <> 0 Then
  293. SA_ServeFailurepage L_FAILEDTOADDCOLOUMN_ERRORMESSAGE
  294. GetServices = false
  295. Exit Function
  296. End IF
  297. ' Add Tasks to the table
  298. Call OTS_SetTableTasksTitle(tableServices, L_SERVICES_TASKS)
  299. ' Add the tasks associated with User objects
  300. sTaskURL = "services/services.asp?service=enable"
  301. strReturnTo = "tasks.asp"
  302. Call SA_MungeURL(strReturnTo, "Tab1", GetTab1())
  303. Call SA_MungeURL(sTaskURL, "ReturnURL", strReturnTo)
  304. nReturnValue = OTS_AddTableTask( tableServices, OTS_CreateTaskEx(L_SERVICES_TASK_ENABLE, _
  305. L_SERVICES_TASK_ENABLE_DESC, _
  306. sTaskURL, _
  307. OTS_PT_AREA, _
  308. "EnableServiceTask") )
  309. If nReturnValue <> OTS_ERR_SUCCESS Then
  310. SA_ServeFailurepage L_FAILEDTOADDTASK_ERRORMESSAGE
  311. GetServices = false
  312. Exit Function
  313. End IF
  314. sTaskURL = "services/services.asp?service=disable"
  315. strReturnTo = "tasks.asp"
  316. Call SA_MungeURL(strReturnTo, "Tab1", GetTab1())
  317. Call SA_MungeURL(sTaskURL, "ReturnURL", strReturnTo)
  318. nReturnValue=OTS_AddTableTask( tableServices, OTS_CreateTaskEx(L_SERVICES_TASK_DISABLE, _
  319. L_SERVICES_TASK_DISABLE_DESC, _
  320. sTaskURL, _
  321. OTS_PT_AREA, _
  322. "DisableServiceTask") )
  323. If nReturnValue <> OTS_ERR_SUCCESS Then
  324. SA_ServeFailurepage L_FAILEDTOADDTASK_ERRORMESSAGE
  325. GetServices = false
  326. Exit Function
  327. End IF
  328. nReturnValue=OTS_AddTableTask( tableServices, OTS_CreateTaskEx(L_SERVICES_TASK_PROPERTIES, _
  329. L_SERVICES_TASK_PROPERTIES_DESC, _
  330. "services/service_dispatch.asp",_
  331. OTS_PT_AREA,"PropertiesTask") )
  332. If nReturnValue <> OTS_ERR_SUCCESS Then
  333. SA_ServeFailurepage L_FAILEDTOADDTASK_ERRORMESSAGE
  334. GetServices = false
  335. Exit Function
  336. End IF
  337. 'Add Rows to the table
  338. For intCount = 0 to intArrIndex-1
  339. 'moving the array elements to variables
  340. strArrServiceName = arrServices(0,intCount)
  341. strArrServiceDisplayName = arrServices(1,intCount)
  342. strArrServiceStatus = arrServices(2,intCount)
  343. strArrServiceStartupType = arrServices(3,intCount)
  344. strArrServiceDescription = arrServices(4,intCount)
  345. strArrNonlocalisedServiceStatus = arrServices(5,intCount)
  346. strArrNonlocalisedServiceStartupType = arrServices(6,intCount)
  347. ' Verify that the current user part of the current page
  348. Call OTS_AddTableRow( tableServices, Array(strArrServiceName, strArrServiceDisplayName, strArrServiceStatus, strArrServiceStartupType, strArrServiceDescription,strArrNonlocalisedServiceStatus,strArrNonlocalisedServiceStartupType) )
  349. Next
  350. ' Enable sorting
  351. Call OTS_SortTable(tableServices, g_iSortCol, g_sSortSequence, SA_RESERVED)
  352. '
  353. ' Send table to the response stream
  354. Call OTS_ServeTable(tableServices)
  355. '
  356. ' Code for dynamically enabling tasks
  357. Call OTS_GetTableRows(tableServices, rows)
  358. Call OTS_GetTableTasks(tableServices, tasks)
  359. Call ServeCustomTaskFunctions(tasks, rows)
  360. 'Release the objects
  361. Set objManagedServices = Nothing
  362. Set objWMIService = Nothing
  363. Set objServiceSet = Nothing
  364. GetServices = TRUE
  365. End Function
  366. '-------------------------------------------------------------------------
  367. ' Function name: IsSameElementID
  368. ' Description: Compares 2 service names and returns true if they are
  369. ' same else false
  370. ' Input Variables: sElementID1 - System Service
  371. ' sElementID2 - Manged service
  372. ' Output Variables: None
  373. ' Return Values: True if equals else false
  374. ' Global Variables: None
  375. '-------------------------------------------------------------------------
  376. Function IsSameElementID(ByVal sElementID1, ByVal sElementID2)
  377. Err.Clear
  378. on error resume next
  379. Dim s1, s2
  380. s1 = LCase(Trim(sElementID1))
  381. s2 = LCase(Trim(sElementID2))
  382. IsSameElementID = CBool(s1 = s2)
  383. End Function
  384. '---------------------------------------------------------------------
  385. ' Function: ServeCustomTaskFunctions()
  386. ' Description: Dynamically enable OTS tasks (Enable and Disable Tasks)
  387. ' Input Variables: aTasks - Array of tasks added to the OTS table
  388. ' aItems - Array of items added to the OTS table
  389. ' Output Variables: aTasks - Array of tasks added to the OTS table
  390. ' aItems - Array of items added to the OTS table
  391. ' Returns: None
  392. '---------------------------------------------------------------------
  393. Private Function ServeCustomTaskFunctions(ByRef aTasks, ByRef aItems)
  394. Call SA_TraceOut(SOURCE_FILE, "ServeCustomTaskFunctions")
  395. %>
  396. <script language='javascript'>
  397. // Global variable declaration
  398. var EnableServiceTaskEnabled = false;
  399. var DisableServiceTaskEnabled = false;
  400. var PropertiesTaskEnabled = false;
  401. // Constants for dynamic tasks
  402. var JS_CONST_strRunning = "RUNNING";
  403. var JS_CONST_strAutomatic = "AUTO";
  404. var JS_CONST_strStopped = "STOPPED";
  405. var JS_CONST_strDisabled = "DISABLED";
  406. var JS_CONST_StopPending = "STOP PENDING";
  407. var JS_CONST_StartPending = "START PENDING";
  408. //---------------------------------------------------------------------
  409. // Function: ServiceObject
  410. // Description: Pseudo object constructor to create a Service object.
  411. // Input Variables: Service Status - string indicating the status of the service
  412. // Output Variables: None
  413. // Returns: Reference to ServiceObject
  414. //---------------------------------------------------------------------
  415. function ServiceObject(ServiceStatus)
  416. {
  417. this.ServiceStatus = ServiceStatus;
  418. }
  419. <%
  420. Dim iX
  421. Dim aItem
  422. Dim sServStatus
  423. Dim sServStartup
  424. Dim sServiceName
  425. Dim ServiceArr
  426. Response.Write(""+vbCrLf)
  427. Response.Write("//"+vbCrLf)
  428. Response.Write("// Create ServiceStatus array, one element for every row in the OTS Table."+vbCrLf)
  429. Response.Write("// Create ServiceStartUp array, one element for every row in the OTS Table."+vbCrLf)
  430. Response.Write("//"+vbCrLf)
  431. Response.Write("var oServiceStatus = new Array();"+vbCrLf)
  432. Response.Write("var oServiceStartUp = new Array();"+vbCrLf)
  433. Response.Write("var oServiceName = new Array();"+vbCrLf)
  434. For iX = 0 to (UBound(aItems)-1)
  435. aItem = aItems(iX)
  436. If ( IsArray(aItem)) Then
  437. sServStatus = aItem(5)
  438. sServStartup = aItem(6)
  439. sServiceName = aItem(0)
  440. ServiceArr = split(sServiceName, "~")
  441. sServiceName = ServiceArr(1)
  442. Response.Write("oServiceStatus["+CStr(iX)+"] = new ServiceObject('"+sServStatus+"');"+vbCrLf)
  443. Response.Write("oServiceStartUp["+CStr(iX)+"] = new ServiceObject('"+sServStartup+"');"+vbCrLf)
  444. Response.Write("oServiceName["+CStr(iX)+"] = new ServiceObject('"+sServiceName+"');"+vbCrLf)
  445. Else
  446. Call SA_TraceOut(SA_GetScriptFileName(), "Error: aItem is not an array")
  447. End If
  448. Next
  449. %>
  450. //---------------------------------------------------------------------
  451. // Function: EnableServiceTask()
  452. // Description: Disables the Enable task if any service has status
  453. // as running and startup type as Automatic
  454. // Input Variables: sMessage
  455. // iTaskNo - number of task
  456. // iItemNo - index number of item that has been selected
  457. // Output Variables: None
  458. // Returns: True to continue processing, False to stop.
  459. //---------------------------------------------------------------------
  460. function EnableServiceTask(sMessage, iTaskNo, iItemNo)
  461. {
  462. var bRc = true;
  463. try
  464. {
  465. if ( sMessage.toLowerCase() == OTS_MESSAGE_BEGIN )
  466. {
  467. EnableServiceTaskEnabled = true;
  468. }
  469. else if ( sMessage.toLowerCase() == OTS_MESSAGE_ITEM )
  470. {
  471. var ServStatusObject = oServiceStatus[iItemNo];
  472. var ServStartUpObject = oServiceStartUp[iItemNo];
  473. var ServStatus1 = ServStatusObject.ServiceStatus;
  474. var ServStatus2 = ServStartUpObject.ServiceStatus;
  475. if ( ((ServStatus1.toUpperCase() == JS_CONST_strRunning) && (ServStatus2.toUpperCase() == JS_CONST_strAutomatic))
  476. || (ServStatus1.toUpperCase() == JS_CONST_StopPending) || (ServStatus1.toUpperCase() == JS_CONST_StartPending))
  477. {
  478. EnableServiceTaskEnabled = false;
  479. }
  480. }
  481. else if ( sMessage.toLowerCase() == OTS_MESSAGE_END )
  482. {
  483. if ( EnableServiceTaskEnabled == true )
  484. {
  485. OTS_SetTaskEnabled(iTaskNo, true);
  486. }
  487. else
  488. {
  489. OTS_SetTaskEnabled(iTaskNo, false);
  490. }
  491. }
  492. }
  493. catch(oException)
  494. {
  495. if ( SA_IsDebugEnabled() )
  496. {
  497. alert("EnableServiceTask function encountered exception\n\nError: " + oException.number + "\nDescription:"+oException.description);
  498. }
  499. }
  500. return bRc;
  501. }
  502. //---------------------------------------------------------------------
  503. // Function: DisableServiceTask()
  504. // Description: Disables the Disable task if any service has status as
  505. // stopped and startup type as Disabled
  506. // Input Variables: sMessage
  507. // iTaskNo - number of task
  508. // iItemNo - index number of item that has been selected
  509. // Output Variables: None
  510. // Returns: True to continue processing, False to stop.
  511. //---------------------------------------------------------------------
  512. function DisableServiceTask(sMessage, iTaskNo, iItemNo)
  513. {
  514. var bRc = true;
  515. try
  516. {
  517. if ( sMessage.toLowerCase() == OTS_MESSAGE_BEGIN )
  518. {
  519. DisableServiceTaskEnabled = true;
  520. }
  521. else if ( sMessage.toLowerCase() == OTS_MESSAGE_ITEM )
  522. {
  523. var ServStatusObject = oServiceStatus[iItemNo];
  524. var ServStartUpObject = oServiceStartUp[iItemNo];
  525. var ServName = oServiceName[iItemNo];
  526. var ServStatus1 = ServStatusObject.ServiceStatus;
  527. var ServStatus2 = ServStartUpObject.ServiceStatus;
  528. if ( ((ServStatus1.toUpperCase() == JS_CONST_strStopped) && (ServStatus2.toUpperCase() == JS_CONST_strDisabled)) || (ServName.ServiceStatus == "1" )
  529. || (ServStatus1.toUpperCase() == JS_CONST_StopPending) || (ServStatus1.toUpperCase() == JS_CONST_StartPending))
  530. {
  531. DisableServiceTaskEnabled = false;
  532. }
  533. }
  534. else if ( sMessage.toLowerCase() == OTS_MESSAGE_END )
  535. {
  536. if ( DisableServiceTaskEnabled == true )
  537. {
  538. OTS_SetTaskEnabled(iTaskNo, true);
  539. }
  540. else
  541. {
  542. OTS_SetTaskEnabled(iTaskNo, false);
  543. }
  544. }
  545. }
  546. catch(oException)
  547. {
  548. if ( SA_IsDebugEnabled() )
  549. {
  550. alert("DisableServiceTask function encountered exception\n\nError: " + oException.number + "\nDescription:"+oException.description);
  551. }
  552. }
  553. return bRc;
  554. }
  555. //---------------------------------------------------------------------
  556. // Function: PropertiesTask()
  557. // Description: Disables the Properties task if any service has status as
  558. // stop pending or Start pending.
  559. // Input Variables: sMessage
  560. // iTaskNo - number of task
  561. // iItemNo - index number of item that has been selected
  562. // Output Variables: None
  563. // Returns: True to continue processing, False to stop.
  564. //---------------------------------------------------------------------
  565. function PropertiesTask(sMessage, iTaskNo, iItemNo)
  566. {
  567. var bRc = true;
  568. try
  569. {
  570. if ( sMessage.toLowerCase() == OTS_MESSAGE_BEGIN )
  571. {
  572. PropertiesTaskEnabled = true;
  573. }
  574. else if ( sMessage.toLowerCase() == OTS_MESSAGE_ITEM )
  575. {
  576. var ServStatusObject = oServiceStatus[iItemNo];
  577. var ServStatus1 = ServStatusObject.ServiceStatus;
  578. if ( (ServStatus1.toUpperCase() == JS_CONST_StopPending) || (ServStatus1.toUpperCase() == JS_CONST_StartPending))
  579. {
  580. PropertiesTaskEnabled = false;
  581. }
  582. }
  583. else if ( sMessage.toLowerCase() == OTS_MESSAGE_END )
  584. {
  585. if ( PropertiesTaskEnabled == true )
  586. {
  587. OTS_SetTaskEnabled(iTaskNo, true);
  588. }
  589. else
  590. {
  591. OTS_SetTaskEnabled(iTaskNo, false);
  592. }
  593. }
  594. }
  595. catch(oException)
  596. {
  597. if ( SA_IsDebugEnabled() )
  598. {
  599. alert("PropertiesTask function encountered exception\n\nError: " + oException.number + "\nDescription:"+oException.description);
  600. }
  601. }
  602. return bRc;
  603. }
  604. </script>
  605. <%
  606. End Function
  607. '---------------------------------------------------------------------
  608. ' Function: ServiceTaskClick()
  609. ' Description: Called to enable or disable service is clicked
  610. ' Input Variables: None
  611. ' Output Variables: None
  612. ' Return Values: None
  613. ' Global Variables: In:None
  614. '---------------------------------------------------------------------
  615. Function ServiceTaskClick()
  616. Dim strServiceRetval ' to hold site name
  617. Dim retVal ' to hold the return value
  618. Dim objService ' to hold the connection
  619. Dim ServiceArr ' service name as array from pkey
  620. objService = Request.QueryString("PKey")
  621. 'pkey consists of notdisable registry element value concatenated
  622. ServiceArr = Split(objService, "~")
  623. if IsArray(ServiceArr) and UBound(ServiceArr) > 0 then
  624. objService = ServiceArr(0)
  625. 'Check whether to enable/disable service
  626. strServiceRetval = Request.QueryString("service")
  627. If strServiceRetval = "enable" then
  628. retVal = EnableService(objService)
  629. Elseif strServiceRetval = "disable" then
  630. retVal = DisableService(objService)
  631. End if
  632. end if
  633. End Function
  634. '-------------------------------------------------------------------------
  635. 'Function name: EnableService
  636. 'Description: Start the service
  637. 'Input Variables: None
  638. 'Output Variables: None
  639. 'Returns: (True/False)
  640. 'Global Variables: In: F_strService 'Service Name
  641. '--------------------------------------------------------------------------
  642. Function EnableService(Service)
  643. Err.Clear
  644. On Error Resume Next
  645. Dim objService 'services list
  646. Dim strWMIPath 'wmi path
  647. Dim objWMIService 'wmi object
  648. Const CONST_STARTMODE = "Automatic"
  649. EnableService=False
  650. 'wmi path
  651. strWMIPath = "Win32_Service.Name=" & chr(34) & Service & chr(34)
  652. 'connecting to WMI
  653. Set objWMIService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  654. set objService = objWMIService.get(strWMIPath)
  655. objService.ChangeStartMode(CONST_STARTMODE)
  656. objService.StartService()
  657. If(Err.Number <> 0) Then
  658. SA_SetErrMsg L_NOINSTANCE_ERRORMESSAGE
  659. Exit Function
  660. End If
  661. EnableService = True
  662. 'Release the objects
  663. Set objService = Nothing
  664. Set objWMIService = Nothing
  665. End Function
  666. '-------------------------------------------------------------------------
  667. 'Function name: DisableService
  668. 'Description: Disable service
  669. 'Input Variables: None
  670. 'Output Variables: None
  671. 'Returns: (True/False)
  672. 'Global Variables: In: F_strServiceName 'Service Name
  673. ' In: L_*
  674. '--------------------------------------------------------------------------
  675. Function DisableService(Service)
  676. Err.Clear
  677. On Error Resume Next
  678. Dim objService 'services list
  679. Dim strWMIPath 'wmi path
  680. Dim objWMIService 'wmi object
  681. Const CONST_STARTMODE = "Disabled"
  682. DisableService = False
  683. 'wmi path
  684. strWMIPath = "Win32_Service.Name=" & chr(34) & Service & chr(34)
  685. 'connecting to WMI
  686. Set objWMIService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  687. set objService = objWMIService.get(strWMIPath)
  688. 'making the service disable
  689. objService.ChangeStartMode(CONST_STARTMODE)
  690. objService.StopService()
  691. If(Err.Number <> 0) Then
  692. SA_SetErrMsg L_NOINSTANCE_ERRORMESSAGE
  693. Exit Function
  694. End If
  695. 'Release the objects
  696. Set objService = Nothing
  697. Set objWMIService = Nothing
  698. DisableService = True
  699. End Function
  700. %>