IfYouSaySo
Well-known member
Ok. I'm about to go out of my mind here. I want to throw my computer out my office window. But I don't have a window in my office. Here's the problem.
System.IO.Path.GetTempFileName() it seems determines the temp directory from System.IO.GetTempPath(), which in turn determines the temp location based on the TMP environment variable.
When you impersonate a user, the environment variables are not updated, which means you can't call GetTempFileName() without getting unauthorized access exception--because it points to some other user's temp area. But I don't let that stop me. I write a wrapper around GetTempFileName, and modify the environment variable on the fly to give me a value that I want. If I point this environment variable to the impersonated user's standard temp area (C:\Documents and settings\username\Local settings\Temp) everything works as expected.
BUT, this temp file needs to be accessible from a few different machines (please don't get caught up in why this needs to be the case--I'm writing some wrapper code around the MS compute cluster API, and I need to specify a standard output file location, and the compute cluster job process could run on any of the valid compute nodes in the cluster), so I set TMP to something like:
\\machinename\temp_root\username
Where machinename is the local machine name, temp_root is a share that I set up, and username is a subdirectory under temp_root where the impersonation user has full control access.
Now, after this, the call to GetTempFileName() is throwing an UnauthorizedAccessException. I have basically made everything WIDE OPEN at this point. The share is wide open, the subfolder is wide open, everything.
I logged in as the user on a different machine on the network, and accessed the share remotely via windows explorer, and created a file in the location where I supposedly do not have access.
System.IO.Path.GetTempFileName() it seems determines the temp directory from System.IO.GetTempPath(), which in turn determines the temp location based on the TMP environment variable.
When you impersonate a user, the environment variables are not updated, which means you can't call GetTempFileName() without getting unauthorized access exception--because it points to some other user's temp area. But I don't let that stop me. I write a wrapper around GetTempFileName, and modify the environment variable on the fly to give me a value that I want. If I point this environment variable to the impersonated user's standard temp area (C:\Documents and settings\username\Local settings\Temp) everything works as expected.
BUT, this temp file needs to be accessible from a few different machines (please don't get caught up in why this needs to be the case--I'm writing some wrapper code around the MS compute cluster API, and I need to specify a standard output file location, and the compute cluster job process could run on any of the valid compute nodes in the cluster), so I set TMP to something like:
\\machinename\temp_root\username
Where machinename is the local machine name, temp_root is a share that I set up, and username is a subdirectory under temp_root where the impersonation user has full control access.
Now, after this, the call to GetTempFileName() is throwing an UnauthorizedAccessException. I have basically made everything WIDE OPEN at this point. The share is wide open, the subfolder is wide open, everything.
I logged in as the user on a different machine on the network, and accessed the share remotely via windows explorer, and created a file in the location where I supposedly do not have access.