我不想只从 java 调用批处理文件,我希望代码在 java 中。
到目前为止我有这个但是我的批处理文件有很多代码并且不接受它。
public static void main(String[] args) {
final String dosCommand = "cmd /c dir /s";
final String location = "C:\\WINDOWS";
try {
final Process process = Runtime.getRuntime().exec(dosCommand + " " + location);
final InputStream in = process.getInputStream();
int ch;
while((ch = in.read()) != -1) {
System.out.print((char)ch);
}
} catch (IOException e) {
e.printStackTrace();
}
}
我想在我的 java 类中添加的批处理代码示例。我不会在课堂上添加@echo,除非有人告诉我需要。
@echo off
rundll32 wbemupgd, UpgradeRepository
NET USE Q: \\Somenetworkpath\ /PERSISTENT:NO
Q:
CD \DeskTop\Troubleshoot\
COPY subinacl.msi "C:\Documents and Settings\%USERNAME%\Desktop"
C:
MSIEXEC.EXE /i "\Documents and Settings\%USERNAME%\Desktop\subinacl.msi" /qn
DEL /Q "C:\Documents and Settings\%USERNAME%\Desktop\subinacl.msi"
C:
CD \Program Files\Windows Resource Kits\Tools\
SUBINACL /SUBKEYREG HKEY_LOCAL_MACHINE /GRANT=Administrators=F
SUBINACL /SUBKEYREG HKEY_CURRENT_USER /GRANT=Administrators=F
SUBINACL /SUBKEYREG HKEY_CLASSES_ROOT /GRANT=Administrators=F
SUBINACL /SUBDIRECTORIES %SystemDrive% /GRANT=Administrators=F
SUBINACL /SUBKEYREG HKEY_LOCAL_MACHINE /GRANT=System=F
SUBINACL /SUBKEYREG HKEY_CURRENT_USER /GRANT=System=F
SUBINACL /SUBKEYREG HKEY_CLASSES_ROOT /GRANT=System=F
SUBINACL /SUBDIRECTORIES %SystemDrive% /GRANT=System=F