在vb.net中编写文件 - 权限

发布于 2025-02-11 15:28:11 字数 758 浏览 1 评论 0原文

我有一个文件夹,我只希望管理员拥有权限为其写文本文件。

我需要在程序中写入文本文件并将其插入文件夹。我目前正在使用StreamWriter编写文件。它可以编写文件,因为我是管理员并且可以访问该文件夹。

我需要拥有它,以便所有使用可能无法访问该文件夹的程序的用户可以使用该程序,并且在需要时,请使用vb.net程序将其写入文件夹,但是如果他们尝试访问文件夹,则无法访问写或编辑任何内容。

我的想法是可以创建可以访问该文件夹的“应用程序用户”的位置。从应用程序编写文件时,该用户将以某种方式参考。不确定是否可能。

            Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("O:\*****\****\**\****\" + LPlant + LMove + "_" + Format(thisDay, "yyyyMMddhhmmss") + ".dat", True)
        file.WriteLine(LPlant + LMove + LMaterial + LQuantity + LLocation + LUnit + LPPOrderNum + LPONum + LPOItem + LBatchNum + LDocumentDT + LBadgeID + LSequenceNum)
        file.Close()

是否有人在VB.NET应用程序中做过这样的事情。

任何帮助都将不胜

感激

I have a folder that I only want Administrators having permissions to write text files to it.

I need to write text files in a program and insert it into the folder. I am currently using StreamWriter to write the files. It works for me to write the files because I am an administrator and have access to the folder.

I need to have it so all users using the program that may not have access to write to the folder can use the program, and when needed, use the vb.net program to write to the folder but if they try to access the folder they wont have access to write or edit anything in it.

My Idea's where to possibly create a 'Application User' that has access to the folder. This user would be somehow reference when writing the files from the application. Not sure if that is possible.

            Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("O:\*****\****\**\****\" + LPlant + LMove + "_" + Format(thisDay, "yyyyMMddhhmmss") + ".dat", True)
        file.WriteLine(LPlant + LMove + LMaterial + LQuantity + LLocation + LUnit + LPPOrderNum + LPONum + LPOItem + LBatchNum + LDocumentDT + LBadgeID + LSequenceNum)
        file.Close()

Has anyone done anything like this in a vb.net application.

Any help would be appreciated

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

够运 2025-02-18 15:28:11

抱歉,那行不通。用户X运行的程序只能执行用户X可以做的事情。 Windows上没有setUID功能

您可以通过将应用程序设计为经典Windows服务或例如本地运行的Web应用程序来解决此问题。该服务应用程序将使用具有必要权限的特殊用户帐户运行(即,将权限写入该目录)。您的最终用户将使用Web界面(在Web应用程序的情况下)或可以与您的特权服务通信的非特权应用程序(如果Windows Service)。

Sorry, that won't work. A program run by user X can only do what user X can do. There is no setuid functionality on Windows.

You can work around this issue by designing your application as a service, either a classic Windows Service or, for example, a locally running web application. That service application would run with a special user account that has the necessary permissions (i.e., write permissions to that directory). Your end users would use the web interface (in case of a web application) or a non-privileged application that can communicate with your privileged service (in case of a Windows service).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文