................................................................................................
'Autor: ||m0rPh3vZ||
'Script: Instalacao remota de software :
"UltraVnc" "1.0.9.6.1"
'Versao: 02
'Tipo: Automatizado
'Criacao: 2011.08.30
'Modificacao: 2012.03.03
'Modificado: Luciano
'Descricao: Instala o programa no computador remoto
'Script: Instalacao remota de software :
"UltraVnc" "1.0.9.6.1"
'Versao: 02
'Tipo: Automatizado
'Criacao: 2011.08.30
'Modificacao: 2012.03.03
'Modificado: Luciano
'Descricao: Instala o programa no computador remoto
'...............................................................................................
'Variaveis do programa
sApp = "UltraVnc"
sFolder = "UltraVNC"
sProcGetRun = ""
sAppVer = "1.0.9.6.1"
sSource = "dell.hmsm"
sFolder = "UltraVNC"
sProcGetRun = ""
sAppVer = "1.0.9.6.1"
sSource = "dell.hmsm"
sUncDriver = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\driver"
sSwitchsExeDriver = ""
sUnc = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\uvnc.exe"
sSwitchsExe = "/LOADINF=c:\remote\10961.inf /VERYSILENT"
sPathuvncini = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\ultravnc.ini"
sUncinf = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\10961.inf"
sSwitchsExeDriver = ""
sUnc = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\uvnc.exe"
sSwitchsExe = "/LOADINF=c:\remote\10961.inf /VERYSILENT"
sPathuvncini = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\ultravnc.ini"
sUncinf = "\\" & sSource & "\NETLOGON\desenvolvimento\vbs\projetos\uvnc\1.0.9.6.1\10961.inf"
'================================== + =====================================
'Classes
Set objNetwork = WScript.CreateObject( "WScript.Network" )
strComputer = objNetwork.ComputerName
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Set WshSysEnv = WshShell.Environment( "PROCESS" )
sProgramFiles = WshSysEnv( "PROGRAMFILES" )
strComputer = objNetwork.ComputerName
Set WshShell = WScript.CreateObject( "WScript.Shell" )
Set WshSysEnv = WshShell.Environment( "PROCESS" )
sProgramFiles = WshSysEnv( "PROGRAMFILES" )
'Variaveis de entrada de dadosstrInputComputers = strComputer
'Variaveis fixas para iniciar o procedimento
strInstalado = AppCheckInstalled( sApp, sAppVer )
strDriveCRemote = "C$\"
strRemoteFile = "\\"
strDriveC = "C:\"
strFolder = "remote"
sPathExeFull = sUnc
strDriveCRemote = "C$\"
strRemoteFile = "\\"
strDriveC = "C:\"
strFolder = "remote"
sPathExeFull = sUnc
'ObjetosstrInstalado = AppCheckInstalled( sApp, sAppVer )
sPathExeFull = sUnc
sPathExe2 = ExeFind( sPathExeFull )
'Verifica se o software ja esta instalado caso contrario instala.
If strInstalado = TRUE Then
Else 'Checa se a pasta existe caso contrario cria sFolderUltraVNC = FolderCheck( sProgramFiles, sFolder )
If sFolderUltraVNC = FALSE Then
FolderCreate strRemoteFile & strComputer & "\" & strDriveCRemote & "Arquivos de programas" & "\", sFolder
End If
'ultravnc.ini copia para o computador remoto na pasta do UltraVnc
FileCopy sPathuvncini, strRemoteFile & strComputer & "\" & strDriveCRemote & "Arquivos de programas" & "\" & sFolder & "\"
sRemoteFolder = FolderCheck( "c:", strFolder )
sRemoteFolder = FolderCheck( "c:", strFolder )
If sRemoteFolder = FALSE Then
FolderCreate strRemoteFile & strComputer & "\" & strDriveCRemote, "remote"
End If
FolderCreate strRemoteFile & strComputer & "\" & strDriveCRemote, "remote"
End If
'Driver hook2 para o computador local
FolderCopy sUncDriver, strRemoteFile & strComputer & "\" & strDriveCRemote & strFolder & "\"
FolderCopy sUncDriver, strRemoteFile & strComputer & "\" & strDriveCRemote & strFolder & "\"
'UltraVnc copia do programa para o computador remoto e sua execucao
CmdRunCopy sUnc, sSwitchsExe
'Monitora o processo, quando terminar o script continua
ProcessGetRunning( sPathExe2 ) '20s
'~ 'Hook2 instalacao '~ CmdRun strDriveC & strFolder & "\" & "driver" & "\" & "install.bat" & " ", sSwitchsExeDriver
End If
End If
'========================== Funcoes e Subrotinas ==========================
'Checa se o programa esta instalad
Function AppCheckInstalled( sApp, sAppVer )
Const hklm = &H80000002
strPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
'Inicio do tratamento de erros
On Error Resume Next
Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv" )
On Error Resume Next
Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv" )
'Tratamento de erros If Err.Number <> 0 Then
WScript.Echo Err.Description & vbCr & vbCr & "Computador: " & UpperCase( strComputer )
Err.Clear
Wscript.Quit
End If
WScript.Echo Err.Description & vbCr & vbCr & "Computador: " & UpperCase( strComputer )
Err.Clear
Wscript.Quit
End If
EnuReg = objReg.EnumKey( hklm, strPath, arSubKeys )
For Each sKey In arSubKeys
EnuReg = objReg.GetStringValue( hklm, strPath & sKey, "DisplayName", sValue )
EnuReg2 = objReg.GetStringValue (hklm, strPath & sKey, "DisplayVersion", sValue2 )
For Each sKey In arSubKeys
EnuReg = objReg.GetStringValue( hklm, strPath & sKey, "DisplayName", sValue )
EnuReg2 = objReg.GetStringValue (hklm, strPath & sKey, "DisplayVersion", sValue2 )
If sValue = sApp Then
If sValue2 = sAppVer Then
AppCheckInstalled = TRUE
End If
End If
Next
End Function
If sValue2 = sAppVer Then
AppCheckInstalled = TRUE
End If
End If
Next
End Function
'Rotina para Executar a instalacao no computadorSub CmdRunCopy( cUnc, cSwitchsExe )
cDriveCRemote = "C$\"
c2Slashinv = "\\"
cDriveC = "C:\"
cFolder = "remote" cUnc2 = cUnc
oExe = ExeFind( cUnc )
Set objWMIService = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process" )
Set objWMIService2 = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
Set colFolders = objWMIService2.ExecQuery( "Select * From Win32_Directory Where Name = 'C:\\" & cFolder & "'")
Set objWMIService2 = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
Set colFolders = objWMIService2.ExecQuery( "Select * From Win32_Directory Where Name = 'C:\\" & cFolder & "'")
If colFolders.Count < 1 Then
FolderCreate c2Slashinv & strComputer & "\" & cDriveCRemote, cFolder
End If
FolderCreate c2Slashinv & strComputer & "\" & cDriveCRemote, cFolder
End If
FileCopy cUnc2, c2Slashinv & strComputer & "\" & cDriveCRemote & cFolder & "\"
FileCopy sUncinf, c2Slashinv & strComputer & "\" & cDriveCRemote & cFolder & "\"
FileCopy sUncinf, c2Slashinv & strComputer & "\" & cDriveCRemote & cFolder & "\"
Exec = objWMIService.Create( cDriveC & cFolder & "\" & oExe & " " & cSwitchsExe, null, null, intProcessID )
End Sub
End Sub
'Rotina para Executar a acao no computador
Sub CmdRun( eUnc, eSwitchsExe )
Set objWMIService = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2:Win32_Process" )
Exec = objWMIService.Create( eUnc & eSwitchsExe, null, null, intProcessID )
End Sub
'Copia arquivo para um derterminado local
Sub FileCopy( sFile, sLocal )
Set objFSO = CreateObject( "Scripting.FileSystemObject" ) objFSO.CopyFile sFile, sLocal, True
End Sub
'Verifica o processo em andamento
Sub ProcessGetRunning( sProcessName )
ctrue = 0 'Quantindade de vezes que entrou no loop
ctimer = 30 'Tempo de execucao do loop
sProcess = ProcessGetName( sProcessName )
'Timer para que o .exe entre na lista de processos
For i = 0 to 3
If sProcess = FALSE Then
Wscript.Sleep 2800
Else
i = 3
End If
Next
For i = 0 to 3
If sProcess = FALSE Then
Wscript.Sleep 2800
Else
i = 3
End If
Next
'Enquanto o sProcess for False ficara dentro do relogio interno
Do While sProcess = TRUE
if ctimer = 0 Then
sProcess = FALSE
Else
sProcess = ProcessGetName( sProcessName )
ctrue = ctrue +1
ctimer = ctimer -1
Wscript.Sleep 5000 'Valor setado para 5s
End If
Loop
End Sub
Do While sProcess = TRUE
if ctimer = 0 Then
sProcess = FALSE
Else
sProcess = ProcessGetName( sProcessName )
ctrue = ctrue +1
ctimer = ctimer -1
Wscript.Sleep 5000 'Valor setado para 5s
End If
Loop
End Sub
'Checa o nome do processo
Function ProcessGetName( sProcessName )
Set objWMIService = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
Set colProcess = objWMIService.ExecQuery ( "Select * from Win32_Process" )
For Each objProcess in colProcess
If objProcess.Name = sProcessName Then
ProcessGetName = TRUE
Else
End If
Next
End Function
'Transforma a string de entrada em maiscula
Function UpperCase( string )
strUpperCase = UCase( string )
UpperCase = strUpperCase
End Function
'Econtra o .exe no caminho informado
Function ExeFind( sPathExe )
'Tratamento da variavel
sFullPathExe = sPathExe
sPathExe = sPathExe & "\"
sPathExe = "\" & sPathExe
strTamSoftwareCaminho = Len( sPathExe )
Do While strTamSoftwareCaminho > 1
strBarraInvertidaInicio = InStr( 1, sPathExe, "\" )
strBarraInvertidaInicio = strBarraInvertidaInicio +1
strBarraInvertidaFinal = InStr( strBarraInvertidaInicio, sPathExe, "\" )
strBarraInvertidaFinal = strBarraInvertidaFinal -2
strCutInputSoftwareCaminho = Mid( sPathExe, strBarraInvertidaInicio, strBarraInvertidaFinal )
sExe = strCutInputSoftwareCaminho
strCut = strTamSoftwareCaminho -1 -strBarraInvertidaFinal
sPathExe = Right( sPathExe, strCut )
strTamSoftwareCaminho = strCut
ExeFind = sExe
Loop
End Function
strBarraInvertidaInicio = InStr( 1, sPathExe, "\" )
strBarraInvertidaInicio = strBarraInvertidaInicio +1
strBarraInvertidaFinal = InStr( strBarraInvertidaInicio, sPathExe, "\" )
strBarraInvertidaFinal = strBarraInvertidaFinal -2
strCutInputSoftwareCaminho = Mid( sPathExe, strBarraInvertidaInicio, strBarraInvertidaFinal )
sExe = strCutInputSoftwareCaminho
strCut = strTamSoftwareCaminho -1 -strBarraInvertidaFinal
sPathExe = Right( sPathExe, strCut )
strTamSoftwareCaminho = strCut
ExeFind = sExe
Loop
End Function
'Copia pastas para o local informado
Sub FolderCopy( strFolder, strLocal )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
objFSO.CopyFolder strFolder, strLocal, True
End Sub
'Checa se a pasta existe
Function FolderCheck( sPath, sFolder )
Set objWMIService = GetObject( "winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
sPath = sPath & "\"
sPath = Replace( sPath, "\", "\\" )
Set colsFolders = objWMIService.ExecQuery ( "Select * From Win32_Directory Where Name = '" & sPath & sFolder & "'" )
If colsFolders.Count < 1 Then
FolderCheck = FALSE
Else
FolderCheck = TRUE
End If
sPath = Replace( sPath, "\\", "\" )
End Function
'Cria pasta no local informado
Sub FolderCreate( strLocal, strFolder )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
objFSO.CreateFolder strLocal & strFolder
End Sub
'================================== + =====================================
Parabéns pela iniciativa.. ainda não testei.. assim que o fizer volto para informar o resultado. obrigado.
ResponderExcluir