quinta-feira, 28 de julho de 2011

Exemplo de Script Logon em VbScript para Active directory

'Impedindo exibição de error para o usuário
on error resume next

'SINCRONIZA HORARIO ESTAÇÃO x SERVIDOR
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "NET TIME \\pdcsrv01 /SET /Y", 0, True

'LIMPA UNIDADES DE REDE
Set WSHNetwork = WScript.CreateObject("WScript.Network")
on error resume next
WSHNetwork.RemoveNetworkDrive "G:", True, True
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "I:", True, True
WSHNetwork.RemoveNetworkDrive "J:", True, True
WSHNetwork.RemoveNetworkDrive "K:", True, True
WSHNetwork.RemoveNetworkDrive "L:", True, True
WSHNetwork.RemoveNetworkDrive "M:", True, True
WSHNetwork.RemoveNetworkDrive "N:", True, True
WSHNetwork.RemoveNetworkDrive "O:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "Q:", True, True
WSHNetwork.RemoveNetworkDrive "R:", True, True
WSHNetwork.RemoveNetworkDrive "S:", True, True
WSHNetwork.RemoveNetworkDrive "T:", True, True
WSHNetwork.RemoveNetworkDrive "U:", True, True
WSHNetwork.RemoveNetworkDrive "V:", True, True
WSHNetwork.RemoveNetworkDrive "X:", True, True
WSHNetwork.RemoveNetworkDrive "Y:", True, True
WSHNetwork.RemoveNetworkDrive "w:", True, True
WSHNetwork.RemoveNetworkDrive "Z:", True, True
WScript.DisconnectObject WSHNetwork
'FIM DO LIMPA UNIDADES

Dim strComputername, strDomain, strUser, strIp, strLoc, wshshell

Set wshShell = CreateObject("WScript.Shell")
strComputername = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strDomain = wshShell.ExpandEnvironmentStrings("%userdomain%")
strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")

'Wscript.Echo strUser


'CONECTA UNIDADES DE REDE
Set objNet = CreateObject("Wscript.Network")

'MAPEIA DIRETORIO PESSOAL
objNet.MapNetworkDrive "U:","\\stgsrv01\home_"&strUser & "$"

'MAPEIA DIRETORIO DO LINX
objNet.MapNetworkDrive "L:","\\appsrv04\l"

'MAPEIA DIRETORIO DO MODARIS E DIAMINO
objNet.MapNetworkDrive "Z:","\\stgsrv01\lectra"

'MAPEIA DIRETORIO DO INVESTRONICA
objNet.MapNetworkDrive "X:","\\sqlsrv02\x"

'MOSTRA O CAMINHO DO DIRETORIO PESSOAL
' WScript.Echo "U:","\\stgsrv01\home_"&strUser & "$"

'C:\Documents and Settings\ti01\Dados de aplicativos\Microsoft\Internet Explorer\Quick Launch
'C:\Users\marcelo.souza\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

'CRIA ICONE DO LINX NO DESKTOP
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Visual Linx 8.lnk")
oUrlLink.TargetPath = "L:\Linx_sql\LINX\VisualLinx.exe"
oUrlLink.IconLocation = "L:\Linx_sql\LINX\VisualLinx.exe"
oUrlLink.Save

'CRIA ATALHO DO DIRETORIO PESSOAL NO DESKTOP
strAppPath = "U:\"
Set wshShell = CreateObject("WScript.Shell")
objDesktop = wshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(objDesktop & "\Diretorio Pessoal.lnk")
oShellLink.TargetPath = strAppPath
oShellLink.WindowStyle = "1"
oShellLink.Description = "Diretorio Pessoal"
oShellLink.Save

'COPIA ICONE DO MODARIS NO DESKTOP
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Wshs = WScript.CreateObject("WScript.Shell")
Const OverwriteExisting = true
usrProfile = Wshs.ExpandEnvironmentStrings("%UserProfile%")
objFSO.CopyFile "\\pdcsrv01\netlogon\Modaris Diamino Server.rdp" , usrProfile & "\Desktop\", OverwriteExisting

'ENVIA O COMANDO PARA APERTAR A TECLA F5 PARA ATUALIZAR OS ICONES NO DESKTOP
WshShell.SendKeys "{F5}"


'WScript.Quit