Usuário com melhor resposta
Gerar log sobre legenda.

Pergunta
-
Ba galera oia eu de novo tche.
como posso fazer para colocar nesse scritp uma legenda, para que seja usada como referencia na criação do log para colocar sim ou nao na frente da informação levandata no registro, por exemplo:
strLegenda
Central de segurança = 4 no log ele coloque o caminho da chave e valor como o codigo abaixo ja faz mais na frente ele coloque tb a palavra sim, caso o valor for outro ele coloque não.
Codigo.
Set WshNetwork = WScript.CreateObject("WScript.Network")
set FSO = createobject("scripting.filesystemobject")
Set shell = createobject("wscript.shell")
computador = UCASE(WshNetwork.ComputerName)
strLog = "c:\" & computadorif fso.folderexists(strLog) = false then
set objfolder = fso.createfolder(strLog)
End IfDim objFSO, objLogFile, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog
Dim strUserName, strComputerName, strIP, strShare, strLogFile'-----------------------------------------------------------------------------------
Set objShell = CreateObject("WScript.Shell")
'****************************************************************************************************
strValor = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\SharedAccess\Start")
strValor1 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Start")'*****************************************************************************************************
strValor2 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wscsvc\Start")
strValor3 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wscsvc\Start")
'***********************************************************************************
strValor4 = objShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDriveTypeAutoRun")'***************************************************************************************
strValor5 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wuauserv\Start")
strValor6 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\Start")
intTimeout = 20Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")strUserName = objNetwork.Username
'strLogFile = objNetWork.Computername & ".log"
strLogFile = "\Serviços.log"
strComputerName = objNetwork.ComputerName
strIP = GetIPAddresses 'Join(GetIPAddresses())If (objFSO.FolderExists(strLog) = True) Then
On Error Resume Next
if not objFSO.FileExists(strLog & "\" & strLogFile) Then
Set objLogFile = objFSO.CreateTextFile(strLog & "\" & 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 "" & now & vbCrLf
objLogFile.WriteLine "****************************************************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor1 & vbCrLf
objLogFile.WriteLine "*****************************************************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor2 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor3 & vbCrLf
objLogFile.WriteLine "***********************************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor4 & vbCrLf
objLogFile.WriteLine "***************************************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor5 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor6 & vbCrLf
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 IfSet objFSO = Nothing
Set objNetwork = Nothing
Set objShell = NothingWscript.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- Editado Marcelo TI sexta-feira, 11 de setembro de 2009 16:28
Respostas
-
Olá,
Dá uma olhada no script abaixo, veja se é isso que você precisa.
Set WshNetwork = WScript.CreateObject("WScript.Network")
set FSO = createobject("scripting.filesystemobject")
Set shell = createobject("wscript.shell")
computador = UCASE(WshNetwork.ComputerName)
strLog = "c:\" & computador
'======== PADROES =========
strCentral = 0
strFirewall = 0
strAutorun = 0
strUpdate = 0
if fso.folderexists(strLog) = false then
set objfolder = fso.createfolder(strLog)
End If
Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog
Dim strUserName, strComputerName, strIP, strShare, strLogFile
'-----------------------------------------------------------------------------------
Set objShell = CreateObject("WScript.Shell")
'*********************************************Central de segurança*******************************************************
strValor = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\SharedAccess\Start")
strValor1 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Start")
'*********************************************Firewall do Windows********************************************************
strValor2 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wscsvc\Start")
strValor3 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wscsvc\Start")
'**********************************************Desativa Autorun de todas as Unidades*************************************
strValor4 = objShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDriveTypeAutoRun")
'************************************Desativa Atualizações Automaticas***************************************************
strValor5 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wuauserv\Start")
strValor6 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\Start")
intTimeout = 20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
strUserName = objNetwork.Username
'strLogFile = objNetWork.Computername & ".log"
strLogFile = "\Serviços.log"
strComputerName = objNetwork.ComputerName
strIP = GetIPAddresses 'Join(GetIPAddresses())
If (objFSO.FolderExists(strLog) = True) Then
On Error Resume Next
if not objFSO.FileExists(strLog & "\" & strLogFile) Then
Set objLogFile = objFSO.CreateTextFile(strLog & "\" & 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 "" & now & vbCrLf
IF strValor = strCentral Then
strStatus = " CORRETO"
Else
strStatus = " ERRADO"
End if
IF strValor1 = strCentral Then
strStatus1 = " CORRETO"
Else
strStatus1 = " ERRADO"
End if
IF strValor2 = strFirewall Then
strStatus2 = " CORRETO"
Else
strStatus2 = " ERRADO"
End if
IF strValor3 = strFirewall Then
strStatus3 = " CORRETO"
Else
strStatus3 = " ERRADO"
End if
IF strValor4 = strAutorun Then
strStatus4 = " CORRETO"
Else
strStatus4 = " ERRADO"
End if
IF strValor5 = strUpdate Then
strStatus5 = " CORRETO"
Else
strStatus5 = " ERRADO"
End if
IF strValor6 = strCentral Then
strStatus6 = " CORRETO"
Else
strStatus6 = " ERRADO"
End if
objLogFile.WriteLine "******************************Central de segurança**********************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor & strStatus & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor1 & strStatus1 & vbCrLf
objLogFile.WriteLine "*******************************Firewall do Windows**********************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor2 & strStatus2 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor3 & strStatus3 & vbCrLf
objLogFile.WriteLine "*******************************Desativa Autorun de todas as Unidades****************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor4 & strStatus4 & vbCrLf
objLogFile.WriteLine "*******************************Desativa Atualizações Automaticas********************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor5 & strStatus5 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor6 & strStatus6 & vbCrLf
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
Talvez não seja a melhor maneira, mas acredito que seja isso que você precisa.
Até mais,
Jesiel
Obs.: Se útil, classifique
- Marcado como Resposta Marcelo TI sexta-feira, 11 de setembro de 2009 16:29
Todas as Respostas
-
-
Ba Jesiel
Vamos la...
no corpo do scritp eu teria uma legenda com os valores da seguinte forma:
Central de Serviço = 0
Firewall do Windows = 0
ai ele roda o corpo todo assim que ja gera um log com o nome da chave e o valor que esta gravado no registro o que quero e colocar uma linha a mais a frente dessa informação com a palavra correto ou errado, caso o valor no registro seja diferente do valor da legenda ele coloque errado caso seja igual ele coleque correto no log que esta sendo gerado, mais com um detalhe, se o valor da chave do registro for diferente do valor da legenda, ele só coloque a informação no log, e não altere nada no registro da estação.
abraço.... -
Olá,
Dá uma olhada no script abaixo, veja se é isso que você precisa.
Set WshNetwork = WScript.CreateObject("WScript.Network")
set FSO = createobject("scripting.filesystemobject")
Set shell = createobject("wscript.shell")
computador = UCASE(WshNetwork.ComputerName)
strLog = "c:\" & computador
'======== PADROES =========
strCentral = 0
strFirewall = 0
strAutorun = 0
strUpdate = 0
if fso.folderexists(strLog) = false then
set objfolder = fso.createfolder(strLog)
End If
Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog
Dim strUserName, strComputerName, strIP, strShare, strLogFile
'-----------------------------------------------------------------------------------
Set objShell = CreateObject("WScript.Shell")
'*********************************************Central de segurança*******************************************************
strValor = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\SharedAccess\Start")
strValor1 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Start")
'*********************************************Firewall do Windows********************************************************
strValor2 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wscsvc\Start")
strValor3 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wscsvc\Start")
'**********************************************Desativa Autorun de todas as Unidades*************************************
strValor4 = objShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDriveTypeAutoRun")
'************************************Desativa Atualizações Automaticas***************************************************
strValor5 = objShell.RegRead("HKLM\SYSTEM\ControlSet001\Services\wuauserv\Start")
strValor6 = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\Start")
intTimeout = 20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
strUserName = objNetwork.Username
'strLogFile = objNetWork.Computername & ".log"
strLogFile = "\Serviços.log"
strComputerName = objNetwork.ComputerName
strIP = GetIPAddresses 'Join(GetIPAddresses())
If (objFSO.FolderExists(strLog) = True) Then
On Error Resume Next
if not objFSO.FileExists(strLog & "\" & strLogFile) Then
Set objLogFile = objFSO.CreateTextFile(strLog & "\" & 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 "" & now & vbCrLf
IF strValor = strCentral Then
strStatus = " CORRETO"
Else
strStatus = " ERRADO"
End if
IF strValor1 = strCentral Then
strStatus1 = " CORRETO"
Else
strStatus1 = " ERRADO"
End if
IF strValor2 = strFirewall Then
strStatus2 = " CORRETO"
Else
strStatus2 = " ERRADO"
End if
IF strValor3 = strFirewall Then
strStatus3 = " CORRETO"
Else
strStatus3 = " ERRADO"
End if
IF strValor4 = strAutorun Then
strStatus4 = " CORRETO"
Else
strStatus4 = " ERRADO"
End if
IF strValor5 = strUpdate Then
strStatus5 = " CORRETO"
Else
strStatus5 = " ERRADO"
End if
IF strValor6 = strCentral Then
strStatus6 = " CORRETO"
Else
strStatus6 = " ERRADO"
End if
objLogFile.WriteLine "******************************Central de segurança**********************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor & strStatus & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor1 & strStatus1 & vbCrLf
objLogFile.WriteLine "*******************************Firewall do Windows**********************************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor2 & strStatus2 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor3 & strStatus3 & vbCrLf
objLogFile.WriteLine "*******************************Desativa Autorun de todas as Unidades****************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor4 & strStatus4 & vbCrLf
objLogFile.WriteLine "*******************************Desativa Atualizações Automaticas********************************************************" & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor5 & strStatus5 & vbCrLf
objLogFile.WriteLine "Valor de Definição: " & strValor6 & strStatus6 & vbCrLf
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
Talvez não seja a melhor maneira, mas acredito que seja isso que você precisa.
Até mais,
Jesiel
Obs.: Se útil, classifique
- Marcado como Resposta Marcelo TI sexta-feira, 11 de setembro de 2009 16:29
-