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
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
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.
Answered 10/30/2009 by: VBScab
Red Belt

Please log in to comment
0
Dim WS, FS, RootPth
Set WS=CreateObject("WScript.Shell")
Set FS=CreateObject("Scripting.FileSystemObject")
RootPth = Session.Property("SOURCEDIR")
PR = WS.ExpandEnvironmentStrings("%PROGRAMFILES%")
Root1 = RootPth &"TheFiles"
Pth2 = PR &"Java\Java5"
Pth3 = PR &"Java\Java5.2"
Pth4 = PR &"Java\Java5.3"
FS.CopyFolder Root1, Pth2, True
FS.CopyFolder Root1, Pth3, True
' blah blah
Answered 10/30/2009 by: jinxngoblins
Senior Yellow Belt

Please log in to comment
0
As you may know, the script interface to the registry which most people use, the Shell object.


<Monocle> People actually use the shell object for registry operations? </monocle>
Answered 10/30/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
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.
Answered 10/31/2009 by: VBScab
Red Belt

Please log in to comment
0
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
Answered 11/02/2009 by: mailmanju
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity