简体   繁体   English

我可以编写的最简单的程序来调用批处理脚本?

[英]What is the simplest program I can write to invoke a batch script?

It is very stupid that windows will not let you add batch files to your quick launch or whatever they call in in windows 7. That bar across the bar, i can attach firefox there, command prompt, even paint (my favorite), but not a batch file. Windows不允许您将批处理文件添加到快速启动中或在Windows 7中调用它们,这是非常愚蠢的。在该条上的那个条,我可以在其中附加Firefox,命令提示符,甚至绘制(我最喜欢的),但不能批处理文件。 I can "pin" it to another program, which is just weird. 我可以将它“固定”到另一个程序,这很奇怪。 I want it to standalone, the batch file does enough work by itself. 我希望它独立运行,批处理文件本身可以完成足够的工作。

So lets say i have batch file. 所以可以说我有批处理文件。 What is the simplest executable program I can write to invoke said script. 我可以编写最简单的可执行程序来调用所述脚本。 Then I can finally pin all my useful batch files on that quick-jump-pin-bar. 然后,我终于可以将所有有用的批处理文件固定在该quick-jump-pin-bar上。

If I remember right, you can do this by first pinning a shortcut to CMD.exe to the taskbar. 如果我没记错的话,您可以先将CMD.exe的快捷方式固定在任务栏上,然后再执行此操作。 Then edit the command, and change CMD.exe to CMD.exe /c MyBatchFile.bat . 然后编辑命令,并将CMD.exe更改为CMD.exe /c MyBatchFile.bat I believe this will execute the batch file. 我相信这将执行批处理文件。

Since you can only pin one cmd, here's an alternative, assuming you have the .NET framework installed - a very simple C# application: 由于您只能固定一个cmd,因此假设您已安装.NET Framework,这是一个替代方法-一个非常简单的C#应用​​程序:

Populate a textfile with the following contents: 用以下内容填充文本文件:

class Program {
  static void Main() {
    System.Diagnostics.Process.Start(@"c:\test.bat");
  }
}

where Program is the name of the executable you want to create, and c:\\test.bat is the full path to the batch file. 其中Program是您要创建的可执行文件的名称, c:\\test.bat是批处理文件的完整路径。 Save the file as Program.cs . 将文件另存为Program.cs Execute the following from the command line: 从命令行执行以下命令:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe Program.cs

You can replace 2.0.50727 with whatever directory exists on your machine - might be 1.1.something or 3.5 or 4.0.something - it's all the same for this scenario. 您可以用计算机上存在的任何目录替换2.0.50727可能是1.1.something或3.5或4.0.something-在这种情况下都相同。

This will generate Program.exe. 这将生成Program.exe。 You can put that exe file wherever you want, and pin that executable to the taskbar. 您可以将该exe文件放在任何位置,然后将该可执行文件固定到任务栏。 You can discard the .cs file once you're done making your executables. 制作完可执行文件后,就可以丢弃.cs文件。

Kind of a crappy solution, but it should work, assuming you don't find anything better. 有点糟糕的解决方案,但是如果您找不到更好的解决方案,它应该可以工作。 And if you don't have the .NET framework (which I'm not sure is even possible in Windows 7), you can install it pretty easily. 而且,如果您没有.NET框架(我不确定在Windows 7中甚至无法实现),则可以很轻松地安装它。

The easiest way is to create a folder, put your batch files in it, and pin the folder to the menu bar :D 最简单的方法是创建一个文件夹,将批处理文件放入其中,然后将该文件夹固定到菜单栏:D

You can also write a startup script, so the batch file will be executed on startup, but I don't know if you want to run those scripts on every bootup... You can also add the command prompt to the bar, and edit the startup path.. 您还可以编写启动脚本,因此批处理文件将在启动时执行,但是我不知道是否要在每次启动时都运行这些脚本...您还可以将命令提示符添加到栏中,然后进行编辑启动路径

使用命令打开CMD.exe

cmd.exe /c "myscript.bat"

As a sort of workaround you could use the following trick. 作为一种解决方法,您可以使用以下技巧。 Pin an arbitrary application to the task bar, Shift+right click on the pinned icon, select Properties, change 'Target' and 'Start in' accordingly. 将任意应用程序固定到任务栏,按住Shift并右键单击固定的图标,选择“属性”,相应地更改“目标”和“开始于”。 Rename it too if you like. 如果愿意,也可以重命名。

You can pin more than one .bat file using this technique. 您可以使用此技术固定多个.bat文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我启动一个程序的地方编写批处理文件,当该程序完成或关闭时,启动另一个程序 - How Can I Write a Batch File Where I Start one Program and When that Program Finishes or Closes, Start Another 如何在输出重定向中使用vbscript变量从批处理脚本写入配置文件 - How can I write a config file from batch script using vbscript variables in output redirect 如何使用 Windows 批处理脚本将空 ASCII 字符 (nul) 写入文件? - How can I write a null ASCII character (nul) to a file with a Windows batch script? Windows 批处理脚本 - %%i 是什么意思? - Windows Batch script - what does %%i mean? 以二进制模式写入标准输出的最简单方法是什么? - What is the simplest way to write to stdout in binary mode? 我如何用其他方式写它? (批量) - How i can write it in a different way? (batch) 如何编写可以每天运行一个进程的Windows批处理脚本 - How to write a windows batch script that can run a process everyday 如何检查命名程序是否在批处理脚本中运行? - How would I check if a named program is running in a batch script? 我可以在 Windows 中将 Sass 与批处理脚本一起使用吗 - Can I use Sass with a batch script in Windows 如何修复 thix 批处理脚本 - How can i fix thix batch script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM