none
Script VBS para aplicar papel de parede e proteção de tela

    Question

  • Bom dia pessoALL!

    Tenho uma necessidade aqui na empresa aparentemente simples, porém está se tornando um enorme pesadelo! Quero deixar claro que não conheço nada sobre scripts...rsrs.

    O cenário é o seguinte: Domínio Windows Server 2003. Temos um script VBS que aplicava o papel de parede e o screen saver (Marquee/Letreiro Digital) nas estações de trabalho Windows XP SP2. Quando o usuário era administrador local, o script funcionava perfeitamente. Tiramos o grupo Domain Users do grupo local Administradores o script não funciona, pois ele escreve na chave HKEY_USERS\.DEFAULT\Control Panel\Desktop\. Segue o script abaixo:


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Configurações do Papel de Parede e Screen Saver         '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    strChaveWallpaper1 = "HKEY_CURRENT_USER\Control Panel\Desktop\"

    strTileWallpaperString = "TileWallpaper"
    strTileWallpaperValor = "1"

    strScreenSaveTimeOutString1 = "ScreenSaveTimeOut"
    strScreenSaveTimeOutValor1 = "600"

    strSCRNSAVEEXEString = "SCRNSAVE.EXE"
    strSCRNSAVEEXEValor = "C:\\windows\\system32\\ssmarque.scr"

    strWallpaperString = "Wallpaper"
    strWallpaperValor = "\\dominio.com\\netlogon\\BRA\\Wpapers\\wallpaper.bmp"

    strWallpaperStyleString = "WallpaperStyle"
    strWallpaperStyleValor = "0"

    strOriginalWallpaperString = "OriginalWallpaper"
    strOriginalWallpaperValor = "\\dominio.com\\netlogon\\BRA\\Wpapers\\wallpaper.bmp"

    strChaveWallpaper2 = "HKEY_USERS\.DEFAULT\Control Panel\" _
    & "Desktop\"

    strScreenSaveTimeOutString2 = "ScreenSaveTimeOut"
    strScreenSaveTimeOutValor2 = "120"


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Configurações do Screen Saver.MARQUEE                   '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    strChaveMarquee1 = "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\"

    strBackgroundColorString = "BackgroundColor"
    strBackgroundColorValor = "0 0 0"

    strCharSetString = "CharSet"
    strCharSetValor = "0"

    strFontString = "Font"
    strFontValor = "Verdana"

    strModeString = "Mode"
    strModeValor = "1"

    strSizeString = "Size"
    strSizeValor = "50"

    strSpeedString = "Speed"
    strSpeedValor = "8"

    strTextString = "Text"
    strTextValor = "Campanha Green Light – Ao sair desligue o monitor."

    strTextColorString = "TextColor"
    strTextColorValor = "255 255 255"

    strChaveMarquee2 = "HKEY_USERS\.DEFAULT\Control Panel\" _
    & "Desktop\"


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Criação dos Registros com as variáveis declaradas acima '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Set oShell = CreateObject("WScript.Shell")
    Set objShell = CreateObject("WScript.Shell")


    objShell.RegWrite strChaveWallpaper1 & strTileWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strTileWallpaperString, strTileWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strScreenSaveTimeOutString1, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strScreenSaveTimeOutString1, strScreenSaveTimeOutValor1, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strSCRNSAVEEXEString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strSCRNSAVEEXEString, strSCRNSAVEEXEValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strWallpaperString, strWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strWallpaperStyleString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strWallpaperStyleString, strWallpaperStyleValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strOriginalWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strOriginalWallpaperString, strOriginalWallpaperValor, "REG_SZ"

    '------------------------------------------------------------------------------------------------

    objShell.RegWrite strChaveWallpaper2 & strTileWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strTileWallpaperString, strTileWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper2 & strScreenSaveTimeOutString2, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strScreenSaveTimeOutString2, strScreenSaveTimeOutValor2, "REG_SZ"

    objShell.RegWrite strChaveWallpaper2 & strSCRNSAVEEXEString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strSCRNSAVEEXEString, strSCRNSAVEEXEValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper2 & strWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strWallpaperString, strWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper2 & strWallpaperStyleString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strWallpaperStyleString, strWallpaperStyleValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper2 & strOriginalWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper2 & strOriginalWallpaperString, strOriginalWallpaperValor, "REG_SZ"

    '------------------------------------------------------------------------------------------------

    objShell.RegWrite strChaveMarquee1 & strBackgroundColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strBackgroundColorString, strBackgroundColorValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strCharSetString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strCharSetString, strCharSetValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strFontString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strFontString, strFontValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strModeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strModeString, strModeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strSizeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strSizeString, strSizeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strSpeedString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strSpeedString, strSpeedValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strTextString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strTextString, strTextValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strTextColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strTextColorString, strTextColorString, "REG_SZ"

    '----------------------------------------------------------------------------------------------------

    objShell.RegWrite strChaveMarquee2 & strBackgroundColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strBackgroundColorString, strBackgroundColorValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strCharSetString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strCharSetString, strCharSetValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strFontString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strFontString, strFontValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strModeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strModeString, strModeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strSizeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strSizeString, strSizeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strSpeedString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strSpeedString, strSpeedValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strTextString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strTextString, strTextValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee2 & strTextColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee2 & strTextColorString, strTextColorString, "REG_SZ"


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Atualiza o Windows à respeito da mudança de configuração'
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

    Como o usuário não pode ser administrador local, depois de muito pesquisar e tentar entender alguma lógica, construí o script abaixo, que define as configurações do papel de parede e chama um arquivo .REG, que define as configurações do Screen Saver (Marquee):

    ' ESSA PARTE DO SCRIPT DEFINE AS CONFIGURAÇÕES DO PAPEL DE PAREDE

    HKEY_CURRENT_USER = &H80000001
    strComputer = "."
    Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "Control Panel\Desktop"
    objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
    ValueName = "ScreenSaveActive"
    strValue = "1"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "TileWallpaper"
    strValue = "1"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "ScreenSaveTimeout"
    strValue = "300"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "SCRNSAVE.EXE"
    strValue = "C:\WINDOWS\System32\ssmarquee.scr"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "Wallpaper"
    strValue = "\\dominio.com\netlogon\BRA\Wpappers\wallpaper.bmp"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "WallpaperStyle"
    strValue = "0"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
    ValueName = "OriginalWallpaper"
    strValue = "\\dominio.com\netlogon\BRA\Wpappers\wallpaper.bmp"
    objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Configurações do Screen Saver.MARQUEE                   '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Set wShell = CreateObject("WScript.Shell")
    wShell.run "cmd /c ""regedit /s \\dominio.com\netlogon\CONFIG_MARQUEE.reg""",0

     

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Criação dos Registros com as variáveis declaradas acima '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Set oShell = CreateObject("WScript.Shell")
    Set objShell = CreateObject("WScript.Shell")
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

    O conteúdo do arquivo .REG é esse:

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee]
    "BackgroundColor"="0 0 0"
    "CharSet"="0"
    "Font"="Verdana"
    "Mode"="1"
    "Size"="50"
    "Speed"="8"
    "Text"="Campanha Green Light – Ao sair desligue o monitor."
    "TextColor"="255 255 255"

    [HKEY_USERS\.DEFAULT\Control Panel\Screen Saver.Marquee]
    "BackgroundColor"="0 0 0"
    "CharSet"="0"
    "Font"="Verdana"
    "Mode"="1"
    "Size"="50"
    "Speed"="8"
    "Text"="Campanha Green Light – Ao sair desligue o monitor."
    "TextColor"="255 255 255"

    Verifiquei o registro do Windows e os valores são aplicados, porém o Papel de parede não funciona e o Screen Saver não é acionado.

    Alguém possui uma luz? Meus cabelos já estão brancos...rsrs.

    Desde já agradeço pela ajuda!!!!


    Bruno Santos MCP, MCDST, MCSA, MCTS, MCITP O difícil é aprender a ler, o restante está escrito.

    Tuesday, December 04, 2012 1:03 PM

Answers

  • Boa tarde pessoALL!

    Depois de muito quebrar a cabeça, com muito custo consegui encontrar a solução.

    Fazendo uma análise mais aprofundada dos meus scripts notei que tinham variáveis/strings declaradas incorretamente, bem como uma letra a mais em um lugar que não devia.

    Para quem precisar, segue abaixo o scritp utilizado por mim para aplicar o papel de parede e definir o texto do Letreiro Digital como Screen Saver:

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Configurações do Papel de Parede e Screen Saver         '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    strChaveWallpaper1 = "HKEY_CURRENT_USER\Control Panel\Desktop\"

    strTileWallpaperString = "TileWallpaper"
    strTileWallpaperValor = "1"

    strScreenSaveTimeOutString1 = "ScreenSaveTimeOut"
    strScreenSaveTimeOutValor1 = "300"

    strSCRNSAVEEXEString = "SCRNSAVE.EXE"
    strSCRNSAVEEXEValor = "C:\windows\system32\ssmarque.scr"

    strWallpaperString = "Wallpaper"
    strWallpaperValor = "\\dominio.com\netlogon\BRA\Wpapers\wallpaper.bmp"

    strWallpaperStyleString = "WallpaperStyle"
    strWallpaperStyleValor = "0"

    strOriginalWallpaperString = "OriginalWallpaper"
    strOriginalWallpaperValor = "\\dominio.com\netlogon\BRA\Wpapers\wallpaper.bmp"

     

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Configurações do Screen Saver.MARQUEE                   '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    strChaveMarquee1 = "HKEY_CURRENT_USER\Control Panel\Screen Saver.Marquee\"

    strBackgroundColorString = "BackgroundColor"
    strBackgroundColorValor = "0 0 0"

    strCharSetString = "CharSet"
    strCharSetValor = "0"

    strFontString = "Font"
    strFontValor = "Verdana"

    strModeString = "Mode"
    strModeValor = "1"

    strSizeString = "Size"
    strSizeValor = "50"

    strSpeedString = "Speed"
    strSpeedValor = "8"

    strTextString = "Text"
    strTextValor = "Campanha Green Light – Ao sair desligue o monitor."

    strTextColorString = "TextColor"
    strTextColorValor = "0 255 0"

    strAttributesString = "Attributes"
    strAttributesValor = "00000"

     

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Criação dos Registros com as variáveis declaradas acima '
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Set oShell = CreateObject("WScript.Shell")
    Set objShell = CreateObject("WScript.Shell")


    objShell.RegWrite strChaveWallpaper1 & strTileWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strTileWallpaperString, strTileWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strScreenSaveTimeOutString1, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strScreenSaveTimeOutString1, strScreenSaveTimeOutValor1, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strSCRNSAVEEXEString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strSCRNSAVEEXEString, strSCRNSAVEEXEValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strWallpaperString, strWallpaperValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strWallpaperStyleString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strWallpaperStyleString, strWallpaperStyleValor, "REG_SZ"

    objShell.RegWrite strChaveWallpaper1 & strOriginalWallpaperString, 1, "REG_SZ"
    objShell.RegWrite strChaveWallpaper1 & strOriginalWallpaperString, strOriginalWallpaperValor, "REG_SZ"

    '------------------------------------------------------------------------------------------------


    objShell.RegWrite strChaveMarquee1 & strBackgroundColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strBackgroundColorString, strBackgroundColorValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strCharSetString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strCharSetString, strCharSetValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strFontString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strFontString, strFontValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strModeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strModeString, strModeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strSizeString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strSizeString, strSizeValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strSpeedString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strSpeedString, strSpeedValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strTextString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strTextString, strTextValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strTextColorString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strTextColorString, strTextColorValor, "REG_SZ"

    objShell.RegWrite strChaveMarquee1 & strAttributesString, 1, "REG_SZ"
    objShell.RegWrite strChaveMarquee1 & strAttributesString, strAttributesValor, "REG_SZ"


    '----------------------------------------------------------------------------------------------------


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                                                         '
    ' Atualiza o Windows à respeito da mudança de configuração'
    '                                                         '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True


    Bruno Santos MCP, MCDST, MCSA, MCTS, MCITP O difícil é aprender a ler, o restante está escrito.

    Tuesday, December 04, 2012 5:24 PM