<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

VB Scripts and UAC elevation

Published on
3,560 Points
560 Views
Last Modified:
Vikas Bhat
I have 10 years of experience as an IT Operations & Services Manager. I am expert in  IT Operations & IT Infrastructure
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
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
1. without using the Command Prompt?
2. without user being admin on machine?
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.
Scenario in my organization
We have intranet site in our organization with downloads page for installation of any software’s for users.
Downloads page has a link to .vbs script which installs the software from local available repository when users click on the link
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.
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 SCSserver,MapPath,oWshShell
Dim strArgs, strAdminUser, strAdminPass
Dim objFSO, wshNetwork, strComputer, objShell, strCommand
Set objFSO = WScript.CreateObject(“Scripting.FileSystemObject”)
Set wshNetwork = WScript.CreateObject(“WScript.Network”)
Set objShell = WScript.CreateObject(“WScript.Shell”)
‘Enter your domain admin user id/password or account with admin privelliges on your organisation machines
strAdminUser = “domain\userid”
strAdminPass = “password”
Dim WSHShell
Dim objNTInfo
Dim GetComputerName
Set objNTInfo = CreateObject(“WinNTSystemInfo”)
GetComputerName = lcase(objNTInfo.ComputerName)
Set WSHShell = WScript.CreateObject(“WScript.Shell”)
If WScript.Arguments.Count < 1 Then
Call Normal_User_Commands
ElseIf WScript.Arguments(0) = “AsAdmin” Then
Call Admin_User_Commands
Else
MsgBox “Unknown Argument received”
End If
Sub Normal_User_Commands
‘MsgBox “Running as initiating user”
strComputer = GetComputerName
‘Download psexec.exe and copy it on network as we are using 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”””
objShell.Run strCommand, 0, True
End Sub
Sub Admin_User_Commands
‘Now running as Administrator on the target machine
‘MsgBox “Running as Admin”
strCommand = “notepad.exe”
objShell.Run strCommand, 0, True
End Sub
********************************************************************
0
Comment
Author:Vikas Bhat
0 Comments

Featured Post

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Join & Write a Comment

If you, like me, have a dislike for using Online Subscription anti-spam services, then this video series is for you. I have an inherent dislike of leaving decisions such as what is and what isn't spamming to other people or services for me and insis…
This is Part-2 of Learning to use the Power of Mailwasher Pro so if you haven't watched Part-1 yet, I urge you to do so before watching this video. Click this link to watch Part-1 (https://www.experts-exchange.com/videos/56638/Learn-to-use-the-POWER…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month