简体   繁体   English

向用户授予本地管理员执行VBS脚本的权限

[英]Granting local adminstrator permissions to a user for executing a VBS script

I am currently working on a LogOn VBScript which has to copy files from one destination to another. 我目前正在使用LogOn VBScript,它必须将文件从一个目标复制到另一个目标。 Before I start to copy I have to set 2 registry keys. 在开始复制之前,我必须设置2个注册表项。 One of them is in HKEY_CURRENT_USER and the other in HKEY_LOCAL_MACHINE. 其中一个在HKEY_CURRENT_USER中,另一个在HKEY_LOCAL_MACHINE中。 I can write the registry key into HKEY_CURRENT_USER, but not into HKEY_LOCAL_MACHINE because of the permissions of the users. 由于用户的权限,我可以将注册表项写入HKEY_CURRENT_USER,但不能写入HKEY_LOCAL_MACHINE。 Next thing is that I have to read from a mapped shared folder (eg mapped to 'Z:'). 接下来的事情是,我必须从映射的共享文件夹中读取(例如,映射到“ Z:”)。 If I run the script locally on my computer, I can get the mapped shared folder like this: 如果我在计算机上本地运行脚本,则可以获取映射的共享文件夹,如下所示:

Set colDrives = objWMIService.ExecQuery _ 
("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'Z:'")

But when I'm running the script as admin I can't get the mapped folder, but I can write to the registry. 但是,当我以admin身份运行脚本时,无法获取映射的文件夹,但可以写入注册表。 Is there any way I can do both tasks with one script? 有什么办法可以用一个脚本同时完成两个任务? I can't change the permissions and one requirement is that everything has to be done with one script. 我无法更改权限,其中一项要求是所有操作都必须使用一个脚本来完成。

Thanks in advance! 提前致谢!

Drives are mapped to user tokens. 驱动器映射到用户令牌。 Limited and Admin are different tokens. Limited和Admin是不同的令牌。 So Z: won't be available if run as admin. 因此Z:如果以管理员身份运行将不可用。 So use unc \\\\servername\\sharename\\folder\\file.ext . 因此,使用unc \\\\servername\\sharename\\folder\\file.ext

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM