一键启动工具的生成

需要打开的软件





一键启动?

cmd?

1


hack


路径与环境变量

d

语法

  1. 判断是否启动
tasklist|find /i "WeChat.exe"
  1. 启动
start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
比如:

  1. 整合:
tasklist|find /i"WeChat.exe"&& echo "WeChat.exe is exists!!" || start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
  1. 写到批处理文件里:
@echo off
echo "start Now"
tasklist|find /i"WeChat.exe"&& echo "WeChat.exe is exists!!" || start C:\"Program Files (x86)"\Tencent\WeChat\WeChat.exe
tasklist|find /i"MarkdownPad2.exe"&& echo "MarkdownPad2.exe is exists!!" || start D:\markdown\markdownpad2-portable\MarkdownPad2.exe
tasklist|find /i"DeskTopShare.exe"&& echo "DeskTopShare.exe is exists!!" || start D:\DeskTopShare\DeskTopShare.exe
tasklist|find /i"vmware.exe"&& echo "vmware.exe is exists!!" || start D:\VMware\vmware.exe

exit

最终

start1.gif

一键生成工具代码:

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>快捷启动生成工具</title> 
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <form action="?" method="get">
            <textarea name="paths" id="" cols="30" rows="10" placeholder="输入的完整路径(支持快捷方式,文件夹,或其他文件, 不支持中文), 多个路径需换行, 格式形如:
D:\VMware\vmware.exe
C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe
E:\aaaaa\ide\" ></textarea>
            <br>
            <input class="first" type="submit" name='submit' value="点击生成">
        </form>
    </div>

</body>
</html>
<script src="js.js"></script>
<script>
    var oForm = document.forms[0];
    var oPaths = oForm.paths;
    var oSubmit = oForm.submit;
    var oContainer = document.getElementsByClassName('container')[0];
    oSubmit.onclick = function (e) {
        var e = e || event;
        e.preventDefault();
        var pathsLineFinal = getUserText();
        if(!pathsLineFinal) return;
        var isch = isChina(pathsLine)
        if(isch){
            alert("不可以为中文路径!");
            return;
        }
        var content = transTotext(pathsLineFinal);
        transTobat(content, 'start.bat');
    }
</script>

js代码(文件js.js):

function getUserText() {
    // 文本框文字
    pathsLine = oPaths.value;    
    return pathsLine;
}
// 转为有效的文本:
function transTotext(pathsLineFinal) {
    // 有效的文本形如:
    // tasklist|find /i "DeskTopShare.exe" && echo DeskTopShare.exe is exists || start D:\DeskTopShare\DeskTopShare.exe
    var fileNameList = pathsLineFinal.split('\n');
    var content = '@echo off \necho \"start Now\"\n';
    for (var i = 0; i < fileNameList.length; i++) {
        thisLine = fileNameList[i];
        var name = exeName(thisLine);
        // 用引号处理带有空格的目录
        pattern1 = /\\([\w\s]*\s+[\s\(\)\w]*)\\/g;
        thisLine = thisLine.replace(pattern1, '\\"$1"\\');
        // 带有字符的文件
        pattern2 = /\\([\w\s\.]*\s+[\s\w\.]*\.\w+)$/g;
        thisLine = thisLine.replace(pattern2, '\\"$1"');
        content1 = 'tasklist|find /i' + '\"' + name + '\"'
        content += content1 + '&& echo \"' + name + " is exists!!\" || start " + thisLine + "\n" ;
    }
    content += "\nexit";
    return content
}
// 传入完整文字信息和下载文件名字
function transTobat(batText, filename) {
    var blob = new Blob([batText]);
    var a = document.createElement('a');
    a.href = URL.createObjectURL(blob);
    a.innerHTML = "下载"
    a.download = filename;
    oContainer.appendChild(a);
    a.style.display = 'none';
    document.body.appendChild(a)
    a.click();
    document.body.removeChild(a);
}
function exeName(siglePath) {
    var index = siglePath.lastIndexOf('\\');
    var name = siglePath.slice(index + 1)
    return name
}
//检测是否含有中文:
function isChina(s) {
    var patrn = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
    if (!patrn.exec(s)) {
        return false;
    }
    else {
        return true;
    }
}

css代码(style.css):

.container{
    width: 500px;
    height: 400px;
    margin: 0 auto;
}
form{
    margin-top: 20px;
    text-align: center;
}
textarea{
    resize: none;
    width: 500px;
    height: 300px;
}
.first{
    margin-top: 20px;
    height: 40px;
    width: 100px;
}

项目地址: 项目地址

制作一键启动批处理.bat