All Forums >> [Scripting] >> Post a VBScript >> Install Software - RUNAS Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
On Error Resume Next Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject") ' Verifica de existe o arquivo em uma área compartilhada If objFSO.FileExists("\\Servidor\Pasta\Arquivo.exe") Then ' Copia o arquivo para máquina do usuário objFSO.CopyFile "\\Servidor\Pasta\Arquivo.exe" , "C:\Temp\Arquivo.exe", OverwriteExisting ' Executa a função para instalar o arquivo Instala Else Wscript.Echo "Arquivo não está disponivel para instalação" End If Function Instala Set WshShell = CreateObject("Wscript.Shell") Set WshEnv = WshShell.Environment("PRocess") WshShell.Run "runas.exe /user:" & "dominio\usuario" & " " & Chr(34) & "C:\TEMP\Arquivo.exe" & Chr(34) Wscript.Sleep 800 WshShell.AppActivate WshEnv("SystemRoot") & "\system32\runas.exe" Wscript.Sleep 200 WshShell.SendKeys "PASSWORD" & "~" Wscript.Sleep 5000 Set WshShell = Nothing Set WshEn = Nothing End Function
ORIGINAL: Gildo_BRAZIL ----------------------------------------------------------------------------------------------------------------------------- On Error Resume Next Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject") ' Verifica de existe o arquivo em uma área compartilhada If objFSO.FileExists("\\Servidor\Pasta\Arquivo.exe") Then ' Copia o arquivo para máquina do usuário objFSO.CopyFile "\\Servidor\Pasta\Arquivo.exe" , "C:\Temp\Arquivo.exe", OverwriteExisting ' Executa a função para instalar o arquivo Instala Else Wscript.Echo "Arquivo não está disponivel para instalação" End If Function Instala Set WshShell = CreateObject("Wscript.Shell") Set WshEnv = WshShell.Environment("PRocess") WshShell.Run "runas.exe /user:" & "dominio\usuario" & " " & Chr(34) & "C:\TEMP\Arquivo.exe" & Chr(34) Wscript.Sleep 800 WshShell.AppActivate WshEnv("SystemRoot") & "\system32\runas.exe" Wscript.Sleep 200 WshShell.SendKeys "PASSWORD" & "~" Wscript.Sleep 5000 Set WshShell = Nothing Set WshEn = Nothing End Function
First of all, Welcome! Second, I took a look at your script posting and spent some time with babylon.com translating it into English. Hopefully, I did ok as some of the words I ended up having to guess at.
Third, some comments on the script:
You use a function, and even thought it works, since a function should return some kind of value, what you should be using - strictly speaking - would be a Sub. I would suggest removing the On Error Resume Next from the script. This should only be used when required for error trapping, rather than all the time. I'll post my 'translated' version of the code here for the other english-only speakers.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury