Windows服务管理脚本:列出所有服务,停止、启动、删除和安装服务

  1. '********************************************************************  
  2. '*  
  3. '* file:           SERVICE.VBS  
  4. '* Created:        March 1999  
  5. '* Version:        1.0  
  6. '*  
  7. '* Main Function: Controls services on a machine.  
  8. '*  
  9. '*  1.  Service.vbs /L  
  10. '*                 [/S <server>][/U <username>][/W <password>]  
  11. '*                 [/O <outputfile>]  
  12. '*  
  13. '*  2.  Service.vbs /G | /X | /R | /D | /M <StartMode>  
  14. '*                  /N <service>  
  15. '*                 [/S <server>][/U <username>][/W <password>]  
  16. '*                 [/O <outputfile>]  
  17. '*  
  18. '*  3.  Service.vbs /I /E <execname> /N <service> [/C <DisplayName>]  
  19. '*                 [/S <server>][/U <username>][/W <password>]  
  20. '*                 [/O <outputfile>]  
  21. '*  
  22. '* Copyright (C) 1999 Microsoft Corporation  
  23. '*  
  24. '********************************************************************  
  25. OPTION EXPLICIT  
  26.  
  27.     'Define constants  
  28.  
  29.     CONST CONST_ERROR                   = 0  
  30.     CONST CONST_WSCRIPT                 = 1  
  31.     CONST CONST_CSCRIPT                 = 2  
  32.     CONST CONST_SHOW_USAGE              = 3  
  33.     CONST CONST_PROCEED                 = 4  
  34.     CONST CONST_LIST                    = "LIST" 
  35.     CONST CONST_START                   = "START" 
  36.     CONST CONST_STOP                    = "STOP" 
  37.     CONST CONST_INSTALL                 = "INSTALL" 
  38.     CONST CONST_REMOVE                  = "REMOVE" 
  39.     CONST CONST_DEPENDS                 = "DEPENDS" 
  40.     CONST CONST_MODE                    = "MODE" 
  41.  
  42.  
  43.     'Declare variables  
  44.     Dim strOutputFile, intOpMode, i  
  45.     Dim strServer, strUserName, strPassword  
  46.     Dim strTaskCommand, strServiceName, strExecName  
  47.     Dim strStartMode, strDisplayName  
  48.  
  49.     'Make sure the host is csript, if not then abort  
  50.     VerifyHostIsCscript()  
  51.  
  52.     'Parse the command line  
  53.  
  54.     intOpMode = intParseCmdLine( strServer      ,  _  
  55.                                  strUserName    ,  _  
  56.                                  strPassword    ,  _  
  57.                                  strOutputFile  ,  _  
  58.                                  strTaskCommand ,  _  
  59.                                  strServiceName ,  _  
  60.                                  strStartMode   ,  _  
  61.                                  strDisplayName ,  _  
  62.                                  strExecName       )  
  63.  
  64.  
  65.     Select Case intOpMode  
  66.  
  67.         Case CONST_SHOW_USAGE  
  68.             Call ShowUsage()  
  69.  
  70.         Case CONST_PROCEED  
  71.             Call Service(strTaskCommand, _  
  72.                    strServiceName,    _   
  73.           strExecName,       _  
  74.              strDisplayName,    _  
  75.                          strStartMode,      _  
  76.           strServer,         _  
  77.                          strOutputFile,     _  
  78.           strUserName,       _  
  79.           strPassword        )  
  80.       
  81.  
  82.         Case CONST_ERROR  
  83.             Wscript.Echo ("Error occurred in passing parameters.")  
  84.  
  85.         Case Else                    'Default -- should never happen  
  86.             call Print("Error occurred in passing parameters.")  
  87.  
  88.     End Select 
  89.  
  90. '********************************************************************  
  91. '*  
  92. '* Sub Service()  
  93. '* Purpose: Controls services on a machine.  
  94. '* Input:     
  95. '*          strTaskCommand      one of /list, /start, /stop /install /remove  
  96. '*                              /dependents  
  97. '*          strServiceName      name of the service  
  98. '*          strExecName         name of executable for service install  
  99. '*          strDisplayName      Display name for the service.  
  100. '*          strStartMode        start mode of the service  
  101. '*          strServer           a machine name  
  102. '*          strOutputFile       an output file name  
  103. '*          strUserName         the current user's name  
  104. '*          strPassword         the current user's password  
  105. '* Output:  Results are either printed on screen or saved in strOutputFile.  
  106. '*  
  107. '********************************************************************  
  108. Private Sub Service(strTaskCommand, _   
  109.                     strServiceName,    _  
  110.                     strExecName,       _  
  111.                     strDisplayName,    _  
  112.                     strStartMode,      _  
  113.                     strServer,     _  
  114.                     strOutputFile,     _  
  115.                  strUserName,       _  
  116.                  strPassword)  
  117.  
  118.     ON ERROR RESUME NEXT  
  119.  
  120.     Dim objFileSystem, objOutputFile, objService, strQuery  
  121.  
  122.     'Open a text file for output if the file is requested  
  123.     If Not IsEmpty(strOutputFile) Then 
  124.         If (NOT blnOpenFile(strOutputFile, objOutputFile)) Then 
  125.             Call Wscript.Echo ("Could not open an output file.")  
  126.             Exit Sub 
  127.         End If 
  128.     End If 
  129.  
  130.     'Establish a connection with the server.  
  131.     If blnConnect("root\cimv2" , _  
  132.                    strUserName , _  
  133.                    strPassword , _  
  134.                    strServer   , _  
  135.                    objService  ) Then 
  136.         Call Wscript.Echo("")  
  137.         Call Wscript.Echo("Please check the server name, " _  
  138.                         & "credentials and WBEM Core.")  
  139.         Exit Sub 
  140.     End If 
  141.  
  142.     'Now execute the method.  
  143.     Call ExecuteMethod(objService,        _  
  144.                     objOutputFile,     _  
  145.                     strTaskCommand, _  
  146.                     strServiceName,    _  
  147.                     strExecName,       _  
  148.            strDisplayName,    _  
  149.                        strStartMode)  
  150.  
  151.     If NOT IsEmpty(objOutputFile) Then 
  152.         objOutputFile.Close  
  153.         Wscript.Echo "Results are saved in file " & strOutputFile & "." 
  154.     End If 
  155.  
  156. End Sub 
  157.  
  158. '********************************************************************  
  159. '*  
  160. '* Sub ExecMethod()  
  161. '* Purpose: Executes a method.  
  162. '* Input:   objService          a service object  
  163. '*          objOutputFile       an output file object  
  164. '*          strTaskCommand   one of /list, /start, /stop /install /delete  
  165. '*          strServiceName      name of the service to be started or stopped  
  166. '*          strExecName         name of executable for service install  
  167. '*       strDisplayName,     Display name for the service.  
  168. '*          strStartMode        start mode of the service  
  169. '* Output:  Results are either printed on screen or saved in objOutputFile.  
  170. '*  
  171. '********************************************************************  
  172. Private Sub ExecuteMethod(objService,        _  
  173.                           objOutputFile,     _  
  174.                           strTaskCommand, _  
  175.                           strServiceName,    _  
  176.         strExecName,       _  
  177.                           strDisplayName,    _  
  178.                           strStartMode)  
  179.  
  180.     ON ERROR RESUME NEXT  
  181.  
  182.     Dim objEnumerator, objInstance, strMessage, intStatus, objReference  
  183.     ReDim strName(0), strDisplayName(0), strState(0), intOrder(0)  
  184.  
  185.  'Initialize local variables  
  186.     strMessage        = "" 
  187.     strName(0)        = "" 
  188.     strDisplayName(0) = "" 
  189.     strState(0)       = "" 
  190.     intOrder(0)       = 0  
  191.  
  192.     Select Case strTaskCommand  
  193.         Case CONST_START  
  194.             Set objInstance = objService.Get("Win32_Service='" &_  
  195.                 strServiceName & "'")  
  196.             If Err.Number Then 
  197.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  198.                     " occurred in getting " & _  
  199.                       "service " & strServiceName & ".")  
  200.                 If Err.Description <> "" Then 
  201.                     call Print( "Error description: " & Err.Description & ".")  
  202.                 End If 
  203.                 Err.Clear  
  204.                 Exit Sub 
  205.             End If 
  206.             If objInstance is nothing Then 
  207.                 Exit Sub 
  208.             Else 
  209.                 intStatus = objInstance.StartService()  
  210.                 If intStatus = 0 Then 
  211.                     strMessage = "Succeeded in starting service " & _  
  212.                         strServiceName & "." 
  213.                 Else 
  214.                     strMessage = "Failed to start service " & _  
  215.                         strServiceName & "." 
  216.                 End If 
  217.                 WriteLine strMessage, objOutputFile  
  218.             End If 
  219.  
  220.         Case CONST_STOP  
  221.             Set objInstance = objService.Get("Win32_Service='" & _  
  222.                  strServiceName&"'")  
  223.             If Err.Number Then 
  224.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  225.                     " occurred in getting " & _  
  226.                       "service " & strServiceName & ".")  
  227.                 Err.Clear  
  228.                 Exit Sub 
  229.             End If 
  230.             If objInstance is nothing Then 
  231.                 Exit Sub 
  232.             Else 
  233.                 intStatus = objInstance.StopService()  
  234.                 If intStatus = 0 Then 
  235.                     strMessage = "Succeeded in stopping service " & _  
  236.                         strServiceName & "." 
  237.                 Else 
  238.                     strMessage = "Failed to stop service " & _  
  239.                         strServiceName & "." 
  240.                 End If 
  241.                 WriteLine strMessage, objOutputFile  
  242.             End If 
  243.  
  244.         Case CONST_MODE  
  245.  
  246.             Set objInstance = objService.Get("Win32_Service='" & _  
  247.                 strServiceName & "'")  
  248.             If Err.Number Then 
  249.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  250.                     " occurred in getting " & _  
  251.                     "service " & strServiceName & ".")  
  252.                 Err.Clear  
  253.                 Exit Sub 
  254.             End If 
  255.             If objInstance is nothing Then 
  256.                 Exit Sub 
  257.             Else 
  258.                 intStatus = objInstance.ChangeStartMode(strStartMode)  
  259.                 If intStatus = 0 Then 
  260.                     strMessage = "Succeeded in changing start mode of the " _  
  261.                         & "service " & strServiceName & "." 
  262.                 Else 
  263.                     strMessage = "Failed to change the start mode of the" _  
  264.                         & " service " & strServiceName & "." 
  265.                 End If 
  266.                 WriteLine strMessage, objOutputFile  
  267.             End If 
  268.  
  269.         Case CONST_INSTALL  
  270.             Set objInstance = objService.Get("Win32_Service")  
  271.             If Err.Number Then 
  272.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  273.                 " occurred in getting " & _  
  274.                       "service " & strServiceName & ".")  
  275.                 If Err.Description <> "" Then 
  276.                     call Print( "Error description: " & Err.Description & ".")  
  277.                 End If 
  278.                 Err.Clear  
  279.                 Exit Sub 
  280.             End If 
  281.             If objInstance is Nothing Then 
  282.                 Exit Sub 
  283.             Else 
  284.  
  285.                 If IsEmpty(strDisplayName) then strDisplayName = strServiceName  
  286.  
  287.                 intStatus = objInstance.Create(strServiceName, strDisplayName(0), strExecName)  
  288.                 If intStatus = 0 Then 
  289.                     strMessage = "Succeeded in creating service " & _  
  290.                         strServiceName & "." 
  291.                 Else 
  292.                     strMessage = "Failed to create service " & _  
  293.                         strServiceName & "." 
  294.                 End If 
  295.                 WriteLine strMessage, objOutputFile  
  296.             End If 
  297.  
  298.         Case CONST_REMOVE  
  299.             Set objInstance = objService.Get("Win32_Service='" & _  
  300.                 strServiceName & "'")  
  301.             If Err.Number Then 
  302.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  303.                     " occurred in getting " & _  
  304.                     "service " & strServiceName & ".")  
  305.                 If Err.Description <> "" Then 
  306.                     call Print( "Error description: " & Err.Description & ".")  
  307.                 End If 
  308.                 Err.Clear  
  309.                 Exit Sub 
  310.             End If 
  311.             If objInstance is Nothing Then 
  312.                 Exit Sub 
  313.             Else 
  314.                 intStatus = objInstance.Delete()  
  315.                 If intStatus = 0 Then 
  316.                     strMessage = "Succeeded in deleting service " & _  
  317.                         strServiceName & "." 
  318.                 Else 
  319.                     strMessage = "Failed to delete service " & _  
  320.                         strServiceName & "." 
  321.                 End If 
  322.                 WriteLine strMessage, objOutputFile  
  323.             End If 
  324.  
  325.         Case CONST_DEPENDS  
  326.             Set objInstance = objService.Get("Win32_Service='" & _  
  327.                 strServiceName&"'")  
  328.             If Err.Number Then 
  329.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  330.                     " occurred in getting " & _  
  331.                       "service " & strServiceName & ".")  
  332.                 If Err.Description <> "" Then 
  333.                     call Print( "Error description: " & Err.Description & ".")  
  334.                 End If 
  335.                 Err.Clear  
  336.                 Exit Sub 
  337.             End If 
  338.             If objInstance is Nothing Then 
  339.                 Exit Sub 
  340.             Else 
  341.                 Set objEnumerator = _  
  342.                     objInstance.References_("Win32_DependentService")  
  343.  
  344.                 If Err.Number Then 
  345.                     call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  346.                         " occurred in getting " & _  
  347.                         "reference set.")  
  348.                     If Err.Description <> "" Then 
  349.                         call Print( "Error description: " & _  
  350.                             Err.Description & ".")  
  351.                     End If 
  352.                     Err.Clear  
  353.                     Exit Sub 
  354.                 End If 
  355.      
  356.                 If objEnumerator.Count = 0 then  
  357.                     WScript.Echo "No dependents listed" 
  358.        Else 
  359.                     i = 0  
  360.                     For Each objReference in objEnumerator  
  361.                         If objInstance is nothing Then 
  362.                             Exit Sub 
  363.                         Else 
  364.                             ReDim Preserve strName(i)  
  365.                             ReDim strDisplayName(i), strState(i), intOrder(i)  
  366.                             strName(i) = _  
  367.                                 objService.Get(objReference.Dependent).Name  
  368.                             strDisplayName(i) = _  
  369.                                 objService.Get _  
  370.                                     (objReference.Dependent).DisplayName  
  371.                             strState(i) = _  
  372.                                 objService.Get(objReference.Dependent).State  
  373.                             intOrder(i) = i  
  374.                             i = i + 1  
  375.                         End If 
  376.                         If Err.Number Then 
  377.                             Err.Clear  
  378.                         End If 
  379.                     Next 
  380.  
  381.                    'Display the header  
  382.                     strMessage = Space(2) & strPackString("NAME", 20, 1, 1)  
  383.                     strMessage = strMessage & strPackString("STATE", 10, 1, 1)  
  384.                     strMessage = strMessage & strPackString _  
  385.                         ("DISPLAY NAME", 15, 1, 0) & vbCRLF  
  386.                     WriteLine strMessage, objOutputFile  
  387.                     Call SortArray(strName, True, intOrder, 0)  
  388.                     Call ReArrangeArray(strDisplayName, intOrder)  
  389.                     Call ReArrangeArray(strState, intOrder)  
  390.                     For i = 0 To UBound(strName)  
  391.                         strMessage = Space(2) & _  
  392.                             strPackString(strName(i), 20, 1, 1)  
  393.                         strMessage = strMessage & _  
  394.                             strPackString(strState(i), 10, 1, 1)  
  395.                         strMessage = strMessage & _  
  396.                             strPackString(strDisplayName(i), 15, 1, 0)  
  397.                         WriteLine strMessage, objOutputFile  
  398.                     Next 
  399.  
  400.                 End If 
  401.             End If 
  402.  
  403.         Case CONST_LIST  
  404.             Set objEnumerator = objService.ExecQuery ( _  
  405.                 "Select Name,DisplayName,State From Win32_Service")  
  406.             If Err.Number Then 
  407.                 call Print( "Error 0x" & CStr(Hex(Err.Number)) & _  
  408.                     " occurred during the query.")  
  409.                 If Err.Description <> "" Then 
  410.                     call Print( "Error description: " & Err.Description & ".")  
  411.                 End If 
  412.                 Err.Clear  
  413.                 Exit Sub 
  414.             End If 
  415.             i = 0  
  416.             For Each objInstance in objEnumerator  
  417.                 If objInstance is nothing Then 
  418.                     Exit Sub 
  419.                 Else 
  420.                     ReDim Preserve strName(i), strDisplayName(i)  
  421.                     ReDim Preserve strState(i), intOrder(i)  
  422.                     strName(i) = objInstance.Name  
  423.                     strDisplayName(i) = objInstance.DisplayName  
  424.                     strState(i) = objInstance.State  
  425.                     intOrder(i) = i  
  426.                     i = i + 1  
  427.                 End If 
  428.                 If Err.Number Then 
  429.                     Err.Clear  
  430.                 End If 
  431.             Next 
  432.  
  433.             If i > 0 Then 
  434.                 'Display the header  
  435.                 strMessage = Space(2) & strPackString("NAME", 20, 1, 1)  
  436.                 strMessage = strMessage & strPackString("STATE", 10, 1, 1)  
  437.                 strMessage = strMessage & strPackString("DISPLAY NAME", 15, 1, 0) & vbCRLF  
  438.                 WriteLine strMessage, objOutputFile  
  439.                 Call SortArray(strName, True, intOrder, 0)  
  440.                 Call ReArrangeArray(strDisplayName, intOrder)  
  441.                 Call ReArrangeArray(strState, intOrder)  
  442.                 For i = 0 To UBound(strName)  
  443.                     strMessage = Space(2) & strPackString(strName(i), 20, 1, 1)  
  444.                     strMessage = strMessage & _  
  445.                         strPackString(strState(i), 10, 1, 1)  
  446.                     strMessage = strMessage & _  
  447.                         Left(strPackString(strDisplayName(i), 15, 1, 0),47)  
  448.                     WriteLine strMessage, objOutputFile  
  449.                 Next 
  450.             Else 
  451.                 Wscript.Echo "Service not found!" 
  452.             End If 
  453.  
  454.     End Select 
  455.  
  456. End Sub 
  457.  
  458. '********************************************************************  
  459. '*  
  460. '* Function intParseCmdLine()  
  461. '*  
  462. '* Purpose: Parses the command line.  
  463. '* Input:     
  464. '*  
  465. '* Output:  strServer          a remote server ("" = local server")  
  466. '*          strUserName        the current user's name  
  467. '*          strPassword        the current user's password  
  468. '*          strOutputFile      an output file name  
  469. '*          strTaskCommand     one of /list, /start, /stop /install /remove  
  470. '*                                    /dependents  
  471. '*          strDriverName      name of the Service  
  472. '*          strStartMode       start mode of the Service  
  473. '*          strDisplayName     Display name for the Service  
  474. '*          strExecName        The Full path of the executable  
  475.  
  476. '*  
  477. '********************************************************************  
  478. Private Function intParseCmdLine( ByRef strServer      ,  _  
  479.                                   ByRef strUserName    ,  _  
  480.                                   ByRef strPassword    ,  _  
  481.                                   ByRef strOutputFile  ,  _  
  482.                                   ByRef strTaskCommand ,  _  
  483.                                   ByRef strServiceName ,  _  
  484.                                   ByRef strStartMode   ,  _  
  485.                                   ByRef strDisplayName ,  _  
  486.                                   ByRef strExecName       )  
  487.  
  488.     ON ERROR RESUME NEXT  
  489.  
  490.     Dim strFlag  
  491.     Dim intState, intArgIter  
  492.     Dim objFileSystem  
  493.  
  494.     If Wscript.Arguments.Count > 0 Then 
  495.         strFlag = Wscript.arguments.Item(0)  
  496.     End If 
  497.  
  498.     If IsEmpty(strFlag) Then                'No arguments have been received  
  499.         intParseCmdLine = CONST_PROCEED  
  500.         strTaskCommand = CONST_LIST  
  501.         Exit Function 
  502.     End If 
  503.  
  504.     'Check if the user is asking for help or is just confused  
  505.     If (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _  
  506.         OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") _   
  507.         OR (strFlag="h"Then 
  508.         intParseCmdLine = CONST_SHOW_USAGE  
  509.         Exit Function 
  510.     End If 
  511.  
  512.     'Retrieve the command line and set appropriate variables  
  513.      intArgIter = 0  
  514.     Do While intArgIter <= Wscript.arguments.Count - 1  
  515.         Select Case Left(LCase(Wscript.arguments.Item(intArgIter)),2)  
  516.     
  517.             Case "/s" 
  518.                 If Not blnGetArg("Server", strServer, intArgIter) Then 
  519.                     intParseCmdLine = CONST_ERROR  
  520.                     Exit Function 
  521.                 End If 
  522.                 intArgIter = intArgIter + 1  
  523.  
  524.             Case "/o" 
  525.                 If Not blnGetArg("Output File", strOutputFile, intArgIter) Then 
  526.                     intParseCmdLine = CONST_ERROR  
  527.                     Exit Function 
  528.                 End If 
  529.                 intArgIter = intArgIter + 1  
  530.  
  531.             Case "/u" 
  532.                 If Not blnGetArg("User Name", strUserName, intArgIter) Then 
  533.                     intParseCmdLine = CONST_ERROR  
  534.                     Exit Function 
  535.                 End If 
  536.                 intArgIter = intArgIter + 1  
  537.  
  538.             Case "/w" 
  539.                 If Not blnGetArg("User Password", strPassword, intArgIter) Then 
  540.                     intParseCmdLine = CONST_ERROR  
  541.                     Exit Function 
  542.                 End If 
  543.                 intArgIter = intArgIter + 1  
  544.  
  545.             Case "/l" 
  546.                 intParseCmdLine = CONST_PROCEED  
  547.                 strTaskCommand = CONST_LIST  
  548.                 intArgIter = intArgIter + 1  
  549.                  
  550.             Case "/d" 
  551.                 intParseCmdLine = CONST_PROCEED  
  552.                 strTaskCommand = CONST_DEPENDS  
  553.                 intArgIter = intArgIter + 1  
  554.  
  555.             Case "/g" 
  556.                 intParseCmdLine = CONST_PROCEED  
  557.                 strTaskCommand = CONST_START  
  558.                 intArgIter = intArgIter + 1  
  559.                 
  560.             Case "/x" 
  561.                 intParseCmdLine = CONST_PROCEED  
  562.                 strTaskCommand = CONST_STOP  
  563.                 intArgIter = intArgIter + 1  
  564.  
  565.             Case "/r" 
  566.                 intParseCmdLine = CONST_PROCEED  
  567.                 strTaskCommand = CONST_REMOVE  
  568.                 intArgIter = intArgIter + 1   
  569.  
  570.             Case "/m" 
  571.                 intParseCmdLine = CONST_PROCEED  
  572.                 strTaskCommand = CONST_MODE  
  573.                 If Not blnGetArg("Start Mode", strStartMode, intArgIter) Then 
  574.                     intParseCmdLine = CONST_ERROR  
  575.                     Exit Function 
  576.                 End If 
  577.                 intArgIter = intArgIter + 1  
  578.               
  579.             Case "/c" 
  580.                 If Not blnGetArg("Display Name", strDisplayName, intArgIter) Then 
  581.                     intParseCmdLine = CONST_ERROR  
  582.                     Exit Function 
  583.                 End If 
  584.                 intArgIter = intArgIter + 1  
  585.  
  586.             Case "/n" 
  587.                 If Not blnGetArg _  
  588.                     ("Service Name", strServiceName, intArgIter) Then 
  589.                     intParseCmdLine = CONST_ERROR  
  590.                     Exit Function 
  591.                 End If 
  592.                 intArgIter = intArgIter + 1  
  593.                 
  594.             Case "/i" 
  595.                 intParseCmdLine = CONST_PROCEED  
  596.                 strTaskCommand = CONST_INSTALL  
  597.                 intArgIter = intArgIter + 1  
  598.  
  599.             Case "/e" 
  600.                 If Not blnGetArg ("Exec Name", strExecName, intArgIter) Then 
  601.                     intParseCmdLine = CONST_ERROR  
  602.                     Exit Function 
  603.                 End If 
  604.                 intArgIter = intArgIter + 1  
  605.  
  606.             Case Else 'We shouldn't get here  
  607.                 Call Wscript.Echo("Invalid or misplaced parameter: " _  
  608.                    & Wscript.arguments.Item(intArgIter) & vbCRLF _  
  609.                    & "Please check the input and try again," & vbCRLF _  
  610.                    & "or invoke with '/?' for help with the syntax.")  
  611.                 Wscript.Quit  
  612.  
  613.         End Select 
  614.  
  615.     Loop '** intArgIter <= Wscript.arguments.Count - 1  
  616.  
  617.     If IsEmpty(strTaskCommand) Then   
  618.         intParseCmdLine = CONST_PROCEED  
  619.         strTaskCommand = CONST_LIST  
  620.         Exit Function 
  621.     End If 
  622.  
  623.     Select Case strTaskCommand  
  624.         Case CONST_START  
  625.             If IsEmpty(strServiceName) then  
  626.                 intParseCmdLine = CONST_ERROR  
  627.             End IF  
  628.         Case CONST_DEPENDS  
  629.             If IsEmpty(strServiceName) then  
  630.                 intParseCmdLine = CONST_ERROR  
  631.             End IF  
  632.         Case CONST_STOP  
  633.             If IsEmpty(strServiceName) then  
  634.                 intParseCmdLine = CONST_ERROR  
  635.             End IF  
  636.         Case CONST_REMOVE  
  637.             If IsEmpty(strServiceName) then  
  638.                 intParseCmdLine = CONST_ERROR  
  639.             End IF  
  640.         Case CONST_MODE  
  641.             If IsEmpty(strServiceName) then  
  642.                 intParseCmdLine = CONST_ERROR  
  643.             End IF  
  644.         Case CONST_INSTALL  
  645.             If IsEmpty(strServiceName) then  
  646.                 intParseCmdLine = CONST_ERROR  
  647.             End If 
  648.             If IsEmpty(strExecName) then  
  649.                 intParseCmdLine = CONST_ERROR  
  650.             End IF  
  651.     End Select 
  652.  
  653. End Function 
  654.  
  655. '********************************************************************  
  656. '*  
  657. '* Sub ShowUsage()  
  658. '*  
  659. '* Purpose: Shows the correct usage to the user.  
  660. '*  
  661. '* Input:   None  
  662. '*  
  663. '* Output:  Help messages are displayed on screen.  
  664. '*  
  665. '********************************************************************  
  666. Private Sub ShowUsage()  
  667.  
  668.     Wscript.Echo "" 
  669.     Wscript.Echo "Controls services on a machine." 
  670.     Wscript.Echo "" 
  671.     Wscript.Echo "SYNTAX:" 
  672.     Wscript.Echo "1.  Service.vbs /L" 
  673.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]" 
  674.     Wscript.Echo "               [/O <outputfile>]" 
  675.     Wscript.Echo "" 
  676.     Wscript.Echo "2.  Service.vbs /G | /X | /R | /D | /M <StartMode>" 
  677.     Wscript.Echo "                /N <service>" 
  678.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]" 
  679.     Wscript.Echo "               [/O <outputfile>]" 
  680.     Wscript.Echo "" 
  681.     Wscript.Echo "3.  Service.vbs /I /E <execname> /N <service> " _  
  682.                & "[/C <DisplayName>]" 
  683.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]" 
  684.     Wscript.Echo "               [/O <outputfile>]" 
  685.     Wscript.Echo "" 
  686.     Wscript.Echo "PARAMETER SPECIFIERS:" 
  687.     Wscript.Echo "   /L            List all Services" 
  688.     Wscript.Echo "   /D            List Service dependencies" 
  689.     Wscript.Echo "   /G            Start a Service" 
  690.     Wscript.Echo "   /X            Stop a Service" 
  691.     Wscript.Echo "   /R            Remove a Service" 
  692.     Wscript.Echo "   /M            Set the Service Mode" 
  693.     Wscript.Echo "   /I            Install a service" 
  694.     Wscript.Echo "   /E            The Full path and filename of the service" 
  695.     Wscript.Echo "   StartMode     The Service Startup Setting." 
  696.     Wscript.Echo "   Service       A Service Name" 
  697.     Wscript.Echo "   DisplayName   The Service name that appears in the" _  
  698.                & " listing/" 
  699.     Wscript.Echo "   server        A machine name." 
  700.     Wscript.Echo "   username      The current user's name." 
  701.     Wscript.Echo "   password      Password of the current user." 
  702.     Wscript.Echo "   outputfile    The output file name." 
  703.     Wscript.Echo "" 
  704.     Wscript.Echo "EXAMPLE:" 
  705.     Wscript.Echo "1. cscript Service.vbs /L /S MyMachine2" 
  706.     Wscript.Echo "   List installed services for the machine MyMachine2." 
  707.     Wscript.Echo "2. cscript Service.vbs /X /N snmp" 
  708.     Wscript.Echo "   Stops the snmp service on the current machine." 
  709.     Wscript.Echo "" 
  710.  
  711. End Sub 
  712.  
  713. '********************************************************************  
  714. '* General Routines  
  715. '********************************************************************  
  716.  
  717. '********************************************************************  
  718. '*  
  719. '* Sub SortArray()  
  720. '* Purpose: Sorts an array and arrange another array accordingly.  
  721. '* Input:   strArray    the array to be sorted  
  722. '*          blnOrder    True for ascending and False for descending  
  723. '*          strArray2   an array that has exactly the same number of   
  724. '*                      elements as strArray and will be reordered   
  725. '*                      together with strArray  
  726. '*          blnCase     indicates whether the order is case sensitive  
  727. '* Output:  The sorted arrays are returned in the original arrays.  
  728. '* Note:    Repeating elements are not deleted.  
  729. '*  
  730. '********************************************************************  
  731. Private Sub SortArray(strArray, blnOrder, strArray2, blnCase)  
  732.  
  733.     ON ERROR RESUME NEXT  
  734.  
  735.     Dim i, j, intUbound  
  736.  
  737.     If IsArray(strArray) Then 
  738.         intUbound = UBound(strArray)  
  739.     Else 
  740.         call Print( "Argument is not an array!")  
  741.         Exit Sub 
  742.     End If 
  743.  
  744.     blnOrder = CBool(blnOrder)  
  745.     blnCase = CBool(blnCase)  
  746.     If Err.Number Then 
  747.         call Print( "Argument is not a boolean!")  
  748.         Exit Sub 
  749.     End If 
  750.  
  751.     i = 0  
  752.     Do Until i > intUbound-1  
  753.         j = i + 1  
  754.         Do Until j > intUbound  
  755.             If blnCase Then     'Case sensitive  
  756.                 If (strArray(i) > strArray(j)) and blnOrder Then 
  757.                     Swap strArray(i), strArray(j)   'swaps element i and j  
  758.                     Swap strArray2(i), strArray2(j)  
  759.                 ElseIf (strArray(i) < strArray(j)) and Not blnOrder Then 
  760.                     Swap strArray(i), strArray(j)   'swaps element i and j  
  761.                     Swap strArray2(i), strArray2(j)  
  762.                 ElseIf strArray(i) = strArray(j) Then 
  763.                     'Move element j to next to i  
  764.                     If j > i + 1 Then 
  765.                         Swap strArray(i+1), strArray(j)  
  766.                         Swap strArray2(i+1), strArray2(j)  
  767.                     End If 
  768.                 End If 
  769.             Else                 'Not case sensitive  
  770.                 If (LCase(strArray(i)) > LCase(strArray(j))) and blnOrder Then 
  771.                     Swap strArray(i), strArray(j)   'swaps element i and j  
  772.                     Swap strArray2(i), strArray2(j)  
  773.                 ElseIf (LCase(strArray(i)) < LCase(strArray(j))) _  
  774.                         and Not blnOrder Then 
  775.                     Swap strArray(i), strArray(j)   'swaps element i and j  
  776.                     Swap strArray2(i), strArray2(j)  
  777.                 ElseIf LCase(strArray(i)) = LCase(strArray(j)) Then 
  778.                     'Move element j to next to i  
  779.                     If j > i + 1 Then 
  780.                         Swap strArray(i+1), strArray(j)  
  781.                         Swap strArray2(i+1), strArray2(j)  
  782.                     End If 
  783.                 End If 
  784.             End If 
  785.             j = j + 1  
  786.         Loop 
  787.         i = i + 1  
  788.     Loop 
  789.  
  790. End Sub 
  791.  
  792. '********************************************************************  
  793. '*  
  794. '* Sub Swap()  
  795. '* Purpose: Exchanges values of two strings.  
  796. '* Input:   strA    a string  
  797. '*          strB    another string  
  798. '* Output:  values of strA and strB are exchanged.  
  799. '*  
  800. '********************************************************************  
  801. Private Sub Swap(ByRef strA, ByRef strB)  
  802.  
  803.     Dim strTemp  
  804.  
  805.     strTemp = strA  
  806.     strA = strB  
  807.     strB = strTemp  
  808.  
  809. End Sub 
  810.  
  811. '********************************************************************  
  812. '*  
  813. '* Sub ReArrangeArray()  
  814. '* Purpose: Rearranges one array according to order specified in another array.  
  815. '* Input:   strArray    the array to be rearranged  
  816. '*          intOrder    an integer array that specifies the order  
  817. '* Output:  strArray is returned as rearranged  
  818. '*  
  819. '********************************************************************  
  820. Private Sub ReArrangeArray(strArray, intOrder)  
  821.  
  822.     ON ERROR RESUME NEXT  
  823.  
  824.     Dim intUBound, i, strTempArray()  
  825.  
  826.     If Not (IsArray(strArray) and IsArray(intOrder)) Then 
  827.         call Print( "At least one of the arguments is not an array")  
  828.         Exit Sub 
  829.     End If 
  830.  
  831.     intUBound = UBound(strArray)  
  832.  
  833.     If intUBound <> UBound(intOrder) Then 
  834.         call Print( "The upper bound of these two arrays do not match!")  
  835.         Exit Sub 
  836.     End If 
  837.  
  838.     ReDim strTempArray(intUBound)  
  839.  
  840.     For i = 0 To intUBound  
  841.         strTempArray(i) = strArray(intOrder(i))  
  842.         If Err.Number Then 
  843.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _  
  844.                       & "rearranging an array.")  
  845.             If Err.Description <> "" Then 
  846.                 call Print( "Error description: " & Err.Description & ".")  
  847.             End If 
  848.             Err.Clear  
  849.             Exit Sub 
  850.         End If 
  851.     Next 
  852.  
  853.     For i = 0 To intUBound  
  854.         strArray(i) = strTempArray(i)  
  855.     Next 
  856.  
  857. End Sub 
  858.  
  859. '********************************************************************  
  860. '*  
  861. '* Function strPackString()  
  862. '*  
  863. '* Purpose: Attaches spaces to a string to increase the length to intWidth.  
  864. '*  
  865. '* Input:   strString   a string  
  866. '*          intWidth    the intended length of the string  
  867. '*          blnAfter    Should spaces be added after the string?  
  868. '*          blnTruncate specifies whether to truncate the string or not if  
  869. '*                      the string length is longer than intWidth  
  870. '*  
  871. '* Output:  strPackString is returned as the packed string.  
  872. '*  
  873. '********************************************************************  
  874. Private Function strPackString( ByVal strString, _  
  875.                                 ByVal intWidth,  _  
  876.                                 ByVal blnAfter,  _  
  877.                                 ByVal blnTruncate)  
  878.  
  879.     ON ERROR RESUME NEXT  
  880.  
  881.     intWidth      = CInt(intWidth)  
  882.     blnAfter      = CBool(blnAfter)  
  883.     blnTruncate   = CBool(blnTruncate)  
  884.  
  885.     If Err.Number Then 
  886.         Call Wscript.Echo ("Argument type is incorrect!")  
  887.         Err.Clear  
  888.         Wscript.Quit  
  889.     End If 
  890.  
  891.     If IsNull(strString) Then 
  892.         strPackString = "null" & Space(intWidth-4)  
  893.         Exit Function 
  894.     End If 
  895.  
  896.     strString = CStr(strString)  
  897.     If Err.Number Then 
  898.         Call Wscript.Echo ("Argument type is incorrect!")  
  899.         Err.Clear  
  900.         Wscript.Quit  
  901.     End If 
  902.  
  903.     If intWidth > Len(strString) Then 
  904.         If blnAfter Then 
  905.             strPackString = strString & Space(intWidth-Len(strString))  
  906.         Else 
  907.             strPackString = Space(intWidth-Len(strString)) & strString & " " 
  908.         End If 
  909.     Else 
  910.         If blnTruncate Then 
  911.             strPackString = Left(strString, intWidth-1) & " " 
  912.         Else 
  913.             strPackString = strString & " " 
  914.         End If 
  915.     End If 
  916.  
  917. End Function 
  918.  
  919. '********************************************************************  
  920. '*   
  921. '*  Function blnGetArg()  
  922. '*  
  923. '*  Purpose: Helper to intParseCmdLine()  
  924. '*   
  925. '*  Usage:  
  926. '*  
  927. '*     Case "/s"   
  928. '*       blnGetArg ("server name", strServer, intArgIter)  
  929. '*  
  930. '********************************************************************  
  931. Private Function blnGetArg ( ByVal StrVarName,   _  
  932.                              ByRef strVar,       _  
  933.                              ByRef intArgIter)   
  934.  
  935.     blnGetArg = False 'failure, changed to True upon successful completion  
  936.  
  937.     If Len(Wscript.Arguments(intArgIter)) > 2 then  
  938.         If Mid(Wscript.Arguments(intArgIter),3,1) = ":" then  
  939.             If Len(Wscript.Arguments(intArgIter)) > 3 then  
  940.                 strVar = Right(Wscript.Arguments(intArgIter), _  
  941.                          Len(Wscript.Arguments(intArgIter)) - 3)  
  942.                 blnGetArg = True 
  943.                 Exit Function 
  944.             Else 
  945.                 intArgIter = intArgIter + 1  
  946.                 If intArgIter > (Wscript.Arguments.Count - 1) Then 
  947.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")  
  948.                     Call Wscript.Echo( "Please check the input and try again.")  
  949.                     Exit Function 
  950.                 End If 
  951.  
  952.                 strVar = Wscript.Arguments.Item(intArgIter)  
  953.                 If Err.Number Then 
  954.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")  
  955.                     Call Wscript.Echo( "Please check the input and try again.")  
  956.                     Exit Function 
  957.                 End If 
  958.  
  959.                 If InStr(strVar, "/"Then 
  960.                     Call Wscript.Echo( "Invalid " & StrVarName)  
  961.                     Call Wscript.Echo( "Please check the input and try again.")  
  962.                     Exit Function 
  963.                 End If 
  964.  
  965.                 blnGetArg = True 'success  
  966.             End If 
  967.         Else 
  968.             strVar = Right(Wscript.Arguments(intArgIter), _  
  969.                      Len(Wscript.Arguments(intArgIter)) - 2)  
  970.             blnGetArg = True 'success  
  971.             Exit Function 
  972.         End If 
  973.     Else 
  974.         intArgIter = intArgIter + 1  
  975.         If intArgIter > (Wscript.Arguments.Count - 1) Then 
  976.             Call Wscript.Echo( "Invalid " & StrVarName & ".")  
  977.             Call Wscript.Echo( "Please check the input and try again.")  
  978.             Exit Function 
  979.         End If 
  980.  
  981.         strVar = Wscript.Arguments.Item(intArgIter)  
  982.         If Err.Number Then 
  983.             Call Wscript.Echo( "Invalid " & StrVarName & ".")  
  984.             Call Wscript.Echo( "Please check the input and try again.")  
  985.             Exit Function 
  986.         End If 
  987.  
  988.         If InStr(strVar, "/"Then 
  989.             Call Wscript.Echo( "Invalid " & StrVarName)  
  990.             Call Wscript.Echo( "Please check the input and try again.")  
  991.             Exit Function 
  992.         End If 
  993.         blnGetArg = True 'success  
  994.     End If 
  995. End Function 
  996.  
  997. '********************************************************************  
  998. '*  
  999. '* Function blnConnect()  
  1000. '*  
  1001. '* Purpose: Connects to machine strServer.  
  1002. '*  
  1003. '* Input:   strServer       a machine name  
  1004. '*          strNameSpace    a namespace  
  1005. '*          strUserName     name of the current user  
  1006. '*          strPassword     password of the current user  
  1007. '*  
  1008. '* Output:  objService is returned  as a service object.  
  1009. '*          strServer is set to local host if left unspecified  
  1010. '*  
  1011. '********************************************************************  
  1012. Private Function blnConnect(ByVal strNameSpace, _  
  1013.                             ByVal strUserName,  _  
  1014.                             ByVal strPassword,  _  
  1015.                             ByRef strServer,    _  
  1016.                             ByRef objService)  
  1017.  
  1018.     ON ERROR RESUME NEXT  
  1019.  
  1020.     Dim objLocator, objWshNet  
  1021.  
  1022.     blnConnect = False     'There is no error.  
  1023.  
  1024.     'Create Locator object to connect to remote CIM object manager  
  1025.     Set objLocator = CreateObject("WbemScripting.SWbemLocator")  
  1026.     If Err.Number then  
  1027.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _  
  1028.                            " occurred in creating a locator object." )  
  1029.         If Err.Description <> "" Then 
  1030.             Call Wscript.Echo( "Error description: " & Err.Description & "." )  
  1031.         End If 
  1032.         Err.Clear  
  1033.         blnConnect = True     'An error occurred  
  1034.         Exit Function 
  1035.     End If 
  1036.  
  1037.     'Connect to the namespace which is either local or remote  
  1038.     Set objService = objLocator.ConnectServer (strServer, strNameSpace, _  
  1039.        strUserName, strPassword)  
  1040.     ObjService.Security_.impersonationlevel = 3  
  1041.     If Err.Number then  
  1042.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _  
  1043.                            " occurred in connecting to server " _  
  1044.            & strServer & ".")  
  1045.         If Err.Description <> "" Then 
  1046.             Call Wscript.Echo( "Error description: " & Err.Description & "." )  
  1047.         End If 
  1048.         Err.Clear  
  1049.         blnConnect = True     'An error occurred  
  1050.     End If 
  1051.  
  1052.     'Get the current server's name if left unspecified  
  1053.     If IsEmpty(strServer) Then 
  1054.         Set objWshNet = CreateObject("Wscript.Network")  
  1055.     strServer     = objWshNet.ComputerName  
  1056.     End If 
  1057.  
  1058. End Function 
  1059.  
  1060. '********************************************************************  
  1061. '*  
  1062. '* Sub      VerifyHostIsCscript()  
  1063. '*  
  1064. '* Purpose: Determines which program is used to run this script.  
  1065. '*  
  1066. '* Input:   None  
  1067. '*  
  1068. '* Output:  If host is not cscript, then an error message is printed   
  1069. '*          and the script is aborted.  
  1070. '*  
  1071. '********************************************************************  
  1072. Sub VerifyHostIsCscript()  
  1073.  
  1074.     ON ERROR RESUME NEXT  
  1075.  
  1076.     Dim strFullName, strCommand, i, j, intStatus  
  1077.  
  1078.     strFullName = WScript.FullName  
  1079.  
  1080.     If Err.Number then  
  1081.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & " occurred." )  
  1082.         If Err.Description <> "" Then 
  1083.             Call Wscript.Echo( "Error description: " & Err.Description & "." )  
  1084.         End If 
  1085.         intStatus =  CONST_ERROR  
  1086.     End If 
  1087.  
  1088.     i = InStr(1, strFullName, ".exe", 1)  
  1089.     If i = 0 Then 
  1090.         intStatus =  CONST_ERROR  
  1091.     Else 
  1092.         j = InStrRev(strFullName, "\", i, 1)  
  1093.         If j = 0 Then 
  1094.             intStatus =  CONST_ERROR  
  1095.         Else 
  1096.             strCommand = Mid(strFullName, j+1, i-j-1)  
  1097.             Select Case LCase(strCommand)  
  1098.                 Case "cscript" 
  1099.                     intStatus = CONST_CSCRIPT  
  1100.                 Case "wscript" 
  1101.                     intStatus = CONST_WSCRIPT  
  1102.                 Case Else       'should never happen  
  1103.                     Call Wscript.Echo( "An unexpected program was used to " _  
  1104.                                        & "run this script." )  
  1105.                     Call Wscript.Echo( "Only CScript.Exe or WScript.Exe can " _  
  1106.                                        & "be used to run this script." )  
  1107.                     intStatus = CONST_ERROR  
  1108.                 End Select 
  1109.         End If 
  1110.     End If 
  1111.  
  1112.     If intStatus <> CONST_CSCRIPT Then 
  1113.         Call WScript.Echo( "Please run this script using CScript." & vbCRLF & _  
  1114.              "This can be achieved by" & vbCRLF & _  
  1115.              "1. Using ""CScript Service.vbs arguments"" for Windows 95/98 or" _  
  1116.              & vbCRLF & "2. Changing the default Windows Scripting Host " _  
  1117.              & "setting to CScript" & vbCRLF & "    using ""CScript " _  
  1118.              & "//H:CScript //S"" and running the script using" & vbCRLF & _  
  1119.              "    ""Service.vbs arguments"" for Windows NT/2000." )  
  1120.         WScript.Quit  
  1121.     End If 
  1122.  
  1123. End Sub 
  1124.  
  1125. '********************************************************************  
  1126. '*  
  1127. '* Sub WriteLine()  
  1128. '* Purpose: Writes a text line either to a file or on screen.  
  1129. '* Input:   strMessage  the string to print  
  1130. '*          objFile     an output file object  
  1131. '* Output:  strMessage is either displayed on screen or written to a file.  
  1132. '*  
  1133. '********************************************************************  
  1134. Sub WriteLine(ByVal strMessage, ByVal objFile)  
  1135.  
  1136.     On Error Resume Next 
  1137.     If IsObject(objFile) then        'objFile should be a file object  
  1138.         objFile.WriteLine strMessage  
  1139.     Else 
  1140.         Call Wscript.Echo( strMessage )  
  1141.     End If 
  1142.  
  1143. End Sub 
  1144.  
  1145. '********************************************************************  
  1146. '*   
  1147. '* Function blnErrorOccurred()  
  1148. '*  
  1149. '* Purpose: Reports error with a string saying what the error occurred in.  
  1150. '*  
  1151. '* Input:   strIn  string saying what the error occurred in.  
  1152. '*  
  1153. '* Output:  displayed on screen   
  1154. '*   
  1155. '********************************************************************  
  1156. Private Function blnErrorOccurred (ByVal strIn)  
  1157.  
  1158.     If Err.Number Then 
  1159.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & ": " & strIn)  
  1160.         If Err.Description <> "" Then 
  1161.             Call Wscript.Echo( "Error description: " & Err.Description)  
  1162.         End If 
  1163.         Err.Clear  
  1164.         blnErrorOccurred = True 
  1165.     Else 
  1166.         blnErrorOccurred = False 
  1167.     End If 
  1168.  
  1169. End Function 
  1170.  
  1171. '********************************************************************  
  1172. '*   
  1173. '* Function blnOpenFile  
  1174. '*  
  1175. '* Purpose: Opens a file.  
  1176. '*  
  1177. '* Input:   strFileName  A string with the name of the file.  
  1178. '*  
  1179. '* Output:  Sets objOpenFile to a FileSystemObject and setis it to   
  1180. '*            Nothing upon Failure.  
  1181. '*   
  1182. '********************************************************************  
  1183. Private Function blnOpenFile(ByVal strFileName, ByRef objOpenFile)  
  1184.  
  1185.     ON ERROR RESUME NEXT  
  1186.  
  1187.     Dim objFileSystem  
  1188.  
  1189.     Set objFileSystem = Nothing 
  1190.  
  1191.     If IsEmpty(strFileName) OR strFileName = "" Then 
  1192.         blnOpenFile = False 
  1193.         Set objOpenFile = Nothing 
  1194.         Exit Function 
  1195.     End If 
  1196.  
  1197.     'Create a file object  
  1198.     Set objFileSystem = CreateObject("Scripting.FileSystemObject")  
  1199.     If blnErrorOccurred("Could not create filesystem object."Then 
  1200.         blnOpenFile = False 
  1201.         Set objOpenFile = Nothing 
  1202.         Exit Function 
  1203.     End If 
  1204.  
  1205.     'Open the file for output  
  1206.     Set objOpenFile = objFileSystem.OpenTextFile(strFileName, 8, True)  
  1207.     If blnErrorOccurred("Could not open"Then 
  1208.         blnOpenFile = False 
  1209.         Set objOpenFile = Nothing 
  1210.         Exit Function 
  1211.     End If 
  1212.     blnOpenFile = True 
  1213.  
  1214. End Function 
  1215.  
  1216. '********************************************************************  
  1217. '*                                                                  *  
  1218. '*                           End of File                            *  
  1219. '*                                                                  *  
  1220. '********************************************************************   
此文章由 flyinweb 于 2010-11-08 18:17:37 编辑

本日志由 flyinweb 于 2009-06-18 13:00:27 发表,目前已经被浏览 4055 次,评论 0 次;

作者添加了以下标签: Windows服务管理

引用通告:http://www.517sou.net/Article/16/Trackback.ashx

评论订阅:http://www.517sou.net/Article/16/Feeds.ashx

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)