I'm trying to write a wrapper to help our customers restore a SQL Server database. By default SQL Server runs as user Network Service which has very limited permissions. Our customers are sometimes confused that they can't just point to a backup file in any location and restore it.
I want to copy the file from the location they choose to a temp location that SQL Server can access but I'm having a hard time finding a location. I can't just call Path.GetTempPath() because that gives me the user's temp which SQL Server can't access.
Is there a folder I can retrieve that will always work?
The temp folder for the Network Service account is located here:
%Windir%\ServiceProfiles\NetworkService\AppData\Local\Temp
On Windows XP/2003 the network service profile is located in the general user profile directory. On a German machine it is here:
C:\Dokumente und Einstellungen\NetworkService\Lokale Einstellungen\Temp
On an English computer it would be here:
C:\Documents and Settings\NetworkService\Local Settings\Temp
You can find the path to the profile on all Windows versions by querying this registry value:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20\ProfileImagePath
That does not give you the localized name of "Local Settings" on XP/2003, though.
By default, Administrators can write to the network service profile. Using it's temp folder for your purpose should be perfectly OK.
On Windows Vista and above
System Account (NT AUTHORITY\SYSTEM
)C:\Windows\TEMP
Network Service (NT AUTHORITY\NETWORK SERVICE
)
C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp
Local Service (NT AUTHORITY\LOCAL SERVICE
)
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With