none
Script varios RRS feed

  • Pregunta

  • Hola, necesito hacer mediante un script lo siguiente:
    1) parar un servicio
    2) abrir un txt y modificar una linea
    3) guardar los cambios
    4) iniciar el servicio

    Es posible?
    Cómo se hace esto?

    GRACIAS,
    ZIDAC

     

    viernes, 28 de septiembre de 2007 11:09

Respuestas

  • Se me ocurre que podrias hacer un script que

    1)  net stop servicio
    2) Tener el archivo modificado en una ruta de red , y copiarlo con robocopy o xcopy
    3) net start servicio

    Slds
    Sebastian del Rio

    viernes, 28 de septiembre de 2007 12:38
  •  

    Es muy facil...

     

    En ScriptCenter tienes ejemplos de como parar y arrancar un servicio y sus dependientes:

     

    Parar:

    http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb25.mspx?mfr=true

     

    Arrancar:

    http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb23.mspx?mfr=true

     

    Ejemplo de cambiar texto en un fichero:

     

    '+--------------+--------------------------------------------------------------+
    '| File:        | FindReplace.VBS                                              |
    '| Purpose:     | Find all ocurences of a String1 in a given file and replace  |
    '|              | it with  String 2                                            |
    '+--------------+--------------------------------------------------------------+
    '| Author:      | Ramon Jimenez                                                |
    '| Date:        | Nov 25, 2004                                                 |
    '+-----------------------------------------------------------------------------+
    '| Parameters   | Filename, StrtoReplace, StrReplacement                       |
    '+-----------------------------------------------------------------------------+
    '| Requirements | none                                                         |
    '+--------------+--------------------------------------------------------------+
    '| Version      | 1.0                                                          |
    '+--------------+--------------------------------------------------------------+
    '| File History:                                                               |
    '| +-------+----------+------------------------------------------------------+ |
    '| Name:   Ramon  Jimenez                                                      |
    '| Date:   Nov 25, 2004                                                        |
    '| Desc:   Creation and version 1.0                                            |
    '| +-------+----------+------------------------------------------------------+ |
    '+-----------------------------------------------------------------------------+
    Option Explicit
    CONST ForReading = 1
    CONST ForWriting = 2

    'Example
    FindAndReplace ".\\TEST.TXT", "Cadena1", "Cadena2"

    Sub FindAndReplace (StrFilename, strPattern, StrReplace)
    Dim oFSO, oFile, oRegExp, strData
     
     ' We open the File in ReadOnly mode and read it completely storing the
     'content into a  variable. Then close the file
     
     Set oFSO = CreateObject("Scripting.FileSystemObject")                                    
     Set oFile = oFSO.OpenTextFile(strFileName, ForReading)                                   
     strData = oFile.ReadAll                                                                  
     oFile.Close                                                                              
                                                                                              
     ' Once we have the variable we search the String we want to replace
     ' using a Regular Expression type variable. Then we use a method from
     ' this class to replace all ocurrences
     
     Set oRegexp = New Regexp                                                                 
     oRegexp.Pattern = strPattern                                                             
     oRegexp.Global = TRUE                                                                    
     oRegexp.IgnoreCase = True                                                                
     strData = oRegexp.Replace(strData, strReplace)                                           
                                                                                              
     ' We open again the file in Write mode and dump the content of the variable
     ' into the file
     Set oFile = oFSO.OpenTextFile(strFileName, ForWriting)                                   
     oFile.Write strData                                                                      
     oFile.Close   
    End Sub                                             

     

    viernes, 28 de septiembre de 2007 14:34

Todas las respuestas

  • Se me ocurre que podrias hacer un script que

    1)  net stop servicio
    2) Tener el archivo modificado en una ruta de red , y copiarlo con robocopy o xcopy
    3) net start servicio

    Slds
    Sebastian del Rio

    viernes, 28 de septiembre de 2007 12:38
  •  

    Es muy facil...

     

    En ScriptCenter tienes ejemplos de como parar y arrancar un servicio y sus dependientes:

     

    Parar:

    http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb25.mspx?mfr=true

     

    Arrancar:

    http://www.microsoft.com/technet/scriptcenter/scripts/os/services/ossvvb23.mspx?mfr=true

     

    Ejemplo de cambiar texto en un fichero:

     

    '+--------------+--------------------------------------------------------------+
    '| File:        | FindReplace.VBS                                              |
    '| Purpose:     | Find all ocurences of a String1 in a given file and replace  |
    '|              | it with  String 2                                            |
    '+--------------+--------------------------------------------------------------+
    '| Author:      | Ramon Jimenez                                                |
    '| Date:        | Nov 25, 2004                                                 |
    '+-----------------------------------------------------------------------------+
    '| Parameters   | Filename, StrtoReplace, StrReplacement                       |
    '+-----------------------------------------------------------------------------+
    '| Requirements | none                                                         |
    '+--------------+--------------------------------------------------------------+
    '| Version      | 1.0                                                          |
    '+--------------+--------------------------------------------------------------+
    '| File History:                                                               |
    '| +-------+----------+------------------------------------------------------+ |
    '| Name:   Ramon  Jimenez                                                      |
    '| Date:   Nov 25, 2004                                                        |
    '| Desc:   Creation and version 1.0                                            |
    '| +-------+----------+------------------------------------------------------+ |
    '+-----------------------------------------------------------------------------+
    Option Explicit
    CONST ForReading = 1
    CONST ForWriting = 2

    'Example
    FindAndReplace ".\\TEST.TXT", "Cadena1", "Cadena2"

    Sub FindAndReplace (StrFilename, strPattern, StrReplace)
    Dim oFSO, oFile, oRegExp, strData
     
     ' We open the File in ReadOnly mode and read it completely storing the
     'content into a  variable. Then close the file
     
     Set oFSO = CreateObject("Scripting.FileSystemObject")                                    
     Set oFile = oFSO.OpenTextFile(strFileName, ForReading)                                   
     strData = oFile.ReadAll                                                                  
     oFile.Close                                                                              
                                                                                              
     ' Once we have the variable we search the String we want to replace
     ' using a Regular Expression type variable. Then we use a method from
     ' this class to replace all ocurrences
     
     Set oRegexp = New Regexp                                                                 
     oRegexp.Pattern = strPattern                                                             
     oRegexp.Global = TRUE                                                                    
     oRegexp.IgnoreCase = True                                                                
     strData = oRegexp.Replace(strData, strReplace)                                           
                                                                                              
     ' We open again the file in Write mode and dump the content of the variable
     ' into the file
     Set oFile = oFSO.OpenTextFile(strFileName, ForWriting)                                   
     oFile.Write strData                                                                      
     oFile.Close   
    End Sub                                             

     

    viernes, 28 de septiembre de 2007 14:34