Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Help deploying exe files using VBScript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1430
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help deploying exe files using VBScript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Help deploying exe files using VBScript - 10/6/2004 2:42:57 AM   
  robiee4u

 

Posts: 36
Score: 0
Joined: 10/6/2004
From:
Status: offline
Hi all,
I am novice in VBScripting. I am trying to write a VBScript code that will deploy an exe file over the network. I am using the Runas command for admin rights that needs to install softwares in client machines. Here is the code.

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:firstname.surname""C:\mdac.exe"""
WshShell.appActivate "Runas"
wscript.sleep 2000
WshShell.Sendkeys "password"
WshShell.Sendkeys "y{ENTER}"
Msgbox "Executed"

Can anyone tell me what is wrong with this code,please .
It does not show any error when I execute it but it doesn't start the installation either!

Thanks
 
 
Post #: 1
 
 Re: Help deploying exe files using VBScript - 10/6/2004 11:53:44 PM   
  mbouchard


Posts: 1856
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
While I am not positive, I do not think that you can use sendkeys to get this working. Check out Psexec.exe from the PStools pack on www.sysinternals.com this allows you to run an exe with elevated rights.

(in reply to robiee4u)
 
 
Post #: 2
 
 Re: Help deploying exe files using VBScript - 10/27/2004 8:27:36 AM   
  bobbob

 

Posts: 5
Score: 0
Joined: 10/27/2004
From:
Status: offline
You will need to copy the exe to the local workstation unless it's on a mapped network drive or on a share. Then connect to the machine's wmi. then executed the .exe. the problem lies in no way to tell if the .exe started!


Here's some code from microsoft that does something similar!

It installs patches to a remote machine the code is very sloppy because they use alot of static variables and other poor programming!

It maybe a good start

[code]
' Patchinstall.vbs
' Patch installation script for MS03-026 and MS03-039
' (c) Microsoft 2003
' v1.03 cl

on error resume next

const XP_Patch = "Patch_XP.exe"
const W2k_Patch = "Patch_W2k.exe"
const W2k3_Patch = "Patch_W2k3.exe"

If right(ucase(wscript.FullName),11)="WSCRIPT.EXE" then
wscript.echo "ERROR: You must run this script using cscript, for example 'cscript " & wscript.scriptname & "'."
wscript.quit 0
end if

' USAGE
if wscript.arguments.count <> 2 then
wscript.echo "Usage: cscript " & wscript.scriptname & " <IpFile.txt> <LocalPathToPatches>" & vbCrLf & vbCrLf & _
" <LocalPathToPatches> must be a full path of a folder that contains all of these files:" & vbCrLf & _
" " & XP_Patch & vbCrLf & _
" " & W2k_Patch & vbCrLf & _
" " & W2k3_Patch
wscript.quit
end if

ipFile = wscript.arguments(0)
localPathToPatches = wscript.arguments(1)

set onet = createobject("wscript.network")
set ofs = createobject("scripting.filesystemobject")

' Verify that ipfile is accessible.
set oipFile = ofs.opentextfile(ipFile, 1, false)
if (Err.Number <> 0) then
wscript.echo "Cannot open " & ipFile
wscript.quit
end if

' Make sure to end with a \ character.
if right(localPathToPatches, 1) <> "\" then
localPathToPatches = localPathToPatches & "\"
end if

'Note that cim_datafile does not support UNC paths
'so everything must be handled through mapped drives.
if left(localPathToPatches, 2) = "\\" then
wscript.echo "<pathToExecutable> cannot be a UNC path, please map a drive locally"
wscript.quit
end if

exeWinXP = ofs.getfile(localPathToPatches + XP_Patch).name
exeW2k = ofs.getfile(localPathToPatches + W2k_Patch).name
exeW2k3 = ofs.getfile(localPathToPatches + W2k3_Patch).name

' Verify that the patches are accessible.
if ((len(exeWinXP) = 0) OR (len(exeW2k) = 0) OR (len(exeW2k3) = 0)) then
wscript.echo "Cannot find patch files."
wscript.echo "Please verify that the <LocalPathToPatches> folder contains all of these files:" & vbCrLf & _
" " & XP_Patch & vbCrLf & _
" " & W2k_Patch & vbCrLf & _
" " & W2k3_Patch
wscript.quit
end if


set osvcLocal = getobject("winmgmts:root\cimv2")

'The error-handling code is below the function that may throw one - execute it.
on error resume next

while not oipFile.atEndOfStream
ip = oipFile.ReadLine()
wscript.echo vbCrLf & "Connecting to " & ip & "..."

Err.Clear
set osvcRemote = GetObject("winmgmts:\\" & ip & "\root\cimv2")

if (Err.Number <> 0) then
wscript.echo "Failed to connect to " & ip & "."
else

exeCorrectPatch = detectOSPatch(osvcRemote)
if (exeCorrectPatch <> "") then
' Lay the bits on the remote computer.
wscript.echo "Installing patch " & exeCorrectPatch & "..."

onet.mapnetworkdrive "z:", "\\" & ip & "\C$"
set osourceFile = osvcLocal.get("cim_datafile=""" & replace(localPathToPatches, "\", "\\") & exeCorrectPatch & """")
ret = osourceFile.Copy("z:\\Patchinst.exe")

if (ret <> 0 and ret <> 10) then
' Failure detected and failure was not "file already exists."
wscript.echo "Failed copy to " & ip & " - error: " & ret
else
set oprocess = osvcRemote.Get("win32_process")

' Start the installation without user interaction, and force a restart after completion.
ret = oprocess.create("c:\\Patchinst.exe -q -f")
if (ret <> 0) then
wscript.echo "Failed to start process on " & ip & ": " & ret
else
' Get a reference to the file that was copied.
set odestFile = osvcLocal.get("cim_datafile=""z:\\Patchinst.exe""")

' Wait for the installation to complete.
for waitTime = 0 to 120 ' Lay and wait--up to two minutes for the installation to complete.
wscript.Sleep 1000 ' Sleep one second.
' Delete temporary file as soon as possible after it is freed.
if (odestFile.Delete() = 0) then
exit for
end if
next ' Otherwise, loop again and keep waiting...

wscript.echo "Installation successful."

end if 'Create process succeeded.
end if 'Copy succeeded.

onet.removenetworkdrive "z:", true
end if ' The script knows which patch to install.
end if ' Do the next IP address, then the next IP address...
wend

oipFile.close()

(in reply to robiee4u)
 
 
Post #: 3
 
 Re: Help deploying exe files using VBScript - 11/3/2004 6:08:53 AM   
  mjoni

 

Posts: 3
Score: 0
Joined: 11/3/2004
From:
Status: offline
I fought this same problem and ended up finding the Admin Script Editor. It is a very good editor worth checking out and it lets you compile your script into exe files that you can have run with a username and password you say. This way you don't have to have your password where anyone can see it. If I recall, this is the only feature in the demo you cannot use [V] but they have a flash movie somewhere on the site: www.adminscripteditor.com

(in reply to robiee4u)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help deploying exe files using VBScript Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts