Need a VBScript to copy files to different versions of JRE folders
Hi,
I need a VBScript that can copy a few files to different versions of JRE installed in the machine.. The files need to be copied to each and every version of jre and j2re folders present under C:\Program Files\Java\ in the machine.
Regards,
manju
I need a VBScript that can copy a few files to different versions of JRE installed in the machine.. The files need to be copied to each and every version of jre and j2re folders present under C:\Program Files\Java\ in the machine.
Regards,
manju
0 Comments
[ + ] Show comments
Answers (5)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
Done properly, this a distinctly non-trivial task, in that the script needs to enumerate the 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment' registry branch, grabbing all the version numbers. As you may know, the script interface to the registry which most people use, the Shell object, has no native method to enumerate keys. Then the script needs to check the existence of that version's folder and so on. Consequently, I'd doubt very much if you'd find anyone willing to undertake the job for free.
Posted by:
jinxngoblins
15 years ago
Set WS=CreateObject("WScript.Shell")
Set FS=CreateObject("Scripting.FileSystemObject")
Posted by:
Jsaylor
15 years ago
Posted by:
anonymous_9363
15 years ago
OK, so, remember I said "Done properly ..."?
This is not a personal attack but serves as a pointer to why I say script is easy but good script is hard.
'// \|/
Set WS=CreateObject("WScript.Shell")
Set FS=CreateObject("Scripting.FileSystemObject")
/|\ There's no check to see if objects got created. Always assume the worst will happen.
' \|/
RootPth = Session.Property("SOURCEDIR")
PR = WS.ExpandEnvironmentStrings("%PROGRAMFILES%")
' /|\ Assumes script is running in an MSI as a Custom Action.
' /|\ Meaningless variable naming
' \|/
Root1 = RootPth &"TheFiles"
Pth2 = PR &"Java\Java5"
Pth3 = PR &"Java\Java5.2"
Pth4 = PR &"Java\Java5.3"
' /|\ Hard-code paths
' /|\ No check to see if the source exists
' \|/
FS.CopyFolder Root1, Pth2, True
FS.CopyFolder Root1, Pth3, True
' /|\ There's no check to see if target's "root" exists.
' /|\ There's no check to see if the copy succeeded.
This is not a personal attack but serves as a pointer to why I say script is easy but good script is hard.
'// \|/
Set WS=CreateObject("WScript.Shell")
Set FS=CreateObject("Scripting.FileSystemObject")
/|\ There's no check to see if objects got created. Always assume the worst will happen.
' \|/
RootPth = Session.Property("SOURCEDIR")
PR = WS.ExpandEnvironmentStrings("%PROGRAMFILES%")
' /|\ Assumes script is running in an MSI as a Custom Action.
' /|\ Meaningless variable naming
' \|/
Root1 = RootPth &"TheFiles"
Pth2 = PR &"Java\Java5"
Pth3 = PR &"Java\Java5.2"
Pth4 = PR &"Java\Java5.3"
' /|\ Hard-code paths
' /|\ No check to see if the source exists
' \|/
FS.CopyFolder Root1, Pth2, True
FS.CopyFolder Root1, Pth3, True
' /|\ There's no check to see if target's "root" exists.
' /|\ There's no check to see if the copy succeeded.
Posted by:
mailmanju
15 years ago
Hi,
Thanks everyone for your scripts and suggestions. Though, I cannot use hardcoded paths in the scripts, as part of my requirements. The reason being, I wouldn't know exactly what versions of JRE the USER has installed on his machine, nor would I know what USER would install in the future. Hence, hardcoding is not a reliable option for me. I worked on the script and ended up with a working script (hopefully). Below is the script.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
Set FSO = CreateObject("scripting.filesystemobject")
strKeyPath = "SOFTWARE\JavaSoft\Java Runtime Environment"
strValueName = "JavaHome"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,_
strValueName,strValue
If strValue <> "" then
If FSO.FolderExists(strValue) = True Then
FSO.CopyFile "<SourceFile1>", (strValue), True
FSO.CopyFile "<SourceFile2>", (strValue), True
FSO.CopyFile "<SourceFile3>", (strValue), True
End If
End If
Next
Thanks once again ALL.
Cheers,
manju
Thanks everyone for your scripts and suggestions. Though, I cannot use hardcoded paths in the scripts, as part of my requirements. The reason being, I wouldn't know exactly what versions of JRE the USER has installed on his machine, nor would I know what USER would install in the future. Hence, hardcoding is not a reliable option for me. I worked on the script and ended up with a working script (hopefully). Below is the script.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
Set FSO = CreateObject("scripting.filesystemobject")
strKeyPath = "SOFTWARE\JavaSoft\Java Runtime Environment"
strValueName = "JavaHome"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,_
strValueName,strValue
If strValue <> "" then
If FSO.FolderExists(strValue) = True Then
FSO.CopyFile "<SourceFile1>", (strValue), True
FSO.CopyFile "<SourceFile2>", (strValue), True
FSO.CopyFile "<SourceFile3>", (strValue), True
End If
End If
Next
Thanks once again ALL.
Cheers,
manju
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.