AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-2280728

kaj's questions

Martin Hope
kaj
Asked: 2024-10-16 11:17:41 +0800 CST

我希望这个脚本能够与“文件和文件夹”一起使用,并避免弹出窗口

  • 3
//  SendToQuickLaunch.js - Version 1.3
//  Copyright (c) 2010, 2013 Bill Chatfield <[email protected]>
//  All rights reserved.

var programDesc = "Send to Quick Launch";
var quickLaunchMenuItem = "Quick Launch (create shortcut)";
var installFolder = getEnvironmentVariable("AppData") + "\\" + programDesc;
var installedScript = installFolder + "\\" + WScript.ScriptName;

var shell = null;
var environment = null;
var fileSystem = null;

/* Returns a FileSystemObject object */
function getFileSystem() {
    if (fileSystem == null) {
        fileSystem = WScript.CreateObject("Scripting.FileSystemObject");
    }
    return fileSystem;
}

/* Returns a WshShell object */
function getShell() {
    if (shell == null) {
        shell = WScript.CreateObject("WScript.Shell");
    }
    return shell;
}

/* Returns a WshEnvironment object */
function getEnvironment() {
    if (environment == null) {
        environment = getShell().Environment("Process");
    }
    return environment;
}

/* Returns a String object */
function getEnvironmentVariable(name) {
    var env = getEnvironment();
    return env(name);
}

/* String */
function askOperation() {
    // Ask the user if they want to install.
    var answer = getShell().Popup("Install \"Quick Launch\" option in the \"Send To\" menu?", 300, programDesc + " - Admin", 4 + 32);
    if (answer == 6) { // If Yes
        return 'install';
    }
    var answer = getShell().Popup("Remove \"Quick Launch\" option from the \"Send To\" menu?", 300, programDesc + " - Admin", 4 + 32);
    if (answer == 6) { // If Yes
        return 'remove';
    }
    return '';
}

/* void */
function install() {
    // Copy this script into its formal install folder.
    if (! getFileSystem().FolderExists(installFolder)) {
        getFileSystem().CreateFolder(installFolder);
    }
    // Destination folder must end in a backslash to be recognized as a folder.
    getFileSystem().CopyFile(WScript.ScriptFullName, installFolder + "\\", true);

    // Create the link in the SendTo folder that is invoked by the
    // "Quick Launch" menu item on the "Send To" menu. This also
    // creates the menu item beause Windows creates the "Send To"
    // menu from whatever is in the "SendTo" special folder.
    var sendToFolder = getShell().SpecialFolders("SendTo");
    var link = getShell().CreateShortcut(sendToFolder + "\\" + quickLaunchMenuItem + ".lnk");
    link.TargetPath = installedScript;
    link.WindowStyle = 1;
    link.IconLocation = "wscript.exe, 3"; // The yellow JavaScript icon is at index 3.
    link.Description = programDesc;
    link.WorkingDirectory = installFolder;
    link.Save();

    // Create a link in the Start Menu to allow uinstalling of this script.
    var programsFolder = getShell().SpecialFolders("Programs");
    var startMenuFolder = programsFolder + "\\" + programDesc;
    if (! getFileSystem().FolderExists(startMenuFolder)) {
        getFileSystem().CreateFolder(startMenuFolder);
    }
    var startMenuLink = getShell().CreateShortcut(startMenuFolder + "\\Uninstall " + programDesc + ".lnk");
    startMenuLink.TargetPath = installedScript;
    startMenuLink.Arguments = "--uninstall";
    startMenuLink.WindowStyle = 1;
    startMenuLink.IconLocation = "wscript.exe, 3";
    startMenuLink.Description = "Uninstall " + programDesc;
    startMenuLink.WorkingDirectory = installFolder;
    startMenuLink.Save();

    // Tell the user it was successful.
    getShell().Popup("The installation is complete.", 300, programDesc + " - Admin", 64);
}

/* void */
function uninstall() {
    // Uninstall Send To link.
    var sendToFolder = getShell().SpecialFolders("SendTo");
    var link = sendToFolder + "\\" + quickLaunchMenuItem + ".lnk";
    if (getFileSystem().FileExists(link)) {
        getFileSystem().DeleteFile(link);
    }

    // Uninstall file and folder in Program Files.
    if (getFileSystem().FileExists(installedScript)) {
        getFileSystem().DeleteFile(installedScript);
    }
    if (getFileSystem().FolderExists(installFolder)) {
        getShell().CurrentDirectory = "C:\\";  // Move away so we can delete it.
        getFileSystem().DeleteFolder(installFolder);
    }

    // Uninstall Start Menu link and folder.
    var programsFolder = getShell().SpecialFolders("Programs");
    var startMenuFolder = programsFolder + "\\" + programDesc;
    var startMenuLink = startMenuFolder + "\\Uninstall " + programDesc + ".lnk";
    if (getFileSystem().FileExists(startMenuLink)) {
        getFileSystem().DeleteFile(startMenuLink);
    }
    if (getFileSystem().FolderExists(startMenuFolder)) {
        getFileSystem().DeleteFolder(startMenuFolder);
    }

    getShell().Popup("It has been removed.", 300, programDesc + " - Admin", 64);
}

/* void */
function createQuickLaunchLinkFor(targetName) {
    var target = getFileSystem().GetFile(targetName);
    var link = getShell().CreateShortcut(buildShortcutFileName(target));
    link.TargetPath = target.Path;
    link.WindowStyle = 1;
    link.Description = "Shortcut to " + target.Path;
    link.WorkingDirectory = target.ParentFolder;
    link.Save();
    getShell().Popup("A shortcut to " + targetName + " was added to the Quick Launch menu.", 300, programDesc, 64);
}

/* String */
function buildShortcutFileName(/* File */ target) {
    var homeDir = getEnvironmentVariable("USERPROFILE");
    var quickLaunchDir = homeDir + "\\Desktop";
    var name = quickLaunchDir + "\\" + target.Name;
    var duplicateFileStartIndex = 2;
    var i = duplicateFileStartIndex;
    
    // Check for extensions that should be removed.
    if (target.Type == "Application") {
        // Remove the extension.
        name = name.replace(/\.exe$/i, "");
    }
    else if (target.Type == "MS-DOS Batch File") {
        // Remove the extension.
        name = name.replace(/\.bat$/i, "");
    }
    
    // If the target is a Shortcut already, then do not append an additional
    // link extension to the new Shortcut name. Else...
    if (target.Type != "Shortcut") {
        // The new Shortcut name does not have a ".lnk" Shortcut extension
        // because the target didn't have one, so it needs one now.
        name += ".lnk";
    }
    
    // Resolve Shortcut name conflicts.
    while (getFileSystem().FileExists(name)) {
        if (i == duplicateFileStartIndex) {
            name = name.replace(/\.lnk$/i, "(" + i + ").lnk");
        }
        else {
            name = name.replace(/\(\d+\)\.lnk$/i, "(" + i + ").lnk");
        }
        i++; // Increment index and try again.
    }
    return name;
}

/* Boolean */
function isUninstallSwitch(arg) {
    var switches = new Array("--remove", "-remove", "--uninstall", "-uninstall");
    var i;
    for (i in switches) {
        if (arg == switches[i]) {
            return true;
        }
    }
}

/////////////////////////////////////////////////////////////////////////////
//
//  Main Program
//
/////////////////////////////////////////////////////////////////////////////

var targetName;

if (WScript.Arguments.length == 0) {
    // If there is no argument, then perform an install or remove.
    var op = askOperation();
    if (op == 'install') {
        install();
    }
    else if (op == 'remove') {
        uninstall();
    }
}
else {
    // There is at least one command line argument.
    targetName = WScript.Arguments(0);

    if (isUninstallSwitch(targetName)) {
        uninstall();
    }
    else {
        // If we have an argument then we were invoked from the SendTo menu,
        // so create a Quick Launch link for the given argument.
        createQuickLaunchLinkFor(targetName);
    }
}
vbscript
  • 1 个回答
  • 78 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve