VB Script to Modify Folder NTFS Security and Share Permission

Below is the VBscript to Modify Folder NTFS Security and Share permission. It is using Cacls.exe and Rmtshare.exe to modify the permission. Cacls.exe can be used to modify Folder NTFS security Permission and  rmtshare.exe modifies Share Permission.  Below script removes all the existing permission NTFS Permission and Provides domain\accountname Full access and remove Inheritance check box and provide domain\accountname read share permission and remove all the other share permission. You can modify the script to suite your requirement

Set WshNetwork = WScript.CreateObject(“WScript.Network”)
strFolderName = Installerpath(WshNetwork.ComputerName)
Set objShell = CreateObject(“Wscript.Shell”)
intRunError = objShell.Run(“%COMSPEC% /c Echo Y| cacls ” & strFolderName & ” /c /g domain\accountname:F”, 2, True)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /remove”)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /grant “”domain\accountname””:read”)
intRunError = objShell.Run(“F:\Krishna\Rmtshare.exe \\Servername\Sharename /remove everyone”)

Function Installerpath(compname)
strPath = “\\” &  compname & “\Sharename”
strPath = Replace(strPath, “\\”, “”)
arrPath = Split(strPath, “\”)
strComputer = arrPath(0)
strShare = arrPath(1)
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery(“Select * From Win32_Share Where Name = ‘” & strShare & “‘”)

For Each objItem in colItems
strFolderName = objItem.Path
Installerpath = strFolderName

End Function

Executing the script :

Save the file as .vbs and you can execute locally or user psexec.exe to execute script remotely. Below is the psexec command to run remotely.

Psexec.exe \\servername cscript C:\Securitymodify.vbs

You can find the copy of the code in the below link


Windows Password Change Notification Script

If your orginization has users who is working outside office network and they normally access email through pop3 then chances that they do not have any notification on password change. This script helps to intimate the give list of users to change the password.

Please find the copy of the script in the below link



VBscript to Pull out the Members of the local Adminstrators Group

Below VBscript helps to pull out Members of the Local Administrators Group from the given list of computer names. You need you have admin permission on the remote computer to pull out the membership details


Option Explicit

Dim objNetwork, objLocalGroup
Dim objTrans, strComputer, strNetBIOSDomain
Dim Result,k,v, Lusr,Dusr, Grp
Dim filesys
Dim filetxt,Servername

‘ Determine NetBIOS name of domain and local computer.
Set objNetwork = CreateObject(“Wscript.Network”)
strNetBIOSDomain = objNetwork.UserDomain
‘strComputer = objNetwork.ComputerName

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.OpenTextFile(“D:\scripts\LocalAdministrator\Servers.txt”,1)

do Until filetxt.AtEndOfStream
Servername = filetxt.Readline
Servername = trim(Servername)

strComputer = Servername
Set objNetwork = Nothing

‘ Bind to local Administrators group.
Set objLocalGroup = GetObject(“WinNT://” & strComputer  & “/Administrators,group”)

‘ Enumerate members of the local group.
result = strComputer
Lusr = “Local User :”
grp = “Domain Group :”
Dusr = “Domain USer : “

Call EnumLocalGroup(objLocalGroup,strComputer)


Sub EnumLocalGroup(ByVal objGroup,strComputer)
    ‘ Subroutine to enumerate members of local group.
    ‘ The variable strComputer has global scope.

    Dim objMember

    ‘ Enumerate direct members of group.
    For Each objMember In objGroup.Members

 If (LCase(objMember.Class) = “group”) Then
 K = objMember.AdsPath
 V = split(K,”/”)
 grp = grp & V(2) & “/” & v(3) & ” : ”
        K = objMember.AdsPath
 V = split(K,”/”)
 if Ubound(v) = 3 Then
 Dusr = Dusr  & V(2) & “/” & v(3) & ” : ”
 ElseIF Ubound(v) = 4 Then
 Lusr = Lusr & V(3) & “/” & v(4)  & ” : ”
 ‘wscript.echo objMember.AdsPath
 End If
 End If
 wscript.echo Ucase(strComputer) & “,” & Ucase(Lusr) &”,” & Ucase(Dusr) &”,” & Ucase(grp)
End Sub


Copy of the script can be found in the below mentioned Link


VBscript to Check Schema has been updated on Domain Controllers

To Introduce new Windows 2008 Additional domain controller we have to forest and domain. As part of the forest preparation we run the commaind adprep /Forestprep. Its recommended to run this command on the Schema Master Server


Below VBscript  will check on all the DCs for Schema update on the servername which are given in the file serverlist.  Script result will confirm if schema is updated successful or failed on the servers.


Dim objShell
set objShell = wscript.createObject(“wscript.shell”)

Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt1 = filesys.OpenTextFile(“C:\serverlist.txt”,1)

do Until filetxt1.AtEndOfStream
 Servername = filetxt1.Readline
 servername = trim(Servername)
 iReturn = objShell.Run(“CMD /C psexec.exe \\” & servername & ” schupgr > log.txt”, , True)
 Set filesys = CreateObject(“Scripting.FileSystemObject”)
 set filetxt = filesys.OpenTextFile(“C:\log.txt”,1)
 K = 0
 str = “Current Schema Version is 44”
 do Until filetxt.AtEndOfStream
  LineVerify = filetxt.Readline
  LineVerify = trim(LineVerify)
  If InStr(UCase(LineVerify), Ucase(“Current Schema Version is 44”)) Then
   K = 1
  End If

 if iReturn = 1 AND K = 1 Then

  wscript.echo servername & “: Success”
  wscript.echo servername &”: Failure”
 End If



Find the copy of the script in the below link


VBscript to copy file to the remote computers

Below is the VB script to copy a file from local computer to list of remote computers

On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile(“C:\server.txt”, ForReading)

Do Until objTextFile.AtEndOfStream
 strComputer = objTextFile.Readline
        objFSO.CopyFile “C:\regsetting.bat” , “\\” & strcomputer & “\C$\”
        wscript.echo strcomputer & ” Copied”

VBscript to check if SCOM agent is installed on a given list of servers

Below scripts takes input list of servers as input and generates the out with list of scom agent installed servers  and also get the details like start mode, current status etc

on error resume next
Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt = filesys.OpenTextFile(“C:\scripts\Server.txt”,1)

do Until filetxt.AtEndOfStream
 name = filetxt.Readline
 strComputer = trim(name)

 Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
 Set colServices = objWMIService.ExecQuery (“Select * From Win32_Service”)

 For Each objService in colServices
  if objService.Name = “HealthService” Then
   wscript.echo  strcomputer & ” – ” & objService.Name & ” – ” & objService.State & ” – ” &objService.Startmode
  End If