REM ** vbscript to hunt Registry for desired JRE version
REM ** if found, reset NCDesk shortcut values using:
REM ** new JRE path and the NCDesk path passed in
REM **
Const vers = "1.5.0_08"
Dim strKeyPath, strDesktop
Dim ncdeskPath, jrePath, jbinPath

On Error Resume Next
Set WshShell = Wscript.CreateObject("Wscript.Shell")
ncdeskPath = WshShell.CurrentDirectory
'wscript.echo "ncdesk path " & ncdeskPath

REM ** hunt for correct JRE
strKeyPath = "HKLM\SOFTWARE\JavaSoft\Java Runtime Environment\" & vers
jrePath = WshShell.RegRead(strKeyPath & "\JavaHome")

If IsEmpty(jrePath) Then
  wscript.echo "Please install Java Runtime Environment " & vers & "."
  wscript.quit
End If
'wscript.echo "reg jre path " & jrePath

REM set JRE path
jbinPath = """" & jrePath & "\bin\javaw.exe"""
'wscript.echo "java bin path: " & jbinPath

set objGlobalEnv = WshShell.Environment("PROCESS")
'wscript.echo "os = " & objGlobalEnv("OS")
If UCase(objGlobalEnv("OS")) = "WINDOWS_NT" Then
    strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
Else
    strDesktop = WshShell.SpecialFolders("Desktop")
End If
'wscript.echo "desktop " & strDesktop

set oShellLink = WshShell.CreateShortcut(strDesktop & "\NCDesk.lnk")
oShellLink.TargetPath = jbinPath
oShellLink.Arguments = "-jar """ & ncdeskPath & "\ncdesk.jar"""
oShellLink.IconLocation = ncdeskPath & "\ncdesk.ico,0"
oShellLink.WindowStyle = 1
oShellLink.WorkingDirectory = ncdeskPath
oShellLink.Save

If Err.Number <> 0 Then
    wscript.echo "Update of NCDesk shortcut failed."
End If

wscript.quit
