vb uac 拖放
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script under elevated privileges/admin privileges
在Windows 7中启用了用户帐户控制(UAC)后,需要打开提升的命令提示符才能在管理特权下运行脚本。 尽管提升的命令提示符完成了任务,但问题是如何在提升的特权/管理员特权下作为脚本运行
1. without using the Command Prompt?
1.不使用命令提示符?
2. without user being admin on machine?
2.没有用户在计算机上被管理员?
We can achieve the same by GPO which can deploy application etc. using system account but it doesn’t solve the purpose where only selected users need to install applications with no admin rights on machine.
通过GPO,我们可以使用系统帐户部署应用程序等来达到相同目的,但是它不能解决仅选定用户需要在计算机上没有管理员权限的情况下安装应用程序的目的。
Scenario in my organization
我组织中的方案
We have intranet site in our organization with downloads page for installation of any software’s for users.
我们在组织中拥有Intranet网站,该网站带有“下载”页面,用于为用户安装任何软件。
Downloads page has a link to .vbs script which installs the software from local available repository when users click on the link
下载页面上有一个指向.vbs脚本的链接,当用户单击该链接时,该脚本将从本地可用存储库中安装软件。
Problem is that users with no admin rights on local machine cannot install software especially in windows 7 as most of our users have been migrated to windows 7 with no administrator rights.
问题是,在本地计算机上没有管理员权限的用户无法安装软件,尤其是在Windows 7中,因为我们的大多数用户已迁移到没有管理员权限的Windows 7。
Solution:
解:
We created a script which can install the software on any machine with no admin privileges
我们创建了一个脚本,该脚本可以在没有管理员权限的情况下将软件安装在任何计算机上
We encoded the final script to protect from users
我们对最终脚本进行了编码,以防止受到用户的攻击
Below is the script:
下面是脚本:
**************************
************************** ********** ********** ********** **********
Option Explicit
显式期权
Dim MyArr, i, IPaddress, tstr, Subnet2, Subnet3
Dim MyArr,i,IPaddress,tstr,Subnet2,Subnet3
Dim SCSserver,MapPath,oWshShel
Dim SCSserver,MapPath,oWshShel 升
Dim strArgs, strAdminUser, strAdminPass
昏暗的strArgs,strAdminUser,strAdminPass
Dim objFSO, wshNetwork, strComputer, objShell, strCommand
昏暗的objFSO,wshNetwork,strComputer,objShell,strCommand
Set objFSO = WScript.CreateObject(“Scri
设置objFSO = WScript.CreateObject(“ Scri pting.File 系统对象 ct”)
Set wshNetwork = WScript.CreateObject(“WScr
设置wshNetwork = WScript.CreateObject(“ WScr ipt.Networ k”)
Set objShell = WScript.CreateObject(“WScr
设置objShell = WScript.CreateObject(“ WScr ipt.Shell” )
‘Enter your domain admin user id/password or account with admin privelliges on your organisation machines
'在您的组织机器上输入域管理员用户ID /密码或具有管理员权限的帐户
strAdminUser = “domain\userid”
strAdminUser =“域\用户ID”
strAdminPass = “password”
strAdminPass =“密码”
Dim WSHShell
昏暗的WSHShell
Dim objNTInfo
昏暗的objNTInfo
Dim GetComputerName
昏暗的GetComputerName
Set objNTInfo = CreateObject(“WinNTSystemI
设置objNTInfo = CreateObject(“ WinNTSystemI nfo”)
GetComputerName = lcase(objNTInfo.ComputerNa
GetComputerName = lcase(objNTInfo.ComputerNa 我)
Set WSHShell = WScript.CreateObject(“WScr
设置WSHShell = WScript.CreateObject(“ WScr ipt.Shell” )
If WScript.Arguments.Count < 1 Then
如果WScript.Arguments.Count <1那么
Call Normal_User_Commands
调用Normal_User_Commands
ElseIf WScript.Arguments(0) = “AsAdmin” Then
ElseIf WScript.Arguments(0)=“ AsAdmin”然后
Call Admin_User_Commands
呼叫Admin_User_Commands
Else
其他
MsgBox “Unknown Argument received”
MsgBox“收到未知参数”
End If
万一
Sub Normal_User_Commands
子Normal_User_Commands
‘MsgBox “Running as initiating user”
'MsgBox“作为初始用户运行”
strComputer = GetComputerName
strComputer = GetComputerName
‘Download psexec.exe and copy it on network as we are using psexec.exe
'下载psexec.exe并将其复制到网络上,就像我们使用psexec.exe一样
strCommand = “cmd /c <Path for psexec.exe> \\” & strComputer & ” -i -u ” & strAdminUser & ” -p ” & strAdminPass & ” wscript.exe <complete path for your script which installs application/software.vbs> “”AsAdmin”””
strCommand =“ cmd / c <psexec.exe的路径> \\”和strComputer&“ -i -u”&strAdminUser&“ -p”和strAdminPass&“ wscript.exe <安装应用程序/软件的脚本的完整路径.vbs>““ AsAdmin”””
objShell.Run strCommand, 0, True
objShell.Run strCommand,0,True
End Sub
结束子
Sub Admin_User_Commands
子Admin_User_Commands
‘Now running as Administrator on the target machine
'现在以管理员身份在目标计算机上运行
‘MsgBox “Running as Admin”
'MsgBox“以管理员身份运行”
strCommand = “notepad.exe”
strCommand =“ notepad.exe”
objShell.Run strCommand, 0, True
objShell.Run strCommand,0,True
End Sub
结束子
**************************
************************** ********** ********** ********** ********** **
翻译自: https://www.experts-exchange.com/articles/29406/VB-Scripts-and-UAC-elevation.html
vb uac 拖放