Install apps from password protected share using VBScript

VB Script

Let’s say you have a scenario where the user wants to install applications from a share, but he has to login first. Or there is another scenario where you set the application in SCCM to “Run as administrator” and that will be executed in the system context user,that means that even if the user is logged in and has access to the share, by running in SC this will fail.

If you make an install bundle script you will an error that the media cannot be found if the user is logged in.

By using VBScript you can silently map a network drive with the user credentials and install the applications from it.

' Core variable definitions ---------------------------------------------------
strComputer = "."
Set oSH = CreateObject("WScript.Shell")
Set NetworkObject = CreateObject("WScript.Network")

' Initialize server location, username, password ---------------------------------------------------

UserName = "Username"
Password = "Password"

'-----------------------Map network drive--------------------------------

NetworkObject.MapNetworkDrive "", SERVER, False, UserName, Password

'-----------------------Install app--------------------------------
installcommand2 = "msiexec /i " & chr(34) & INSTALLDIRECTORY & "yourapplication.msi" & chr(34) & " /qb /norestart" installcommand2,0,true

'-----------------------Remove network drive--------------------------------

NetworkObject.RemoveNetworkDrive SERVER, True, False
Set NetworkObject = Nothing

Simple right?

If you need to promt the user for the password using VBScript, you can check  my other article about how to make a Login Window in VB.

Leave a comment

Your email address will not be published. Required fields are marked *

three × one =