在C:\ Windows中创建一个文本文件作为另一个用户 [英] Create a Text File in C:\Windows as another user
问题描述
我在这里遇到了一个复杂的问题,我对如何进行感到困惑。以下是它的要点:
- 只对C:\ Windows文件夹具有读访问权限的客户端需要创建一个文件。 (c:\windows\sample.txt)
- 他们运行的应用程序,我希望它使用管理员帐户创建该文件。现在我正在运行一个Process.Start()来触发DOS命令来使用管理员帐户创建文件。
文件:c:\windows \ system32 \ cmd.exe命令:/ c copy nul c:\windows \ _sample.txt
- 在C:\ Windows目录中,您需要运行管理员。如果你是以另一个用户身份运行,则startinfo.Verb(Runas)不起作用。
是否有其他选项可以创建使用管理员帐户到我丢失的C:\ Windows文件夹的文件?
为什么要在C:\ Windows文件夹中做任何事情?这不是一个合法的地方,特别是如果你使用的是Windows 7.
请查看我过去在你可以使用的目录上的答案:
如何查找我的程序目录(可执行目录),
如何查找我的程序目录(当前目录, 特殊文件夹),
哪个更好:使用registery来存储设置或使用Settings类 [ ^ ]。
现在,您无法在运行时提升权限,当然,您无法通过系统管理提供比某些用户更多的权限;应用程序覆盖权限将完全失败其目的。相反,您可以创建一个嵌入应用程序清单以立即通过UAC对话框请求提升,而不需要用户使用以管理员身份运行:
http://msdn.microsoft.com/en-us/library/bb756929.aspx [ ^ ]。
如果您需要了解UAC,请参阅:
http://en.wikipedia.org/wiki / User_Account_Control [ ^ ],
http://technet.microsoft.com/en-us/library/ cc731416(WS.10).aspx [ ^ ],
http://technet2.microsoft.com/WindowsVista/en/library/00d04415-2b2f-422c -b70e-b18ff918c2811033.mspx?mfr = true [ ^ ],
http://technet.microsoft.com/en-us/library/cc731416(WS.10).aspx [ ^ ],
http://windows.microsoft.com/en-US/windows7/turn-用户帐户控制开启或关闭 [ ^ ]。
我会坚强永远不要让你反对关闭UAC。
这就是你正常以管理员身份运行的方式,作为普通用户:
http://4sysops.com/archives/vista%E2%80%99s-uac-8-ways-how-to-elevate-an-application-to-run-it-with-administrator-rights [ ^ ],
http://www.sevenforums.com/tutorials/11841-run-administrator.html [ ^ ]。
-SA
I have a complicated problem here and I'm stumped as to how to proceed. Here is the gist of it:
- Client, who only has read access to the C:\Windows folder needs to have a file created. (c:\windows\sample.txt)
- Application they run, I want it to create that file using an administrator account. Right now I'm running a Process.Start() to trigger a DOS command to create the file using the admin account.
File: c:\windows\system32\cmd.exe Command: /c copy nul c:\windows\sample.txt
- In C:\Windows directory you need have the Run As Administrator. startinfo.Verb("Runas") does not work if you are running as another user.
Is there another option to create a file using an admin account to the C:\Windows folder that I'm missing?
Why doing anything in C:\Windows folder? This is not a legitimate place, especially if you use Windows 7.
Please see my past answers on the directories you can work with:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders"),
which is better : use of registery in order to store setting or use of Settings class[^].
Now, you cannot elevate privilege during run time, and of course you cannot give more privilege than some user has by system administration; overriding privileges by application would totally defeat its purpose. Instead, you can create an embed the Application Manifest to request for elevation via the UAC dialog right away, not requiring a user to use "Run As Administrator":
http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].
If you need to understand UAC, please see:
http://en.wikipedia.org/wiki/User_Account_Control[^],
http://technet.microsoft.com/en-us/library/cc731416(WS.10).aspx[^],
http://technet2.microsoft.com/WindowsVista/en/library/00d04415-2b2f-422c-b70e-b18ff918c2811033.mspx?mfr=true[^],
http://technet.microsoft.com/en-us/library/cc731416(WS.10).aspx[^],
http://windows.microsoft.com/en-US/windows7/turn-user-account-control-on-or-off[^].
I would strongly warm you against turning UAC off, ever.
This is how you "normally" "Run as Administrator", as a regular user:
http://4sysops.com/archives/vista%E2%80%99s-uac-8-ways-how-to-elevate-an-application-to-run-it-with-administrator-rights[^],
http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].
—SA
这篇关于在C:\ Windows中创建一个文本文件作为另一个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!