none
Script Altera Senha VNC RRS feed

  • Pergunta

  •  

    Caros,

     

    Alguem conhece algum script o qual eu possa estar utilizando em minha rede, para estar alterando a senha do VNC???

    Pois teem ocorrido alguns problemas, os quais eu gostaria de sana-los.

     

    Agradeço desde já á todos.

     

    Atenciosamente

    Kelsen Lima

    quinta-feira, 2 de outubro de 2008 16:12

Respostas

  • Segue seu script:
    Fonte: http://www.ureader.com/msg/1675960.aspx
    Só procurei no google
    Caso não queira usar o script, tem o
    VNC Password Set 2.0
    http://www.download3000.com/download_16102.html
    é free.



    '************************************************************************'* File:       ChangeVNCPwd.vbs
    '* Created by: Curtis Wong
    '* Version: 3.0
    '*
    '* Function: Change WinVNC Password in Domain
    '*
    '************************************************************************Option Explicit

    Dim strDomain, wn

    'Make sure the host is csript, if not then abort
    VerifyHostIsCScript

    ' Get the current domain name
    Set wn = WScript.CreateObject("WScript.Network")
    strDomain = UCase(CStr(wn.userdomain))
    Set wn = Nothing

    If strDomain <> "" then
    Dim objDomain, objChild, objFSO, objError
    Dim objLogFile, objReg, objOS, objShell
    Dim CurDir, strLogFile, strComputer, strSourceComputer, strOS, strWMI
    Dim strHKCUKeyPath, strHKLMKeyPath, strValueName, strValue

    ' Define registry constants & variables
    Const HKCU = &H80000001 'HKEY_CURRENT_USER
    Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    strHKCUKeyPath = "Software\ORL\WinVNC3"
    strHKLMKeyPath = "Software\ORL\WinVNC3\Default"
    strValueName = "Password"

    ' Read VNC password from "HKLM\Software\ORL\WinVNC3\Default\Password"
    ' of Local Machine
    Set objShell = WScript.CreateObject("WScript.Shell")
    strValue = objShell.RegRead("HKLM\Software\ORL\WinVNC3\Default\Password")
    Set objShell = Nothing

    ' Create a File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' Define the location of the log file, same as that of this script file
    CurDir = objFSO.GetParentFolderName(Wscript.ScriptFullName)
    strLogFile = CurDir & "\Result.log"

    ' Delete the current log file & create a new log file
    If objFSO.FileExists(strLogFile) Then objFSO.DeleteFile strLogFile, True
    Set objLogFile = objFSO.CreateTextFile(strLogFile, True)

    ' Create Domain Object
    Set objDomain = GetObject("WinNT://" & strDomain)

    WScript.Echo "========================================================" & vbCrLf

    For Each objChild In objDomain

    strComputer = CStr(objChild.Name)

    WriteLine "Attempting to change the VNC password to " & strComputer & vbCrLf, objLogFile

    If IsAlive(strComputer) Then

    ' Create the windows management string
    strWMI = "winmgmts:" _
    & "{impersonationLevel=Impersonate," _
    & "authenticationLevel=PktPrivacy}!" _
    & "\\" & strComputer & "\root\"

    ' Obtain the Windows version of the computer
    ' "On Error Resume Next" is used for the interrupt prevention
    ' when a Windows 9x or Windows NT machine is detected
    strOS = ""
    On Error Resume Next
    For each objOS in GetObject(strWMI & "CIMV2").InstancesOf("Win32_OperatingSystem")
    strOS = CStr(objOS.Caption)
    Next

    ' Clear Error
    Err.Clear

    ' In order to avoid error from detecting Windows 9x and Windows NT
    ' or an error will be obtained at 'Set objReg = GetObject'
    ' When a Windows 9x or Windows NT is detected, strOS = ""
    If strOS <> "" Then

    ' Create remote connection
    CreateObject("WbemScripting.SWbemLocator").ConnectServer _
    strComputer, "root\default"

    ' Get registry Object
    Set objReg = GetObject(strWMI & "defaultTongue TiedtdRegProv")

    ' Define error object
    Set objError = Err
    If objError.number = 0 Then
    WriteLine "Writing the VNC password to ""HKEY_CURRENT_USER\" & _
    strHKCUKeyPath & "\" & strValueName & """" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKCU, strHKCUKeyPath, strValueName, strValue
    WriteLine "Writing the VNC password to ""HKEY_LOCAL_MACHINE\" & _
    strHKLMKeyPath & "\" & strValueName & """" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKLM, strHKLMKeyPath, strValueName, strValue
    WriteLine "Writing the VNC password to ""HKEY_LOCAL_MACHINE\" & _
    strHKLMKeyPath & "\PasswordViewOnly""" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKLM, strHKLMKeyPath, "PasswordViewOnly", strValue
    End if
    ErrorHandler objError
    Else
    WriteLine "Windows version of " & strComputer & " is not allowed to update" & _
    vbCrLf, objLogFile
    End If
    Else
    WriteLine strComputer & " is not reachable" & vbCrLf, objLogFile
    End If
    Next

    Set objError = Nothing: Set objReg = Nothing: Set objDomain = Nothing
    Set objChild = Nothing: Set objFSO = Nothing: Set objLogFile = Nothing

    WScript.Echo "========================================================" & vbCrLf
    WScript.Echo "Results are saved in " & strLogFile & "."
    End If

    '************************************************************************'* Sub ErrorHandler(ByVal code)
    '* Purpose: Write result in the log file
    '* Input: Code number from Err.Number
    '*
    '************************************************************************Sub ErrorHandler(ByRef code)
    If code.Number = 0 Then
    WriteLine "VNC password was changed successfully on " & strComputer _
    & vbCrLf, objLogFile
    ElseIf code.Number = 429 Then
    WriteLine "Error! " & strComputer & " is improper version to accept" _
    & "the update (check WMI/OS version)" & vbCrLf
    Else
    WriteLine "Error! " & strComputer & " returned an error " _
    & "0x" & CStr(Hex(code.Number)) & vbCrLf _
    & "Error description : " & code.Description & vbCrLf, objLogFile
    End If
    End Sub

    '************************************************************************'* Function IsAlive(ByVal strComputer)
    '* Purpose: Check whehther the machine is alive or not.
    '* Input: Computer name
    '* Output: True for alive and False for not alive.
    '*
    '************************************************************************Function IsAlive(ByVal strComputer)
    Dim wshShell, oResult, tmp

    ' Create Shell object
    Set wshShell = CreateObject("WScript.Shell")

    ' Use the shell to run the DOS Ping command.
    ' -n 1 = send only 1 ping packet
    ' -w 500 = wait for a maximum of 500ms for reply
    Set oResult = wshShell.Exec("PING -n 1 -w 500 " & strComputer)

    ' Get the output of our DOS command
    ' Note: No temp files like some other solutions
    tmp = oResult.StdOut.Readall

    ' Look for certain keywords to flag it as a
    ' non-responding computer. Note that this has ONLY been
    ' tested on Windows 2000, you will probably need to look
    ' for different keywords depending on what version of
    ' PING you are using (Win9x, NT, W2k, XP)

    If Instr(1, tmp, "TTL=") > 0 Then
    IsAlive = True
    Else
    IsAlive = False
    End If

    Set oResult = Nothing: Set wshShell = Nothing
    End Function

    '********************************************************************
    '*
    '* Sub WriteLine(ByVal strMessage, ByVal objFile)
    '* Purpose: Writes a text line either to a file or on screen.
    '* Input: strMessage the string to print
    '* objFile an output file object
    '*
    '********************************************************************

    Sub WriteLine(ByVal strMessage, ByVal objFile)
    On Error Resume Next
    If IsObject(objFile) Then 'objFile should be a file object
    objFile.WriteLine strMessage
    Wscript.Echo strMessage
    Else
    Wscript.Echo strMessage
    End If
    End Sub

    '********************************************************************
    '*
    '* Sub VerifyHostIsCscript()
    '* Purpose: Determines which program is used to run this script.
    '* Input: None
    '* Output: If host is not cscript, then an error message is printed
    '* and the script is aborted.
    '*
    '********************************************************************

    Sub VerifyHostIsCScript()

    Dim strFullName, strCommand, i, j, intStatus

    CONST CONST_ERROR = 0
    CONST CONST_WSCRIPT = 1
    CONST CONST_CSCRIPT = 2
    strFullName = WScript.FullName

    On Error Resume Next
    If Err.Number then
    Wscript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred."
    If Err.Description <> "" Then
    Wscript.Echo "Error description: " & Err.Description & "."
    End If
    intStatus = CONST_ERROR
    End If

    i = InStr(1, strFullName, ".exe", 1)
    If i = 0 Then
    intStatus = CONST_ERROR
    Else
    j = InStrRev(strFullName, "\", i, 1)
    If j = 0 Then
    intStatus = CONST_ERROR
    Else
    strCommand = Mid(strFullName, j, i-j-1)
    Select Case LCase(strCommand)
    Case "cscript"
    intStatus = CONST_CSCRIPT
    Case "wscript"
    intStatus = CONST_WSCRIPT
    Case Else 'should never happen
    Wscript.Echo "An unexpected program was used to " _
    & "run this script."
    Wscript.Echo "Only CScript.Exe or WScript.Exe can " _
    & "be used to run this script."
    intStatus = CONST_ERROR
    End Select
    End If
    End If

    If intStatus <> CONST_CSCRIPT Then
    WScript.Echo "Please run this script using CScript." & vbCrLf & _
    "This can be achieved by" & vbCrLf & _
    "1. Using ""CScript ChangeVNCPwd.vbs"" for Windows 2000/XP/Server 2003 or" _
    & vbCRLF & "2. Changing the default Windows Scripting Host " _
    & "setting to CScript" & vbCrLf & " using ""CScript " _
    & "//H:CScript //S"" and running the script using" & vbCrLf & _
    " ""ChangeVNCPwd.vbs"" for Windows 2000/XP/Server 2003."
    WScript.Quit
    End If

    End Sub


    '--------------------------->8-------------------------------------


    terça-feira, 7 de outubro de 2008 14:00
  • Romeu,

     

    Então acabei utilizando outras formas de estar fazendo isso, uma delas está citada abaixo e outra é similiar só acrescenta um arquivo *.vbs chamando o reg.

    Achei muito bom a fonte qual você esteve informando, terei fazendo alguns testes com tal script, mas também fica ae citado abaixo uma outra opção para aqueles que também poderão vir a ter as mesmas necessidades.

     

    ### Trocando a senha do administrador do VNC ###
     ##   remotamente via GPO - Group Policy   ##


    1º - Passo: Definir uma senha qual você desejar no VNC, apôs isso reiniciar sua máquina.
    2º - Passo: Digitar no executar "regedit" e acessar a seguinte chave de registro "HKEY_LOCAL_MACHINE\SOFTWARE\ORL".
    3º - Passo: Apôs ter acessado a chave clicar com lado esquerdo do mouse sob ela e expotrar, destinando o local e seu respectivo nome.
    4º - Passo: Digitar no executar "notepad" e digite a seguinte string "regedit /s \\172.16.100.1\netlogon\vnc1.reg" e salve como *.cmd,lembrando que alguns dados terão quer ser alterados, conforme sua rede e qual nome você salvou o arquivo *.reg.
    5º - Passo: Criar uma GPO Group Policy, ir em User Configuration ou Computer Configuration > Windows Settings > Scripts > Logon > Clicar em Logon > Show Files e colocar o arquivo .*cmd neste local ou apontar para outro destino.

    Obs.: Não esqueça de fazer as alterações necessarias no arquivo de acordo com sua rede e os locais aonde foram salvos.

     

    Atenciosamente
    Kelsen Lima

    quarta-feira, 8 de outubro de 2008 02:27

Todas as Respostas


  • Quais problemas?
    qq aconteceu ?

    sexta-feira, 3 de outubro de 2008 11:46
    Moderador
  •  

    Creio que o problema seje irrelevante, pois o que estou pedindo a comunidade, é que se alguém tem ou conhece, algum script o qual posso estar alterando a senha do VNC em todas as maquinas de meu parque.

    Casualmente já tenho uma solução de REGEDIT, mas outras informações para tal necessidade seria interessante.

     

    Att.

    Kelsen Lima

    domingo, 5 de outubro de 2008 16:54
  • Segue seu script:
    Fonte: http://www.ureader.com/msg/1675960.aspx
    Só procurei no google
    Caso não queira usar o script, tem o
    VNC Password Set 2.0
    http://www.download3000.com/download_16102.html
    é free.



    '************************************************************************'* File:       ChangeVNCPwd.vbs
    '* Created by: Curtis Wong
    '* Version: 3.0
    '*
    '* Function: Change WinVNC Password in Domain
    '*
    '************************************************************************Option Explicit

    Dim strDomain, wn

    'Make sure the host is csript, if not then abort
    VerifyHostIsCScript

    ' Get the current domain name
    Set wn = WScript.CreateObject("WScript.Network")
    strDomain = UCase(CStr(wn.userdomain))
    Set wn = Nothing

    If strDomain <> "" then
    Dim objDomain, objChild, objFSO, objError
    Dim objLogFile, objReg, objOS, objShell
    Dim CurDir, strLogFile, strComputer, strSourceComputer, strOS, strWMI
    Dim strHKCUKeyPath, strHKLMKeyPath, strValueName, strValue

    ' Define registry constants & variables
    Const HKCU = &H80000001 'HKEY_CURRENT_USER
    Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    strHKCUKeyPath = "Software\ORL\WinVNC3"
    strHKLMKeyPath = "Software\ORL\WinVNC3\Default"
    strValueName = "Password"

    ' Read VNC password from "HKLM\Software\ORL\WinVNC3\Default\Password"
    ' of Local Machine
    Set objShell = WScript.CreateObject("WScript.Shell")
    strValue = objShell.RegRead("HKLM\Software\ORL\WinVNC3\Default\Password")
    Set objShell = Nothing

    ' Create a File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' Define the location of the log file, same as that of this script file
    CurDir = objFSO.GetParentFolderName(Wscript.ScriptFullName)
    strLogFile = CurDir & "\Result.log"

    ' Delete the current log file & create a new log file
    If objFSO.FileExists(strLogFile) Then objFSO.DeleteFile strLogFile, True
    Set objLogFile = objFSO.CreateTextFile(strLogFile, True)

    ' Create Domain Object
    Set objDomain = GetObject("WinNT://" & strDomain)

    WScript.Echo "========================================================" & vbCrLf

    For Each objChild In objDomain

    strComputer = CStr(objChild.Name)

    WriteLine "Attempting to change the VNC password to " & strComputer & vbCrLf, objLogFile

    If IsAlive(strComputer) Then

    ' Create the windows management string
    strWMI = "winmgmts:" _
    & "{impersonationLevel=Impersonate," _
    & "authenticationLevel=PktPrivacy}!" _
    & "\\" & strComputer & "\root\"

    ' Obtain the Windows version of the computer
    ' "On Error Resume Next" is used for the interrupt prevention
    ' when a Windows 9x or Windows NT machine is detected
    strOS = ""
    On Error Resume Next
    For each objOS in GetObject(strWMI & "CIMV2").InstancesOf("Win32_OperatingSystem")
    strOS = CStr(objOS.Caption)
    Next

    ' Clear Error
    Err.Clear

    ' In order to avoid error from detecting Windows 9x and Windows NT
    ' or an error will be obtained at 'Set objReg = GetObject'
    ' When a Windows 9x or Windows NT is detected, strOS = ""
    If strOS <> "" Then

    ' Create remote connection
    CreateObject("WbemScripting.SWbemLocator").ConnectServer _
    strComputer, "root\default"

    ' Get registry Object
    Set objReg = GetObject(strWMI & "defaultTongue TiedtdRegProv")

    ' Define error object
    Set objError = Err
    If objError.number = 0 Then
    WriteLine "Writing the VNC password to ""HKEY_CURRENT_USER\" & _
    strHKCUKeyPath & "\" & strValueName & """" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKCU, strHKCUKeyPath, strValueName, strValue
    WriteLine "Writing the VNC password to ""HKEY_LOCAL_MACHINE\" & _
    strHKLMKeyPath & "\" & strValueName & """" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKLM, strHKLMKeyPath, strValueName, strValue
    WriteLine "Writing the VNC password to ""HKEY_LOCAL_MACHINE\" & _
    strHKLMKeyPath & "\PasswordViewOnly""" & vbCrLf, objLogFile
    objReg.SetBinaryValue HKLM, strHKLMKeyPath, "PasswordViewOnly", strValue
    End if
    ErrorHandler objError
    Else
    WriteLine "Windows version of " & strComputer & " is not allowed to update" & _
    vbCrLf, objLogFile
    End If
    Else
    WriteLine strComputer & " is not reachable" & vbCrLf, objLogFile
    End If
    Next

    Set objError = Nothing: Set objReg = Nothing: Set objDomain = Nothing
    Set objChild = Nothing: Set objFSO = Nothing: Set objLogFile = Nothing

    WScript.Echo "========================================================" & vbCrLf
    WScript.Echo "Results are saved in " & strLogFile & "."
    End If

    '************************************************************************'* Sub ErrorHandler(ByVal code)
    '* Purpose: Write result in the log file
    '* Input: Code number from Err.Number
    '*
    '************************************************************************Sub ErrorHandler(ByRef code)
    If code.Number = 0 Then
    WriteLine "VNC password was changed successfully on " & strComputer _
    & vbCrLf, objLogFile
    ElseIf code.Number = 429 Then
    WriteLine "Error! " & strComputer & " is improper version to accept" _
    & "the update (check WMI/OS version)" & vbCrLf
    Else
    WriteLine "Error! " & strComputer & " returned an error " _
    & "0x" & CStr(Hex(code.Number)) & vbCrLf _
    & "Error description : " & code.Description & vbCrLf, objLogFile
    End If
    End Sub

    '************************************************************************'* Function IsAlive(ByVal strComputer)
    '* Purpose: Check whehther the machine is alive or not.
    '* Input: Computer name
    '* Output: True for alive and False for not alive.
    '*
    '************************************************************************Function IsAlive(ByVal strComputer)
    Dim wshShell, oResult, tmp

    ' Create Shell object
    Set wshShell = CreateObject("WScript.Shell")

    ' Use the shell to run the DOS Ping command.
    ' -n 1 = send only 1 ping packet
    ' -w 500 = wait for a maximum of 500ms for reply
    Set oResult = wshShell.Exec("PING -n 1 -w 500 " & strComputer)

    ' Get the output of our DOS command
    ' Note: No temp files like some other solutions
    tmp = oResult.StdOut.Readall

    ' Look for certain keywords to flag it as a
    ' non-responding computer. Note that this has ONLY been
    ' tested on Windows 2000, you will probably need to look
    ' for different keywords depending on what version of
    ' PING you are using (Win9x, NT, W2k, XP)

    If Instr(1, tmp, "TTL=") > 0 Then
    IsAlive = True
    Else
    IsAlive = False
    End If

    Set oResult = Nothing: Set wshShell = Nothing
    End Function

    '********************************************************************
    '*
    '* Sub WriteLine(ByVal strMessage, ByVal objFile)
    '* Purpose: Writes a text line either to a file or on screen.
    '* Input: strMessage the string to print
    '* objFile an output file object
    '*
    '********************************************************************

    Sub WriteLine(ByVal strMessage, ByVal objFile)
    On Error Resume Next
    If IsObject(objFile) Then 'objFile should be a file object
    objFile.WriteLine strMessage
    Wscript.Echo strMessage
    Else
    Wscript.Echo strMessage
    End If
    End Sub

    '********************************************************************
    '*
    '* Sub VerifyHostIsCscript()
    '* Purpose: Determines which program is used to run this script.
    '* Input: None
    '* Output: If host is not cscript, then an error message is printed
    '* and the script is aborted.
    '*
    '********************************************************************

    Sub VerifyHostIsCScript()

    Dim strFullName, strCommand, i, j, intStatus

    CONST CONST_ERROR = 0
    CONST CONST_WSCRIPT = 1
    CONST CONST_CSCRIPT = 2
    strFullName = WScript.FullName

    On Error Resume Next
    If Err.Number then
    Wscript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred."
    If Err.Description <> "" Then
    Wscript.Echo "Error description: " & Err.Description & "."
    End If
    intStatus = CONST_ERROR
    End If

    i = InStr(1, strFullName, ".exe", 1)
    If i = 0 Then
    intStatus = CONST_ERROR
    Else
    j = InStrRev(strFullName, "\", i, 1)
    If j = 0 Then
    intStatus = CONST_ERROR
    Else
    strCommand = Mid(strFullName, j, i-j-1)
    Select Case LCase(strCommand)
    Case "cscript"
    intStatus = CONST_CSCRIPT
    Case "wscript"
    intStatus = CONST_WSCRIPT
    Case Else 'should never happen
    Wscript.Echo "An unexpected program was used to " _
    & "run this script."
    Wscript.Echo "Only CScript.Exe or WScript.Exe can " _
    & "be used to run this script."
    intStatus = CONST_ERROR
    End Select
    End If
    End If

    If intStatus <> CONST_CSCRIPT Then
    WScript.Echo "Please run this script using CScript." & vbCrLf & _
    "This can be achieved by" & vbCrLf & _
    "1. Using ""CScript ChangeVNCPwd.vbs"" for Windows 2000/XP/Server 2003 or" _
    & vbCRLF & "2. Changing the default Windows Scripting Host " _
    & "setting to CScript" & vbCrLf & " using ""CScript " _
    & "//H:CScript //S"" and running the script using" & vbCrLf & _
    " ""ChangeVNCPwd.vbs"" for Windows 2000/XP/Server 2003."
    WScript.Quit
    End If

    End Sub


    '--------------------------->8-------------------------------------


    terça-feira, 7 de outubro de 2008 14:00
  • Romeu,

     

    Então acabei utilizando outras formas de estar fazendo isso, uma delas está citada abaixo e outra é similiar só acrescenta um arquivo *.vbs chamando o reg.

    Achei muito bom a fonte qual você esteve informando, terei fazendo alguns testes com tal script, mas também fica ae citado abaixo uma outra opção para aqueles que também poderão vir a ter as mesmas necessidades.

     

    ### Trocando a senha do administrador do VNC ###
     ##   remotamente via GPO - Group Policy   ##


    1º - Passo: Definir uma senha qual você desejar no VNC, apôs isso reiniciar sua máquina.
    2º - Passo: Digitar no executar "regedit" e acessar a seguinte chave de registro "HKEY_LOCAL_MACHINE\SOFTWARE\ORL".
    3º - Passo: Apôs ter acessado a chave clicar com lado esquerdo do mouse sob ela e expotrar, destinando o local e seu respectivo nome.
    4º - Passo: Digitar no executar "notepad" e digite a seguinte string "regedit /s \\172.16.100.1\netlogon\vnc1.reg" e salve como *.cmd,lembrando que alguns dados terão quer ser alterados, conforme sua rede e qual nome você salvou o arquivo *.reg.
    5º - Passo: Criar uma GPO Group Policy, ir em User Configuration ou Computer Configuration > Windows Settings > Scripts > Logon > Clicar em Logon > Show Files e colocar o arquivo .*cmd neste local ou apontar para outro destino.

    Obs.: Não esqueça de fazer as alterações necessarias no arquivo de acordo com sua rede e os locais aonde foram salvos.

     

    Atenciosamente
    Kelsen Lima

    quarta-feira, 8 de outubro de 2008 02:27