none
Scritp para verificar valor no registro e crie log. RRS feed

  • Pergunta

  • Ola pessoal, estou batendo a cabeça usando uns scripts que o Jesiel, me mandou em outro momento, o que gostaria de fazer é com esse codigo ou de outra forma, eu gostaria de um scritp que verifique no registro a chave referente ao proxy conforme abaixo e pegasse o valor e gerasse um log com o nome da maquina, ip, quem logou e a hora o que esse scritp ja faz mais necessito de mais uma informaçao, se a chave na estaçao esta conforme descrito no scritp, vindo com a informaçao OK sendo valor igual ao do scritp, caso o valor sejá outro, colher o valor que esta no registro da estaçao e jogar no log, tem como fazer isso ????
    e claro mantendo a funçao muito legal desse script que o Jesiel me passou, caso o log exista, ele nao roda de novo caso o log nao exista ele roda.

    Abraço a todos.

    No aguardo.


    Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
    Dim intConstants, intTimeout, strTitle, intCount, blnLog
    Dim strUserName, strComputerName, strIP, strShare, strLogFile

    strShare = "\\servidor\compartilhamento\"

    intTimeout = 20

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("Wscript.Network")
    Set objShell = CreateObject("Wscript.Shell")

    strUserName = objNetwork.Username
    strLogFile = objNetWork.Computername & ".txt"
    strComputerName = objNetwork.ComputerName
    strIP =  GetIPAddresses 'Join(GetIPAddresses())

    If (objFSO.FolderExists(strShare) = True) Then
        On Error Resume Next
       if not objFSO.FileExists(strShare & "\" & strLogFile) Then
          Set objLogFile = objFSO.CreateTextFile(strShare & "\" & strLogFile , True)
           If (Err.Number = 0) Then
               ' Make three attempts to write to log file.
               intCount = 1
               blnLog = False
               Do Until intCount = 3
                   objLogFile.WriteLine "Logon ; "  & Now & " ; " _
                       & strComputerName & " ; " & strUserName & " " & strIP
                   If (Err.Number = 0) Then
                       intCount = 3
                       blnLog = True
                   Else
                       Err.Clear
                       intCount = intCount + 1
                       If (Wscript.Version > 5) Then
                           Wscript.Sleep 200
                       End If
                   End If

    ' Verifica chave / log.
                  
    '-----------------------------------------------------------------------------------

    Const HKLM = &H80000002
    set objshell = createobject("wscript.shell")
     strComputer = "."
     Set oReg=GetObject("winmgmts:\\" & _
        strComputer & "\root\default:StdRegProv")
     
    oReg.GetStringValue HKCU,"Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "servidorproxy:80","Type",strValue1


    If IsNull(strValue1) Then
        objshell.run "\\servidor\compartilhamento\log.log"
    End If

     
    '----------------------------------------------------------------------------------
                  
               Loop
               On Error GoTo 0
               If (blnLog = False) Then
                   strTitle = "Logon Error"
                   strText = "Log cannot be written."
                   strText = strText & vbCrlf _
                       & "Another process may have log file open."
                   intConstants = vbOKOnly + vbExclamation
                   intAns = objShell.Popup(strText, intTimeout, strTitle, _
                       intConstants)
               End If
               objLogFile.Close
           Else
               On Error GoTo 0
               strTitle = "Logon Error"
               strText = "Log cannot be written."
               strText = strText & vbCrLf & "User may not have permissions,"
               strText = strText & vbCrLf & "or log folder may not be shared."
               intConstants = vbOKOnly + vbExclamation
               intAns = objShell.Popup(strText, intTimeout, strTitle, intConstants)
           End If
           Set objLogFile = Nothing
       End if
    End If

    Set objFSO = Nothing
    Set objNetwork = Nothing
    Set objShell = Nothing

    Wscript.Quit

    Function GetIPAddresses()
    Dim Loc,WbemServices,Adapters,Adapter
    Set loc = CreateObject( "WbemScripting.SWbemLocator" )
    Set WbemServices = loc.ConnectServer( ,"root\cimv2" )
    Set Adapters=WbemServices.ExecQuery( "Select * FROM" & _
    " Win32_NetworkAdapterConfiguration" )
    For Each Adapter in Adapters
       If NOT IsNull( Adapter.IPAddress) Then
         if  Left(Adapter.IPAddress(0),1) > 0 Then
            strIP = Adapter.IPAddress(0)
         End if
       
       End If
    Next
    GetIPAddresses = strIP
    End Function

    quarta-feira, 1 de julho de 2009 21:35

Respostas

  • Olá,

    Segue o script abaixo:


    Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
    Dim intConstants, intTimeout, strTitle, intCount, blnLog
    Dim strUserName, strComputerName, strIP, strShare, strLogFile



    ' Verifica chave / log.
                 
    '-----------------------------------------------------------------------------------
    Set objShell = CreateObject("WScript.Shell")
    strValorProxy= objShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

    if isnull(strValorProxy) Then
       strValorProxy = "SEM PROXY"
    End if
    '----------------------------------------------------------------------------------


    strShare = "\\servidor\compartilhamento\"
    intTimeout = 20

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("Wscript.Network")
    Set objShell = CreateObject("Wscript.Shell")

    strUserName = objNetwork.Username
    strLogFile = objNetWork.Computername & ".txt"
    strComputerName = objNetwork.ComputerName
    strIP =  GetIPAddresses 'Join(GetIPAddresses())

    If (objFSO.FolderExists(strShare) = True) Then
        On Error Resume Next
       if not objFSO.FileExists(strShare & "\" & strLogFile) Then
          Set objLogFile = objFSO.CreateTextFile(strShare & "\" & strLogFile , True)
           If (Err.Number = 0) Then
               ' Make three attempts to write to log file.
               intCount = 1
               blnLog = False
               Do Until intCount = 3
                   objLogFile.WriteLine "Logon ; "  & Now & " ; " _
                       & strComputerName & " ; " & strUserName & " " & strIP & " ;  PROXY: " & strValorProxy
                   If (Err.Number = 0) Then
                       intCount = 3
                       blnLog = True
                   Else
                       Err.Clear
                       intCount = intCount + 1
                       If (Wscript.Version > 5) Then
                           Wscript.Sleep 200
                       End If
                   End If


                 
               Loop
               On Error GoTo 0
               If (blnLog = False) Then
                   strTitle = "Logon Error"
                   strText = "Log cannot be written."
                   strText = strText & vbCrlf _
                       & "Another process may have log file open."
                   intConstants = vbOKOnly + vbExclamation
                   intAns = objShell.Popup(strText, intTimeout, strTitle, _
                       intConstants)
               End If
               objLogFile.Close
           Else
               On Error GoTo 0
               strTitle = "Logon Error"
               strText = "Log cannot be written."
               strText = strText & vbCrLf & "User may not have permissions,"
               strText = strText & vbCrLf & "or log folder may not be shared."
               intConstants = vbOKOnly + vbExclamation
               intAns = objShell.Popup(strText, intTimeout, strTitle, intConstants)
           End If
           Set objLogFile = Nothing
       End if
    End If

    Set objFSO = Nothing
    Set objNetwork = Nothing
    Set objShell = Nothing

    Wscript.Quit

    Function GetIPAddresses()
    Dim Loc,WbemServices,Adapters,Adapter
    Set loc = CreateObject( "WbemScripting.SWbemLocator" )
    Set WbemServices = loc.ConnectServer( ,"root\cimv2" )
    Set Adapters=WbemServices.ExecQuery( "Select * FROM" & _
    " Win32_NetworkAdapterConfiguration" )
    For Each Adapter in Adapters
       If NOT IsNull( Adapter.IPAddress) Then
         if  Left(Adapter.IPAddress(0),1) > 0 Then
            strIP = Adapter.IPAddress(0)
         End if
      
       End If
    Next
    GetIPAddresses = strIP
    End Function



    Faça os testes e nos retorne.

    Até mais,

    Jesiel

    Obs.: Se útil, classifique
    • Marcado como Resposta Marcelo TI domingo, 5 de julho de 2009 18:34
    quinta-feira, 2 de julho de 2009 17:20

Todas as Respostas

  • Alguma luz para solucionar a questão ????
    quinta-feira, 2 de julho de 2009 02:14
  • Olá,

    Segue o script abaixo:


    Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
    Dim intConstants, intTimeout, strTitle, intCount, blnLog
    Dim strUserName, strComputerName, strIP, strShare, strLogFile



    ' Verifica chave / log.
                 
    '-----------------------------------------------------------------------------------
    Set objShell = CreateObject("WScript.Shell")
    strValorProxy= objShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

    if isnull(strValorProxy) Then
       strValorProxy = "SEM PROXY"
    End if
    '----------------------------------------------------------------------------------


    strShare = "\\servidor\compartilhamento\"
    intTimeout = 20

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("Wscript.Network")
    Set objShell = CreateObject("Wscript.Shell")

    strUserName = objNetwork.Username
    strLogFile = objNetWork.Computername & ".txt"
    strComputerName = objNetwork.ComputerName
    strIP =  GetIPAddresses 'Join(GetIPAddresses())

    If (objFSO.FolderExists(strShare) = True) Then
        On Error Resume Next
       if not objFSO.FileExists(strShare & "\" & strLogFile) Then
          Set objLogFile = objFSO.CreateTextFile(strShare & "\" & strLogFile , True)
           If (Err.Number = 0) Then
               ' Make three attempts to write to log file.
               intCount = 1
               blnLog = False
               Do Until intCount = 3
                   objLogFile.WriteLine "Logon ; "  & Now & " ; " _
                       & strComputerName & " ; " & strUserName & " " & strIP & " ;  PROXY: " & strValorProxy
                   If (Err.Number = 0) Then
                       intCount = 3
                       blnLog = True
                   Else
                       Err.Clear
                       intCount = intCount + 1
                       If (Wscript.Version > 5) Then
                           Wscript.Sleep 200
                       End If
                   End If


                 
               Loop
               On Error GoTo 0
               If (blnLog = False) Then
                   strTitle = "Logon Error"
                   strText = "Log cannot be written."
                   strText = strText & vbCrlf _
                       & "Another process may have log file open."
                   intConstants = vbOKOnly + vbExclamation
                   intAns = objShell.Popup(strText, intTimeout, strTitle, _
                       intConstants)
               End If
               objLogFile.Close
           Else
               On Error GoTo 0
               strTitle = "Logon Error"
               strText = "Log cannot be written."
               strText = strText & vbCrLf & "User may not have permissions,"
               strText = strText & vbCrLf & "or log folder may not be shared."
               intConstants = vbOKOnly + vbExclamation
               intAns = objShell.Popup(strText, intTimeout, strTitle, intConstants)
           End If
           Set objLogFile = Nothing
       End if
    End If

    Set objFSO = Nothing
    Set objNetwork = Nothing
    Set objShell = Nothing

    Wscript.Quit

    Function GetIPAddresses()
    Dim Loc,WbemServices,Adapters,Adapter
    Set loc = CreateObject( "WbemScripting.SWbemLocator" )
    Set WbemServices = loc.ConnectServer( ,"root\cimv2" )
    Set Adapters=WbemServices.ExecQuery( "Select * FROM" & _
    " Win32_NetworkAdapterConfiguration" )
    For Each Adapter in Adapters
       If NOT IsNull( Adapter.IPAddress) Then
         if  Left(Adapter.IPAddress(0),1) > 0 Then
            strIP = Adapter.IPAddress(0)
         End if
      
       End If
    Next
    GetIPAddresses = strIP
    End Function



    Faça os testes e nos retorne.

    Até mais,

    Jesiel

    Obs.: Se útil, classifique
    • Marcado como Resposta Marcelo TI domingo, 5 de julho de 2009 18:34
    quinta-feira, 2 de julho de 2009 17:20
  • Jesiel

    Show rolou legal, o result do proxy valor vem com o proxy que esta na estaçao ja resolve o problema, so uma questão, essa parte

    ' Verifica chave / log.
                 
    '-----------------------------------------------------------------------------------
    Set objShell = CreateObject("WScript.Shell")
    strValorProxy= objShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

    if isnull(strValorProxy) Then
       strValorProxy = "SEM PROXY"
    End if
    '----------------------------------------------------------------------------------


    nao poderia ficar entre essas duas partes, caso não por favor me informe pois estou criando mutações desse scritp de log com coisas para rodar entre esses conjuntos abaixo.

    Valeu.

                      blnLog = True
                   Else
                       Err.Clear
                       intCount = intCount + 1
                       If (Wscript.Version > 5) Then
                           Wscript.Sleep 200
                       End If
                   End If

    ((((((((( aqui )))))))))))
                 
               Loop
               On Error GoTo 0
               If (blnLog = False) Then
                   strTitle = "Logon Error"
                   strText = "Log cannot be written."
                   strText = strText & vbCrlf _

    quinta-feira, 2 de julho de 2009 21:16
  • Olá,

    Pode sim, desde que seja antes do loop...

    Até mais,

    Jesiel

    Obs.: Se útil, classifique
    sexta-feira, 3 de julho de 2009 12:23
  • legal assim as mutações que estou criando vao rolar...

    vem ca tem como se ele achar um valor x ele trocar por y.

    Caso vc ache melhor abrir outro post com essa questão é só falar que eu abro.

    obrigado mais uma vez.
    sexta-feira, 3 de julho de 2009 20:22