j2sdk环境变量自动设置脚本

'set_java_env.vbs

'******************************************************** 
' FolderSelectDialog.vbs j2sdk环境变量自动设置脚本 
' CodeFish Edit this File .QQ:6120799 
' Alan Kaplan alan at akaplan dot com 12-15-2005 
' after getting tired of reading it will not work... 
' Based in part on FileSelectDialog.vbs by Gunter Born 
' Kaplan added handling of special folders 
' Tested okay with XP and 2000 
' Uses the shell browseforfolder method to select a folder 
'******************************************************** 
Option Explicit 
' Flags for the options parameter 
Const BIF_returnonlyfsdirs = &H0001    'Don't want no steenkin' filenames 
Const BIF_ShowAllObjects      = &H0008    'ReturnFSAncestors. This will give you typical root view 'XP has My Computer, My Network Places not seen on 2000 
Const BIF_editbox = &H0010    'Show active selection, allows manual input 
Dim wshShell,WshEnv 
'Wscript object 
Set wshShell = WScript.CreateObject("WScript.Shell") 
Set WshEnv=WshShell.Environment("System") 
'=== Example === 
Dim strFolder 
StrFolder = BrowseForFolder("选择J2sdk的安装目录:", _
BIF_returnonlyfsdirs + BIF_editbox + BIF_ShowAllObjects,"") 
'If Len(strFolder)>0 Then 
'    MsgBox strFolder,vbOKOnly, "Selected Folder" 
'End If 
If Len(strFolder)>0 Then 
strFolder=mid(strFolder,1,len(strFolder)-1)'删除"\" 
WshEnv.Item("Java_Home")=strFolder 
WshEnv.Item("Path")="%Java_Home%\bin;" & WshEnv.Item("Path") 
WshEnv.Item("ClassPath")=".;%Java_Home%\lib\dt.jar;%Java_Home%\lib\tools.jar;%Java_Home%\lib\htmlconverter.jar" 
MsgBox "Java_Home=" & WshEnv.Item("Java_Home") & vbcrlf &_ 
            ("Path=") & WshEnv.Item("Path") & vbcrlf &_ 
            ("ClassPath=") & WshEnv.Item("ClassPath") ,vbOKOnly, "环境变量设置完毕!" 
End If 
'= End Example === 
Function BrowseForFolder(title, flag, dir) 
    ' title = Text shown in the dialog box 
    ' flag = values controlling BrowseForFolder behavior 
    ' dir = Initial directory (can be ""). 
    '    dir most useful when not using BIF_ShowAllObjects 
On Error Resume Next 
Dim oShell, oItem, strSelection 
' Create Shell object. 
Set oShell = WScript.CreateObject("Shell.Application") 
' Invoke Browse For Folder dialog box. 
Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir) 
        strSelection = oItem.Title 
        If Err <> 0 Then 
'cancelled 
Set oShell = Nothing 
Set oItem = Nothing 
Exit Function 
End If 
      
' If colon found then get drive letter from the title. 
No array 
If InStr(strSelection, ":") Then 
BrowseForFolder = mid(strSelection,InStr(strSelection, ":")-1, 2) 
    Else 
    'Handle all other special cases where path not returned 
        Select Case strSelection 
            Case "Desktop" 
                BrowseForFolder = wshShell.SpecialFolders("Desktop") 
            Case "My Documents" 
                BrowseForFolder = wshShell.SpecialFolders("MyDocuments") 
            Case "My Computer" 
                MsgBox "Invalid selection",vbCritical + vbOKOnly,"Error" 
                WScript.Quit 
            Case "My Network Places" 
                MsgBox "Invalid selection",vbCritical + vbOKOnly,"Error" 
                WScript.Quit 
            Case Else         
             ' Finally try to retrieve the full path a la Born 
             BrowseForFolder = oItem.ParentFolder.ParseName(oItem.Title).Path 
        End Select 
    End If 
      
    'Cleanup 
Set oShell = Nothing 
Set oItem = Nothing     
    'make sure they all end in \ 
If Right(browseForFolder,1)<> "\" Then 
    browseforfolder = browseforfolder & "\" 
End If 
    'Alternate make sure they all end without \ 
' If Right(browseForFolder,1) = "\" Then 
'     browseforfolder = left(BrowseForFolder,Len(BrowseForFolder)-1) 
' End If 
    On Error GoTo 0 
End Function

你可能感兴趣的:(j2sdk环境变量自动设置脚本)