系统变量%sessionname%会返回Console(如果是本地)或RDP*(如果是远程)。isRDP = [System.Environment] .GetEnvironmentVariable("SESSIONNAME").StartsWith("RDP-")