Login | |
|
 |
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.
|
|
| |
|
|
|
 |
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()
|
|
| |
|
|
|
|
|