Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find temp folder for user Network Service?

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?

like image 824
Kevin Gale Avatar asked Mar 24 '11 14:03

Kevin Gale


2 Answers

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.

like image 96
Helge Klein Avatar answered Oct 18 '22 17:10

Helge Klein


On Windows Vista and above

  1. System Account (NT AUTHORITY\SYSTEM)
    C:\Windows\TEMP

  2. Network Service (NT AUTHORITY\NETWORK SERVICE) C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp

  3. Local Service (NT AUTHORITY\LOCAL SERVICE) C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp

like image 27
Kishore A Avatar answered Oct 18 '22 17:10

Kishore A