The VBS script code to write a set command _vbs

Source: Internet
Author: User
Copy Code code as follows:

' Author: Liu Xianyong (Eric Liu)
' Copy and save the following code as the System command. VBS, and run the installation.
' After the installation is successful, you can set a command by right-clicking on a program, file, or folder-> send to the-> system command, and then you can enter the command to open the file in the run.
' Once the script is run, add a shortcut to run CMD From here in the right-click menu, and also increase the Find target file shortcut

' On Error Resume Next
If (LCase Right (wscript.fullname,11) <> "Wscript.exe") Then
Set Objshell=createobject ("Wscript.Shell")
Objshell.run ("Wscript//nologo" &AMP;CHR (+) &AMP;WSCRIPT.SCRIPTFULLNAME&AMP;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 = InStrRev (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 for
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, "Please 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

' Determines 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 ' No parameter run, copy itself to the SendTo folder.

MsgBox "Note that the silent run is the installation process!" "& VBCRLF & _
"The installation process includes the following actions:" & VBCRLF & VBCRLF & _
"1, the shortcut to create the script in the Send to Directory;" & VBCRLF & _
"2, after the installation can be sent 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 a menu item to the System shortcut command to create the current file or folder in the right-click menus
Pcmd.regwrite "hkey_classes_root\*\shell\g Create System Command \command\", "WScript.exe" & Thisfile & "" "%1" "", "REG_SZ"
Pcmd.regwrite "hkey_classes_root\directory\shell\g Create System Command \command\", "WScript.exe" & Thisfile & "" "%1" "", "REG _SZ "
' Add menu item to open CMD Window command on current path in right-click
Pcmd.regwrite "Hkey_classes_root\*\shell\q here to 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 right-click to find the shortcut location
Pcmd.regwrite "hkey_classes_root\*\shell\w Find target location \command\", "WScript.exe" & Thisfile & "S" "%1" "", "REG_SZ"
Pcmd.regwrite "hkey_classes_root\directory\shell\w Find 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 "Installation Successful!"
ElseIf Pargs.count = 1 Then
Open this script for editing if UCase (PArgs (0)) = ' edit ' Then ' has only one parameter and is edit.
Pcmd.run ("Notepad.exe" & Wscript.scriptfullname)
Wscript.Quit ()
ElseIF UCase (PArgs (0)) = "List" Then ' with only one parameter and list, lists all the shortcuts that have been established and their corresponding target files.
Resultfile=pcmd.regread ("Hkcu\software\microsoft\windows\currentversion\explorer\shell Folders\SysCmd") & "\ ListSysCmd.txt "
Listsyscmd Resultfile
Pcmd.run ("Notepad.exe" & Resultfile)
Wscript.Quit ()
Else ' When there is only one parameter, the default approach is to establish a shortcut to the file path passed in.
Pshortcutname=inputbox ("Enter the name of the shortcut:", "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 shortcut destination file location
' The decision whether to include \, from the right menu execution will directly pass the destination address, from the shortcut need to combine the address of the shortcut.
IF Instr (PArgs (1), "\") > 0 and Instr (PArgs (1), ". lnk") = 0 Then ' from right-click menu execution
Pcmd.run ("Explorer.exe/select," & PArgs (1))
Else ' executes 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 ("explorer.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 good script Save as Syscmd.vbs or other name, you can double-click the installation, the installation process is very simple, only the following steps.

1. Double click to start Installation

2. Select installation directory

3. Successful Installation

Now let's look at the right button menu.

1. Create a shortcut command function

Right-click the EXE program or any other file you want to create a shortcut command on, and then select the G Create System command from the shortcut menu, or press the letter G directly to eject the following dialog box:

Direct input shortcut commands, such as QQ, Shortcut command QQ on the creation of success.

Then want to start QQ directly win+r open the running window, and input QQ return, QQ program startup is so simple

2. Open the CMD function here

Right-click on any file or folder and choose "Q to open cmd here" or press Q directly to open the CMD window for the working directory

3. Find the target position function

For Windows shortcuts, often you want to find other file locations, is generally the right key and then check the properties, enumeration find files found, now any file or folder on the right button will have the following menu, select "W Find the target location" or directly by the W, You can find the destination file or folder location for the shortcut, or you can find the directory location of the program on the desktop.

Locate the file directly in the directory and open:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.