本帖最后由 flashercs 于 2021-1-15 20:49 编辑
"固定到任务栏和开始菜单.js.bat"
经实验 win7可以,win10 H2不行- 0<1/*,:
- @echo off
- REM 用法:
- REM cscript -nologo -e:jscript %0 [-PinToTaskbar files] [-UnpinFromTaskbar files] [-PinToStart files] [-UnpinFromStart files]
- REM files 是以空格分割的文件列表
- REM cscript -nologo -e:jscript %0 -UnpinFromTaskbar "%windir%\system32\notepad.exe" "%windir%\system32\cmd.exe" "%programfiles(x86)%\internet explorer\iexplore.exe" -pintostart "C:\Users\Flashercs\OneDriveTools\Tools" "%windir%\system32\notepad.exe"
- @REM cscript -nologo -e:jscript %0 -PinToTaskbar "%windir%\system32\notepad.exe"
- cscript -nologo -e:jscript %0 -UnpinFromTaskbar "%windir%\system32\notepad.exe"
- exit /b %errorlevel%
- */;
- var ARGS = WScript.Arguments;
- if (ARGS.Length === 0) {
- WScript.Echo('No file passed');
- WScript.Echo('Usage(pins/unpins items to/from startmenu/taskbar):');
- WScript.Echo(WScript.ScriptName + ' [-PinToTaskbar files] [-UnpinFromTaskbar files] [-PinToStart files] [-UnpinFromStart files]');
- WScript.Quit(1);
- }
- var oFiles = {}, arr;
- for (var i = 0, l = ARGS.length; i < l; i++) {
- switch (ARGS(i).toLowerCase()) {
- case '-pintotaskbar':
- case '/pintotaskbar':
- arr = oFiles.pintotaskbar = [];
- break;
- case '-unpinfromtaskbar':
- case '/unpinfromtaskbar':
- arr = oFiles.unpinfromtaskbar = [];
- break;
- case '-pintostart':
- case '/pintostart':
- arr = oFiles.pintostart = [];
- break;
- case '-unpinfromstart':
- case '/unpinfromstart':
- arr = oFiles.unpinfromstart = [];
- break;
- default:
- try {
- arr.push(ARGS(i));
- } catch (e) {
-
- }
- }
- }
-
- //fso
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- function existsItem(path) {
- return fso.FolderExists(path) || fso.FileExists(path);
- }
- //get windows version
- var version = GetObject('winmgmts://./root/cimv2').Get('Win32_OperatingSystem=@').Version;
- version = parseInt(version.replace(/\./g, ''));
- // WScript.Echo('os version=' + version);
-
- // if version is later than windows 7 there's pin to start screen instead pin to start menu
- if (version <= 619999) {
- var startVerb1 = 'startpin';
- } else if (version < 10000000) {
- startVerb1 = 'pintostartscreen';
- } else {
- startVerb1 = '';
- }
- var objShell = new ActiveXObject('Shell.Application');
- var oFuncs = {
- 'pintotaskbar': function pintotaskbar(arrFiles) {
- if (startVerb1 === '') {
- var shell = new ActiveXObject('WScript.Shell');
- var regkey = 'HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\taskbarpin\\';
- var regvalue = 'ExplorerCommandHandler';
- shell.RegWrite(regkey + regvalue, '{90AA3A4E-1CBA-4233-B8BB-535773D48449}', 'REG_SZ');
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- WScript.Echo('pinning "' + fullFilename + '" to taskbar ');
- objItem.InvokeVerb('taskbarpin');
- }
- shell.RegDelete(regkey);
- } else {
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- WScript.Echo('pinning "' + fullFilename + '" to taskbar ');
- objItem.InvokeVerb('taskbarpin');
- }
- }
- },
- 'unpinfromtaskbar': function unpinfromtaskbar(arrFiles) {
- if (startVerb1 === '') {
- var shell = new ActiveXObject('WScript.Shell');
- var regkey = 'HKEY_CURRENT_USER\\Software\\Classes\\*\\shell\\taskbarpin\\';
- var regvalue = 'ExplorerCommandHandler';
- shell.RegWrite(regkey + regvalue, '{90AA3A4E-1CBA-4233-B8BB-535773D48449}', 'REG_SZ');
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- WScript.Echo('Unpinning "' + fullFilename + '" from taskbar.');
- objItem.InvokeVerb('taskbarpin');
- }
- shell.RegDelete(regkey);
- } else {
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- WScript.Echo('Unpinning "' + fullFilename + '" from taskbar.');
- objItem.InvokeVerb('taskbarunpin');
- }
- }
- },
- 'pintostart': function pintostart(arrFiles) {
- var re = /Pin to Start|固定到.?开始/i;
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- var verbs = objItem.Verbs();
- for (var j = 0; j < verbs.Count; j++) {
- if (re.test(verbs.Item(j).Name.replace(/&/g, ''))) {
- WScript.Echo('pinning "' + fullFilename + '" to start menu.');
- verbs.Item(j).DoIt();
- break;
- }
- }
- }
- },
- 'unpinfromstart': function unpinfromstart(arrFiles) {
- var re = /Unpin from Start|从.?开始.*取消固定/i;
- for (var i = 0, l = arrFiles.length; i < l; i++) {
- var filename = arrFiles[i];
- if (!existsItem(filename)) {
- WScript.Echo(filename + 'does not exist.');
- continue;
- }
- var fullFilename = fso.GetAbsolutePathName(filename);
- var objFolder = objShell.NameSpace(fso.GetParentFolderName(fullFilename));
- var objItem = objFolder.ParseName(fso.GetFileName(fullFilename));
- var verbs = objItem.Verbs();
- for (var j = 0; j < verbs.Count; j++) {
- if (re.test(verbs.Item(j).Name.replace(/&/g, ''))) {
- WScript.Echo('Unpinning "' + fullFilename + '" from start menu.');
- verbs.Item(j).DoIt();
- break;
- }
- }
- }
- }
- };
- for (var key in oFiles) {
- oFuncs[key](oFiles[key]);
- }
复制代码
|