使用批处理文件创建自己的快捷方式
Start Command in Batch File
Syntax START [“title”] [/D path] [/I] [flags specifying state of window] [flags specifying memory space of program] [priority flags] [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B] [command/program] [parameters]
‘Start’ command is helpful when we require starting a new program window or a command prompt. All the run line commands can be started using this start command in our program. You can see that start command has a very large syntax, but it is pretty simple enough to understand. Let us break it down and deal with a single piece at a time.
Start We use simply start command without any parameters or flags starting a new command prompt in the current directory.
Title The first part is the “Title”. It is specified in quotes, the title is used to display a specified title in window title bar. If you can remember, we already discussed in the previous post.
Eg: start “My Shell”
The above command starts a new command prompt titled as “My shell”.
Path The path is used with the flag /D to specify the starting directory when you start a new command prompt using simply start command. Eg: start /d “C:Userscrazyprogrammer”
Starts a new command prompt with starting directory as the specified one above
I This flag tells that the new environment will be the original environment passed to command prompt initially and not the current executing environment of the program.
State of window We have two flags to specify the state of a window that is being started by the start command. ‘/MIN’ starts the new window in a minimized state, whereas ‘/MAX’ flag specifies the state of windows to be in a maximized state.’/max’ and ‘/min’ switches open up new command prompt either maximized or minimized based on flag used, if no application is specified.
Eg: start /max mspaint
This command opens up MSPaint application with the windows state maximized. You can try similarly for min switch.
B ‘/b’ flag is used to start application on the same console without creating a new window. It’s similar to having two command prompts at the same time. Once you start new command prompt, typing exit will terminate the current one and open up the previous prompt but will not close the window entirely. The application that has been opened up has ^C handling ignored, unless the application enables ^C processing, to interrupt the application ^Break is the only way.
Memory space Next comes the switch to specify the memory space of a program. Often it is necessary to specify the memory space of the windows programs. ‘/SEPARATE switch starts a 16-bit Windows program in separate memory space. ‘/SHARED’ switch allocates shared memory for all the programs.
Eg: start /shared write
The above command is used for opening a WordPad in a shared memory space.
Priority switches If you are familiar with the multithreading and concurrent processing in operating systems, you might have known that there are basically 4 priorities for any process to allocate the CPU. ‘/LOW’ switch starts an application and places it in IDLE priority class. ‘/NORMAL’ switch starts the application and assigns it a NORMAL priority. ‘/HIGH’ switch is used or applications that need CPU to be allocated urgently hence place them in HIGH priority class. ‘/REALTIME’ switch opens an application by setting its priority to REALTIME priority class. Similarly, we also have ‘/abovenormal’ and ‘/belownormal’ switches.
Eg: start /belownormal mshearts.exe
The above command opens up the “hearts” game with the below normal priority class with the priority which stays in between the normal and idle.
Batch program to open your favorite programs and websites easily If you are a no voice user of windows and you want to use your PC like a pro, the below program helps you out. The basic idea behind creating the below program is we frequently be using different shortcuts and programs. Every time we need them, we need to go search them or we need to open up the start menu to get frequently listed programs. Instead of doing so, we can create a batch file to place all our shortcuts at one place.
Before getting into the program, I’d like to mention that I’ve given a list of run commands during the introductory lesson which might be helpful here. The program is very simple enough to understand, I’ve used the simple start command without any switches here. You know how to run the below code. Copy it, save it as shortcuts.bat and double click to execute it. You can see the options displayed as a list on the command prompt as shown below.
I’ve displayed all the options using simple echo commands. To collect the choice of the user, I declared a variable using /p flag for the set command
set /p choice=
Then using a series of if conditional checker, I’ve placed the programs in the respective sections like the one’s shown below.
if %choice%==1 ( start appwiz.cpl ) if %choice%==2 ( start control )
Isn’t awesome, Go and create your own shortcuts. I’d like to mention one thing here. This program lets’s you to open your favorite websites directly using the below command. One thing to note is the link opens up in your default browser that you have set in your computer.
Start [URL of website] Eg: start http://www.crazyprorgammer.com
Entire Source Code
More Fun to TryI’ve used simple start commands in the above batch file program, but I’d like you to try out all the flags and switches and test them.
在批处理文件中启动命令
句法 开始[“标题”] [/ D路径] [/ I] [指定窗口状态的标志] [指定程序的存储空间的标志] [优先级标志] [/ NODE <NUMA节点>] [/ AFFINITY <十六进制亲和力掩码> ] [/ WAIT] [/ B] [命令/程序] [参数]
当我们需要启动新程序窗口或命令提示符时,“启动”命令会很有帮助。 可以在我们的程序中使用此启动命令来启动所有运行命令。 您可以看到start命令的语法非常大,但是很容易理解。 让我们分解一下,一次处理一次。
启动我们仅使用启动命令,不带任何参数或标志来在当前目录中启动新的命令提示符。
标题第一部分是“标题”。 它用引号指定,标题用于在窗口标题栏中显示指定的标题。 如果您还记得的话,我们已经在上一篇文章中进行了讨论。
例如:启动“我的贝壳”
上面的命令将启动一个名为“ My shell”的新命令提示符。
路径当您仅使用start命令启动新命令提示符时,路径与标志/ D一起使用以指定启动目录。 例如:start / d“ C:Userscrazyprogrammer”
使用上面指定的启动目录启动新的命令提示符
I该标志指示新环境将是最初传递给命令提示符的原始环境,而不是程序的当前执行环境。
窗口状态我们有两个标志来指定启动命令正在启动的窗口的状态。 '/ MIN'以最小化状态启动新窗口,而'/ MAX'标志指定窗口处于最大化状态。'/ max'和'/ min'开关打开最大化或最小化的新命令提示符如果未指定应用程序,则基于使用的标志。
例如:start / max mspaint
此命令将打开Windows状态最大化的MSPaint应用程序。 您可以类似地尝试最小切换。
B '/ b'标志用于在同一控制台上启动应用程序,而无需创建新窗口。 这类似于同时具有两个命令提示符。 一旦启动新命令提示符,键入exit将终止当前提示符并打开前一个提示符,但不会完全关闭该窗口。 除非应用程序启用了^ C处理,否则已打开的应用程序将忽略^ C处理,以中断应用程序^ Break是唯一的方法。
内存空间接下来是用于指定程序的内存空间的开关。 通常需要指定Windows程序的存储空间。 '/ SEPARATE开关在单独的内存空间中启动一个16位Windows程序。 '/ SHARED'开关为所有程序分配共享内存。
例如:开始/共享写入
上面的命令用于在共享内存空间中打开写字板。
优先级切换如果您熟悉操作系统中的多线程和并发处理,则可能已经知道,分配CPU的任何进程基本上都有4个优先级。 '/ LOW'开关启动一个应用程序并将其置于IDLE优先级类别中。 '/ NORMAL'开关启动应用程序并为其分配NORMAL优先级。 使用“ / HIGH”开关或需要紧急分配CPU的应用程序,因此将其置于HIGH优先级等级。 “ / REALTIME”开关通过将其优先级设置为REALTIME优先级类别来打开应用程序。 同样,我们也有'/ abovenormal'和'/ belownormal'开关。
例如:启动/ belownormal mshearts.exe
上面的命令打开优先级低于正常级别的“心”游戏,其优先级介于正常和空闲之间。
批处理程序可轻松打开您喜欢的程序和网站如果您不是Windows的语音用户,并且希望像专业人士一样使用PC,则以下程序可以为您提供帮助。 创建以下程序的基本思想是,我们经常使用不同的快捷方式和程序。 每当我们需要它们时,我们都需要去搜索它们,或者我们需要打开开始菜单来获取频繁列出的程序。 代替这样做,我们可以创建一个批处理文件以将所有快捷方式放在一个位置。
在进入程序之前,我想提到一下,在入门课程中我给出了运行命令的列表,这可能会对您有所帮助。 该程序非常简单易懂,我在这里使用了简单的启动命令,没有任何开关。 您知道如何运行以下代码。 复制它,将其另存为shortcuts.bat,然后双击以执行它。 您可以在命令提示符下看到以列表形式显示的选项,如下所示。
我已经使用简单的echo命令显示了所有选项。 为了收集用户的选择,我使用了/ p标志为set命令声明了一个变量
设置/ p选择=
然后,使用一系列的if条件检查器,将程序放置在各个部分中,如下所示。
如果%choice%=== 1( 启动appwiz.cpl ) 如果%choice%== 2( 启动控件 )
太棒了,转到创建自己的快捷方式。 我想在这里提一件事。 该程序使您可以使用以下命令直接打开自己喜欢的网站。 要注意的一件事是,该链接会在您在计算机中设置的默认浏览器中打开。
开始[网站网址] 例如:开始http://www.crazyprorgammer.com
整个源代码
尝试更多乐趣我在上面的 批处理文件程序中使用了简单的启动命令,但是我希望您尝试所有的标志和开关并对其进行测试。
翻译自: https://www.thecrazyprogrammer.com/2015/07/create-your-own-shortcuts-using-batch-file.html