windows 使用 invisible.vbs 在后台运行 BAT 文件,但如何停止它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5559081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running a BAT file in background with invisible.vbs, but how to stop it?
提问by 2rs2ts
I'm using a solution like the one mentioned here run bat file in backgroundbut the bat file in question runs a Bitcoin GPU miner in the background. Sometimes I want to stop the miner, but since I am trying to run it invisibly (because I don't want it in my taskbar) I can't stop the process. I can't even find it in my process manager (no cmd.exe or conhost.exe). [I'm not even sure it's running.] Any help?
我正在使用像这里提到的那样的解决方案在后台运行 bat 文件,但有问题的bat 文件在后台运行比特币 GPU 矿工。有时我想停止矿工,但由于我试图在不可见的情况下运行它(因为我不希望它出现在我的任务栏中)我无法停止这个过程。我什至无法在我的进程管理器中找到它(没有 cmd.exe 或 conhost.exe)。[我什至不确定它是否正在运行。] 有什么帮助吗?
edit: It is most definitely running; opening the process with a window shows that the miner was running at half capacity, which in the past indicated the miner was open twice.
编辑:它肯定在运行;用窗口打开进程显示矿工以一半的能力运行,这在过去表明矿工打开了两次。
edit2: here are the contents of the batch files, if it helps.
edit2:这里是批处理文件的内容,如果有帮助的话。
batch file I run to start everything:
我运行的批处理文件以启动一切:
wscript.exe "D:\Desktop\invisible.vbs" "C:\Program Files (x86)\Bitcoin\DiabloMiner\bpm.bat"
bpm.bat:
bpm.bat:
cd "C:\Program Files (x86)\Bitcoin\DiabloMiner"
java -cp target\libs\*;target\DiabloMiner-0.0.1-SNAPSHOT.jar -Djava.library.path=target\libs\natives\windows com.diablominer.DiabloMiner.DiabloMiner -u <username> -p <password> -o <pool> -p 8332 -w 64 -f 1000
invisible.vbs:
invisible.vbs:
set args = WScript.Arguments
num = args.Count
if num = 0 then
WScript.Echo "Usage: [CScript | WScript] invis.vbs aScript.bat <some script arguments>"
WScript.Quit 1
end if
sargs = ""
if num > 1 then
sargs = " "
for k = 1 to num - 1
anArg = args.Item(k)
sargs = sargs & anArg & " "
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
采纳答案by Conrad Frix
Without seeing the contents of the batch my guess is the CMD.exe runs your batch which launches your bitcoin process and then ends. This would explain why you're not seeing CMD.exe.
在没有看到批处理内容的情况下,我的猜测是 CMD.exe 运行您的批处理,它启动您的比特币进程然后结束。这将解释为什么您没有看到 CMD.exe。
If you want to see an example when you would see cmd.exe you can create a batch that never ends like so.
如果您想在看到 cmd.exe 时看到一个示例,您可以创建一个永远不会像这样结束的批处理。
:TOP
REM FOO
GoTo TOP
Then run inivisible.vbs with this batch and you'll see the cmd.exe in your task. If you use process explorer you'll be able to see the batchfile's name in the command line for the image. Which would look something like this
然后使用此批处理运行 inivisible.vbs,您将在任务中看到 cmd.exe。如果您使用进程资源管理器,您将能够在图像的命令行中看到批处理文件的名称。看起来像这样
`cmd /c ""C:\Whaterver\Looptest.bat" "
`cmd /c ""C:\Whaterver\Looptest.bat" "
UPDATE
更新
As Harry Steinhilber already pointed out the process will be java.exe
正如 Harry Steinhilber 已经指出的那样,该进程将是 java.exe
If you run process explorer and select the Java.Exe you should see this in the command prompt
如果您运行进程资源管理器并选择 Java.Exe,您应该会在命令提示符中看到它
java -cp target\libs\*;target\DiabloMiner-0.0.1-SNAPSHOT.jar -Djava.library.path=target\libs\natives\windows com.diablominer.DiabloMiner.DiabloMiner -u <username> -p <password> -o <pool> -p 8332 -w 64 -f 1000
java -cp target\libs\*;target\DiabloMiner-0.0.1-SNAPSHOT.jar -Djava.library.path=target\libs\natives\windows com.diablominer.DiabloMiner.DiabloMiner -u <username> -p <password> -o <pool> -p 8332 -w 64 -f 1000
This will allow you to identify the DataMiner from other java applcations (if any) that you are running.
这将允许您从正在运行的其他 Java 应用程序(如果有)中识别 DataMiner。
回答by Bob
You can use VBScript.
您可以使用 VBScript。
set shell=createobject("wscript.shell")
dim cmdline
cmdline="C:\path\to\yourprogram.jar" ' HERE
set wmi=getobject("winmgmts:{impersonationLevel=impersonate}!\"&shell.expandenvironmentstrings("%computername%")&"\root\cimv2")
for each process in wmi.instancesof("Win32_process")
if process.name="java.exe" and instr(process.commandline,cmdline)>0 then
process.terminate
end if
next
Sorry about the long line. Change the text where it says HERE to the location of your jar file and it will terminate it.
很抱歉排长队。将此处显示的文本更改为 jar 文件的位置,它将终止它。