View Full Version : VB Script Help
Hi all, im new to vbscript and im trying to make a script that would allow me run a .exe file to update the firmware on all my labs pc's, i need to be on the server and run this vbscript and the file need to install this update on all the ip address that i tell it to and restart the computer when done with all the answers to be yes when poped up. Thank You
that's quite a list. I don't think you're going to get very far with VBSCRIPT in this area. You are asking a script to communicate with a BASIC / LOWLEVEL environment. I would imagine you'd need something more powerful than VBS to do what you ask.
Well i know it can be done cause microsft had posted a vbs to do a security hotfix this way. but i dont know if i can use the same vbs and change some of the file names. here is the script.
' 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()
'Clean up, remove drive mapping (check this time, because it may not have been mapped).
if ofs.folderexists("z:\") then
onet.removenetworkdrive "z:", true
end if
wscript.echo vbCrLf & "Patching complete. Exiting."
function detectOSPatch(osvcRemote)
set oOSInfo = osvcRemote.InstancesOf("Win32_OperatingSystem")
'Only one instance is ever returned (the currently active OS), even though the following is a foreach.
for each objOperatingSystem in oOSInfo
if (objOperatingSystem.OSType <> 18) then
' Make sure that this computer is Windows NT-based.
wscript.echo ip & " is not a Windows XP, Windows 2000, or Windows 2003 Server computer."
else
if (objOperatingSystem.Version = "5.0.2195") then
' Windows 2000 SP2, SP3, SP4.
if (objOperatingSystem.ServicePackMajorVersion = 2) or (objOperatingSystem.ServicePackMajorVersion = 3) or (objOperatingSystem.ServicePackMajorVersion = 4) then
systemType = exeW2k
end if
elseif (objOperatingSystem.Version = "5.1.2600") then
' Windows XP RTM, SP1.
if (objOperatingSystem.ServicePackMajorVersion = 0) or (objOperatingSystem.ServicePackMajorVersion = 1) then
systemType = exeWinXP
end if
elseif (objOperatingSystem.Version = "5.2.3790") then
' Windows Server 2003 RTM
if (objOperatingSystem.ServicePackMajorVersion = 0) then
systemType = exeW2k3
end if
end if
if (systemType = "") then
'This was a Windows NT-based computer, but not with a valid service pack.
wscript.echo "Could not patch " & ip & " - unhandled OS version: " & objOperatingSystem.Caption & " SP" & objOperatingSystem.ServicePackMajorVersion & "("& objOperatingSystem.Version & ")"
end if
end if
next
detectOSPatch = systemType
end function
That script wreaks of having the operating system loaded. This is not loading/installing anything at the bios level.
That script is calling patches from a remote / mapped drive /unc and installing it on the target machine while the OS is loaded..
Yes the .exe file that i need to run is windows based, it does the flash and restarts. and yes i do need to be on one computer and run the vbs and have it copy this file to multiple ip, and run it on the workstation and restart it. i did some changes to this vbs that i didnt post yet, and im hoping it would work.
so your bios update runs in the windows environent?
It's just a flash update from Dell for the DVD drive to read multisession cd's. And yes it's a 32 bit exe that runs in windows and flashes the system for the dvd drive.
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.