[英]Is there a Windows equivalent to $SHLVL?
我最近运行了一个在其中运行“ cmd”的3rd party脚本,从而增加了我的cmd窗口的嵌套深度(这使我的历史记录和DOSKey宏在此过程中不可用)。 所以我想知道是否有等效的$ SHLVL或其他方法来确定这种情况? 我想我可以向上箭头查看我的历史记录是否仍然存在,但是总有一天我可能需要脚本中的内容。
当我查看“ set”的输出时,似乎没有什么不同。 谢谢!
编辑更改代码以列出PID。
编辑2更改代码以将级别输出为%errorlevel%
请参阅https://docs.microsoft.com/zh-cn/windows/console/getconsoleprocesslist
CountConsoleProcess.vb
imports System.Runtime.InteropServices
Public Module MyApplication
Public Declare Function GetConsoleProcessList Lib "Kernel32" (ByRef ProcessList as Integer, ByVal Count as Integer) As Integer
Public Sub Main ()
Dim ProcessList(0 To 9) As Integer
Dim Count As Integer
Dim Ret As Integer
Dim x as Integer
Dim ColItems as Object
Dim objWMIService As Object
objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Count = 10
'subtract one to account for this program
Ret = GetConsoleProcessList(ProcessList(0), 10) - 1
Console.Writeline("Level = " & Ret)
For x = Ret to 1 step -1
colItems = objWMIService.ExecQuery("Select * From Win32_Process where ProcessID=" & ProcessList(x))
For Each objItem in colItems
Console.writeline("PID : " & objItem.ProcessID & " Command line : " & objItem.CommandLine)
Next
Next
Environment.ExitCode = Ret
End Sub
End Module
CountConsoleProcess.bat
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\CountConsoleProcess.vb" /debug:full /out:"%~dp0\CountConsoleProcess.exe" /target:exe
pause
ConsoleTest.Bat
REM Showing error level
"C:\Users\User\Desktop\ConsoleTest.bat"
Echo %errorlevel%
pause
并使用(在执行cmd /k
,它们将运行两个CMD)。 第一个是当前的PID。
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Windows\system32>cmd /k echo hello world
hello world
C:\Windows\system32>"C:\Users\User\Desktop\ConsoleTest.bat"
C:\Windows\system32>"C:\Users\User\Desktop\Console.exe"
Level = 2
PID : 6848 Command line : "C:\Windows\System32\cmd.exe"
PID : 7824 Command line : cmd /k echo hello world
C:\Windows\system32>Echo 2
2
C:\Windows\system32>
并将当前文件夹添加到路径
_AddThisFolderToPath.bat
Setx path "%path%;%~dp0"
Pause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.