“cscript //NoLogo” 代表什么意思?

3
这是一个Java程序代码,运行记事本程序并粘贴存储在自身程序中的特定文本....
我想知道你是否能解释一下`String vbs`值,以及`File file`和`("cscript //NoLogo " + file.getPath())`在`Process p`中的含义。如果您慷慨的话,那么请解释一下整个代码。
我是Java初学者,不完全准确地说,但如果您想评分从0到10,我会给自己1.5/10。
import java.io.File;
import java.io.FileWriter;
import javax.swing.JTextField;

 public class PasteToNotepad {

   public static void main(String[] args) throws Exception {
     String text = "Some text for testing.";
     JTextField textField = new JTextField(text);
     textField.setSelectionStart(0);
     textField.setSelectionEnd(text.length() - 1);
     textField.copy();

     String vbs = ""
             + "Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
             + "WshShell.Run \"notepad\", 9\n"
             + "WScript.Sleep 500\n"
             + "WshShell.SendKeys \"^V\"";

     File file = File.createTempFile("PrintDialog", ".vbs");
     file.deleteOnExit();
     FileWriter fw = new java.io.FileWriter(file);
     fw.write(vbs);
     fw.close();
     Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
     p.waitFor();
   }
 }
2个回答

5

虽然这个问题主要不是关于cscript //NoLogo的,但是由于它的标题很好地适用于这个短语,所以我们也会详细回答。

我不确定为什么他们称其为“logo”,但从@MByD显示的内置帮助中,它确实就是你想象的那样。为了完整起见......

C:\prompt>cscript spam.js
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

C:\prompt>cscript //NoLogo spam.js

C:\prompt>

如果您正在管道输出并且不想要所有的Microsoft模板,请使用//Nologo

C:\prompt>cscript spam.js > out.txt

C:\prompt>more out.txt
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.


C:\prompt>cscript spam.js //NoLogo > out.txt

C:\prompt>more out.txt

C:\prompt>

(spam.js中有var spam = "spam";。)

哇,这是一个非常复杂的方式将文本输入到记事本中。我猜这更多是关于如何写入文件和从Java中执行命令的教学吧?


2

你需要做的基本上是:

  1. 创建一个包含脚本的字符串(String vbs = ...
  2. 将其写入文件中(File file = File...fw.close()
  3. 通过调用 cscript 在单独的进程中执行此脚本(Process p = Runtime.getRuntime().exec(...)

关于cscript //NoLogo,这与Java几乎没有任何关系,因为这是Windows命令:

C:\Documents and Settings\bsharet>cscript
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: CScript scriptname.extension [option...] [arguments...]

Options:
 //B         Batch mode: Suppresses script errors and prompts from displaying
 //D         Enable Active Debugging
 //E:engine  Use engine for executing script
 //H:CScript Changes the default script host to CScript.exe
 //H:WScript Changes the default script host to WScript.exe (default)
 //I         Interactive mode (default, opposite of //B)
 //Job:xxxx  Execute a WSF job
 //Logo      Display logo (default)
 //Nologo    Prevent logo display: No banner will be shown at execution time
 //S         Save current command line options for this user
 //T:nn      Time out in seconds:  Maximum time a script is permitted to run
 //X         Execute script in debugger
 //U         Use Unicode for redirected I/O from the console

那么这个程序(Notepad.exe)怎么运行,我该如何更改它呢? - Sarsur.A
该程序运行的是 cscript,而不是 notepad,然后由 cscript 执行的脚本运行了 notepad。如何更改它 - 这取决于您想要实现什么目标。 - MByD
假设我想运行位于“C:\Program Files\Windows Live\Messenger\msnmsgr.exe”中的Messenger。另外一个问题是,这段代码没有任何路径可见,但它如何运行记事本? - Sarsur.A
这是因为notepad.exe位于Windows路径中,再次强调,与Java无关,只是Windows系统相关。 - MByD
好的,最后一个问题你没有回答我,如果我想运行不在Windows路径中的其他东西,我应该在哪里设置路径?因为我尝试在这一行中将路径设置为记事本单词而不是(+“WshShell.Run \”notepad\”,9\n”)中的括号... - Sarsur.A
是的,我知道这个步骤,但很抱歉我正在尝试在任何没有设置此步骤的设备上运行此程序... - Sarsur.A

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接