/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (5)

Posted by: anonymous_9363 14 years ago
Red Belt
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.
Posted by: jinxngoblins 14 years ago
Senior Yellow Belt
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
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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>
Posted by: anonymous_9363 14 years ago
Red Belt
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.
Posted by: mailmanju 14 years ago
Senior Yellow Belt
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ