[英]C# Temp Folder with session IDs
I have an application that target .NET Framework 4.8.我有一个针对 .NET Framework 4.8 的应用程序。 When using
%temp%
in File Explorer on a remote desktop machine I go to a path similar like this在远程桌面计算机上的文件资源管理器中使用
%temp%
时,我会转到类似这样的路径
C:\Users\UserName\Local\Temp\6
where 6 is the session ID. C:\Users\UserName\Local\Temp\6
其中 6 是会话 ID。
My problem is that System.IO.Path.GetTempPath()
method returns this value without the session ID.我的问题是
System.IO.Path.GetTempPath()
方法返回此值而没有会话 ID。 In .NET 6 however it does return the value with the session ID.然而,在 .NET 6 中,它确实返回带有会话 ID 的值。
Upgrading the project to .NET 6 is currently out of the question so I was wondering how else I could get around this?将项目升级到 .NET 6 目前是不可能的,所以我想知道我还能如何解决这个问题?
My proposed solution is to determine if in a remote session using我提出的解决方案是确定是否在远程会话中使用
[DllImport("user32")]
static extern bool GetSystemMetric(int indeX);
const int SM_REMOTESESSION = 0x1000;
var isRemoteSession = GetSystemMetrics(SM_REMOTESESSION);
and then I can combine the two using Path.Combine()
然后我可以使用
Path.Combine()
将两者结合起来
Is there any better solutions out there?有没有更好的解决方案?
I don't have a remote machine to test out but I have used Environment.ExpandEnvironmentVariables to get full paths for strings containing path tokens.我没有要测试的远程机器,但我使用Environment.ExpandEnvironmentVariables来获取包含路径标记的字符串的完整路径。
See if that works for you.看看这是否适合你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.