<!DOCTYPE html>
<html>
<head>
    <title>文件夹快捷打开</title>
    <HTA:APPLICATION
        ID="oHTA"
        APPLICATIONNAME="open pvzHE"
        BORDER="thin"
        CAPTION="yes"
        SHOWINTASKBAR="yes"
        SINGLEINSTANCE="yes"
        SYSMENU="yes"
        WINDOWSTATE="normal"
    />
    <script language="VBScript" type="text/vbscript">
        Sub Button1_Click()
            Set objShell = CreateObject("WScript.Shell")
            strSoftwareName = "pvzHE"
            strRegPath = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strSoftwareName

            On Error Resume Next
            strUninstallString = objShell.RegRead(strRegPath & "\UninstallString")
            On Error GoTo 0

            If strUninstallString <> "" Then
                ' 去掉卸载字符串中的参数部分，只保留路径
                strPath = Left(strUninstallString, InStrRev(strUninstallString, "\") - 1)
                
                ' 检查路径是否存在
                If strPath <> "" Then
                    objShell.Run "explorer.exe " & strPath  ' 暂时去掉 chr(34) 处理
                Else
                    MsgBox "路径异常，无法打开文件夹"
                End If
            Else
                MsgBox "找不到文件夹，可能游戏未安装"
            End If
        End Sub
        
        Dim fso

        Sub Button2_Click()
            Dim shell, folderPath, systemDrive
            ' 创建 FileSystemObject 和 Shell 对象实例
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set shell = CreateObject("WScript.Shell")

            ' 获取系统驱动器路径
            systemDrive = shell.ExpandEnvironmentStrings("%SystemDrive%")
            folderPath = systemDrive & "\ProgramData\PopCap Games\PlantsVsZombies\pvzHE\yourdata"

            ' 检查文件夹是否存在，如果不存在则递归创建
            CreateFoldersRecursive folderPath

            ' 启动文件夹
            shell.Run "explorer.exe " & Chr(34) & folderPath & Chr(34)
        End Sub

        ' 递归创建文件夹的函数
        Sub CreateFoldersRecursive(path)
            If Not fso.FolderExists(path) Then
                ' 获取父文件夹路径
                parentFolder = fso.GetParentFolderName(path)
                If Not fso.FolderExists(parentFolder) Then
                    ' 递归创建父文件夹
                    CreateFoldersRecursive parentFolder
                End If
                ' 创建当前文件夹
                fso.CreateFolder(path)
            End If
        End Sub
    </script>
    <script type="text/javascript">
        function resizeWindow(width, height) {
            window.resizeTo(width, height);
        }

        window.onload = function() {
            resizeWindow(450, 300); // 调整为你需要的宽度和高度
        }
    </script>
    <style>
    body{
        text-align:center;
    }
    button{
        height:50px;
        cursor:pointer;
    }
    </style>
</head>
<body>
    <h2>默认文件夹快速打开</h2>
    <button onclick="Button1_Click()">打开游戏文件夹</button>
    <br/>
    <br/>
    <button onclick="Button2_Click()">打开存档文件夹</button>
</body>
</html>