如何通过批处理脚本测试用户的有效权限?
我需要在批处理脚本中测试特定用户(即不一定是当前用户)的有效权限,并据此采取行动(提供警告)。我想要一个可以调用的子例程来检查指定文件或目录的权限,以便我可以测试只有管理员才能访问的内容(从而警告授予的权限过高)并检查数据可以访问我的应用程序路径中的目录(否则权限太低)。我希望它能在 XP、2008 和 win7 上运行。
顺便说一句,我已经弄清楚如何解析“net localgroup Administrators”,但我认为这不足以满足我的需求。
I need to test the effective permissions of a specific user (i.e. not necessarily the current user) from within a batch script and take action (provide a warning) based on that. I'd like to have a subroutine I could call to check privileges against a specified file or directory so I could test that something only an administrator should be able to access (and thus warn that too high of permissions are granted) and check that data directories in my apps path can be accessed (otherwise too low of permissions). I'd like this to work in XP, 2008, and win7.
By the way, I have figured out how to parse "net localgroup Administrators", but I don't think this is sufficient for my needs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Jared,
根据您的需求,我认为通过简单的 copy 和 %errorlevel% 您就可以获得您想要的。
或者,要检查任何用户,请执行相同的操作,但使用 Windows 受保护的文件夹...
如果您需要测试其他用户,请尝试使用 runas 选项...
@Lizz
此脚本检查 Windows 版本,并提升临时文件以使用管理员权限运行特定文件。
注意:如果 yourFileNameAsAdmin.bat 使用文件的相对路径,请记住在文件开头启用扩展名和本地目录:
希望有帮助!...
作为附加相关信息...
使用命令 net 您可以获得有关用户和组的大量信息,并且您还可以与他们一起工作。
例如
NET USER
NET LOCALGROUP
@Jared,
For your needs, I think with a simple copy and %errorlevel% you can have what you want.
Or, to check for any user, do the same but with a windows protected folder...
If you need to test other user try with the runas option...
@Lizz
This script check windows version, and elevate a temporary file to run a specific one with ADMIN RIGHTS.
Note: If yourFileNameAsAdmin.bat use RELATIVE path to files, remember to enableextensions and the local dir at the beginning of the file:
Hope that helps!...
As adition related info...
With the command net you get a lot of info about users and goups, and also can you work with them.
e.g.
NET USER
NET LOCALGROUP