windows 查找用户网络服务的临时文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5420898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find temp folder for user Network Service?
提问by Kevin Gale
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.
我正在尝试编写一个包装器来帮助我们的客户恢复 SQL Server 数据库。默认情况下,SQL Server 以具有非常有限权限的用户网络服务身份运行。我们的客户有时会感到困惑,他们不能只是指向任何位置的备份文件并恢复它。
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.
我想将文件从他们选择的位置复制到 SQL Server 可以访问的临时位置,但我很难找到位置。我不能只调用 Path.GetTempPath() 因为这给了我 SQL Server 无法访问的用户临时值。
Is there a folder I can retrieve that will always work?
是否有一个我可以检索的文件夹将始终有效?
回答by Helge Klein
The temp folder for the Network Service account is located here:
网络服务帐户的临时文件夹位于此处:
%Windir%\ServiceProfiles\NetworkService\AppData\Local\Temp
%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:
在 Windows XP/2003 上,网络服务配置文件位于一般用户配置文件目录中。在德国机器上,它在这里:
C:\Dokumente und Einstellungen\NetworkService\Lokale Einstellungen\Temp
C:\Dokumente 和 Einstellungen\NetworkService\Lokale Einstellungen\Temp
On an English computer it would be here:
在英语计算机上,它会在这里:
C:\Documents and Settings\NetworkService\Local Settings\Temp
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:
您可以通过查询此注册表值找到所有 Windows 版本上的配置文件的路径:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20\ProfileImagePath
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.
但是,这不会为您提供 XP/2003 上“本地设置”的本地化名称。
By default, Administrators can write to the network service profile. Using it's temp folder for your purpose should be perfectly OK.
默认情况下,管理员可以写入网络服务配置文件。出于您的目的使用它的临时文件夹应该是完全可以的。
回答by Kishore A
On Windows Vista and above
在 Windows Vista 及更高版本上
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
系统帐号 (
NT AUTHORITY\SYSTEM
)C:\Windows\TEMP
网络服务 (
NT AUTHORITY\NETWORK SERVICE
)C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp
本地服务 (
NT AUTHORITY\LOCAL SERVICE
)C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
回答by Justin Dearing
Why not just give NETWORK_SERVICE permission to a specific folder and tell the users to place the backup files there?
为什么不给特定文件夹的 NETWORK_SERVICE 权限并告诉用户将备份文件放在那里?
Or just run:
或者只是运行:
BACKUP DATABASE [master] TO DISK='master.bak'
GO
from SSMS and see where the file gets written to.
从 SSMS 并查看文件写入的位置。