'Prepared by Eric Liu)
'Copy and save the following code as "system command. vbs" and run the installation.
'After the installation is successful, you can right-click a program, file, or folder and choose "send"> "system command" to set a command. Then, you can enter the command to open the file during running.
'After the script runs once, add a shortcut to run cmd from here in the right-click menu, and add a shortcut to find the target file.
'On error resume next
If (lcase (right (wscript. fullname, 11) <> "wscript.exe") then
Set objshell = Createobject ("wscript. Shell ")
Objshell. Run ("wscript // nologo" & CHR (34) & wscript. scriptfullname & CHR (34 ))
Wscript. Quit
End if
Set pcmd = Createobject ("wscript. Shell ")
Set PFSO = Createobject ("scripting. FileSystemObject ")
Set pshell = Createobject ("Shell. Application ")
Set psysenv = Createobject ("wscript. Shell"). Environment ("system ")
Strcomputer = "."
Set pwmiservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Function lgetpath (pfile)
Ilastseppos = Limit Rev (pfile, "\",-1, 1)
If ilastseppos <= 0 then
Lgetpath = ""
Exit Function
Else
Lgetpath = left (pfile, iLastSepPos-1)
End if
End Function
Function getlnktarget (linkpath)
Linkpath = Replace (linkpath ,"\","\\")
Set pfiles = pwmiservice. execquery ("select * From win32_shortcutfile where name =" & "'" & linkpath &"'")
For each pfile in pfiles
Getlnktarget = pfile. Target
Exit
Next
End Function
Function listsyscmd (pfilename)
Syscmdpath = pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd ")
Set pfolder = PFSO. getfolder (syscmdpath)
Set pfile = PFSO. opentextfile (pfilename, 2, true)
For each file in pfolder. Files
Linkpath = syscmdpath & "\" & file. Name
If ucase (right (file. Name, 4) = ". lnk" then
Set lnkfiles = pwmiservice. execquery ("select * From win32_shortcutfile where name =" & "'" & replace (linkpath ,"\","\\")&"'")
For each lnkfile in lnkfiles
Pfile. writeline (linkpath & "& lnkfile. Target)
Next
Else
Pfile. writeline linkpath
End if
Next
End Function
Function getconfigpath
Set pfolder = pshell. browseforfolder (0, "select a directory:", 0, ": {20d04fe0-3aea-1069-a2d8-08002b30309d }")
If pfolder is nothing then
Wscript. Quit
End if
Set pfolderitem = pfolder. Self
Getconfigpath = pfolderitem. Path
End Function
Sub setenv (ppath, pvalue)
If pvalue = "" then
Psysenv. Remove (ppath)
Else
Psysenv (ppath) = pvalue
End if
End sub
Function getenv (ppath)
Getenv = psysenv (ppath)
End Function
'Determine whether a string matches a regular expression
'^ \ W + [@] \ W + [.] \ W + $ e-mail address
'^ [0-9-] + $ number
Function ismatch (STR, patrn)
Set R = new Regexp
R. pattern = patrn
Ismatch = R. Test (STR)
End Function
Sub addnewcmd (pshortcutname, ptargetpath, pcmdlocation)
If pshortcutname <> "" then
Linkdir = pcmdlocation
Set pcmdlink = pcmd. createshortcut (linkdir & "\" & pshortcutname & ". lnk ")
Pcmdlink. targetpath = ptargetpath
Pcmdlink. windowstyle = 1
Pcmdlink. hotkey = ""
Pcmdlink. iconlocation = "% SystemRoot % \ system32 \ shell32.dll, 146"
Pcmdlink. Description = "shortcut created at" & date () & "" & time ()
Pcmdlink. workingdirectory = lgetpath (ptargetpath)
Pcmdlink. Save
End if
End sub
Set pargs = wscript. Arguments
If pargs. Count = 0 then 'runs without parameters, copy itself to the sendto folder.
Msgbox "Pay attention to running without parameters to execute the installation process! "& Vbcrlf &_
"The installation process includes the following operations:" & vbcrlf &_
"1. Create a shortcut for this script in the directory;" & vbcrlf &_
"2. After the installation is complete, you can send it to create a shortcut;" & vbcrlf &_
"3. All shortcut commands can be executed by running (WIN + r. "& Vbcrlf
Syscmdpath = getconfigpath
If syscmdpath = "" Then wscript. Quit ()
Pcmd. regwrite "hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd", syscmdpath, "REG_SZ"
'Path = pcmd. regread ("HKEY_LOCAL_MACHINE \ SYSTEM \ controlset001 \ Control \ Session Manager \ environment \ path ")
Path = getenv ("path ")
If right (syscmdpath, 1) = "\" then syscmdpath = left (syscmdpath, Len (syscmdpath)-1)
Syscmdpathpattern = "(;)? ("& Replace (syscmdpath ,"\","\\")&")(\\)? (; | $ )"
If not ismatch (path, syscmdpathpattern) then
Path = Path & ";" & syscmdpath
Setenv "path", path
End if
Thisfile = wscript. scriptfullname
If thisfile <> syscmdpath & "\" & wscript. scriptname then
PFSO. copyfile thisfile, syscmdpath &"\"
Thisfile = syscmdpath & "\" & wscript. scriptname
End if
Addnewcmd "n system command", thisfile, pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ sendto ")
'Add the menu item of the system shortcut command for creating the current file or folder in the context menu.
Pcmd. regwrite "hkey_classes_root \ * \ shell \ G create system command \", "wscript.exe" & thisfile & "% 1" "," REG_SZ"
Pcmd. regwrite "hkey_classes_root \ directory \ shell \ G create system command \", "wscript.exe" & thisfile & "% 1" "," REG_SZ"
'Add the menu item for opening the CMD window command in the current path in the context menu.
Pcmd. regwrite "hkey_classes_root \ * \ shell \ q open cmd \ command \", "CMD/K pushd" "% 1 \ ..", "REG_SZ"
Pcmd. regwrite "hkey_classes_root \ directory \ shell \ q open cmd \ command \", "CMD/K pushd" "% 1", "REG_SZ"
'Add a menu item in the shortcut menu
Pcmd. regwrite "hkey_classes_root \ * \ shell \ W find the target location \ command \", "wscript.exe" & thisfile & "S" "% 1", "REG_SZ"
Pcmd. regwrite "hkey_classes_root \ directory \ shell \ W find the target location \ command \", "wscript.exe" & thisfile & "S" "% 1", "REG_SZ"
Addnewcmd "Q", pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd"), pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd ")
Addnewcmd "QC", thisfile, pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd ")
Msgbox "installed successfully! "
Elseif pargs. Count = 1 then
If ucase (pargs (0) = "edit" then' has only one parameter and is edit, open this script for editing.
Pcmd. Run ("notepad.exe" & wscript. scriptfullname)
Wscript. Quit ()
Elseif ucase (pargs (0) = "list" then' only has one parameter and is list. All created shortcuts and their corresponding target files are listed.
Resultfile = pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd") & "\ listsyscmd.txt"
Listsyscmd resultfile
Pcmd. Run ("notepad.exe" & resultfile)
Wscript. Quit ()
When else has only one parameter, the default processing method is to create a shortcut for the input file path.
Pshortcutname = inputbox ("Enter the shortcut name:", "Create a shortcut command ...","")
If pshortcutname = "" Then wscript. Quit ()
Addnewcmd pshortcutname, pargs (0), pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd ")
End if
Elseif pargs. Count = 2 then
If ucase (pargs (0) = "S" then' find the location of the target file in the shortcut
'Determine whether to include \. The target address will be directly transferred from the right-click menu, and the shortcut address needs to be combined from the shortcut.
If instr (pargs (1), "\")> 0 and instr (pargs (1), ". lnk") = 0 then "from the context menu
Pcmd. Run ("assumer.exe/select," & pargs (1 ))
Else' run from the command line
If instr (pargs (1), "\")> 0 then' full path. lnk path
Linkpath = pargs (1)
Else
Linkpath = pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd") & "\" & pargs (1) & ". lnk"
End if
Linkpath = Replace (linkpath ,"\","\\")
Set pfiles = pwmiservice. execquery ("select * From win32_shortcutfile where name =" & "'" & linkpath &"'")
For each pfile in pfiles
Pcmd. Run ("assumer.exe/N,/select," & pfile. Target)
Next
End if
Else
'Filelocation, shortcutname
Pshortcutname = pargs (1)
Addnewcmd pshortcutname, pargs (0), pcmd. regread ("hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Shell Folders \ syscmd ")
End if
End if
Copy the script and save it as syscmd. vbs or another name. You can double-click it to install it. The installation process is very simple and only takes the following steps.
1. Double-click to start Installation
2. Select the installation directory
3. Installation successful
Right-click the menu.
1. Create a shortcut command
In the EXE where you want to create a Quick CommandProgramOr right-click any other file, and select "G create System Command" in the shortcut menu, or press the letter G to bring up the following dialog box:
Enter a shortcut command, such as QQ. The shortcut command QQ is successfully created.
Then, when you want to start QQ, open the running window with win + R and press Enter. It's so easy to start the QQ program.
2. Enable the CMD function here.
Right-click any file or folder and select "Q open cmd here" or press Q to open the CMD window as the working directory.
3. Find the target location
For Windows shortcuts, you often need to find the location of other files. Generally, You need to right-click the file and check the properties to find the file. Now, right-click any file or folder and choose the following menu, select "W find target location" or press W to find the destination file or folder location of the shortcut, or find the directory location of the Program on the desktop.
Locate the directory where the file is located and open it: