RSSCategory: VBS

List members of all local groups on a list of computers vbs script

Here is a script that I use to list members of all local groups on a list of computers. It takes a list of computer names and checks the group members on each one then writes the results to a second file. Change the file paths in lines 6,19 and 36 to match your environment. When its complete it will open the text file with the enumerated computers.

Const ForAppending = 8
Const ForReading = 1
ServerCount = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\serverlist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
 strComputer = strNextLine
 'WScript.Echo "Processing " & strComputer
 ProcessGroups
 ServerCount = ServerCount + 1
Loop
'WScript.Echo "Computers Processed  " & ServerCount
'WScript.Quit

Sub ProcessGroups
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\scripts\GroupInfo.txt", _
    ForAppending, True)

objLogFile.writeline " "
objLogFile.writeline "***************** " & strComputer & " *****************"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    objLogFile.writeline objGroup.Name
    For Each objUser in objGroup.Members
        objLogFile.writeline vbTab & objUser.Name
    Next
Next
objLogFile.Close
End Sub

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\scripts\GroupInfo.txt"

2012/12/12 | By | Reply More

VB Script to Remotely Start or Stop a windows service with get current state

This script will start or stop a service on a remote computer. It will optionally allow you to retrieve the current state of the service before and after you make a change. This is useful for verifying the state of the service before you make a change and to verify the change has been applied.

Download Button5

dim svcName, sStart, sStop
dim service
dim objService
dim SvrName
dim input
dim input2
Dim svclist
Dim compname
dim objFile
Set WshShell = WScript.CreateObject("WScript.Shell")

on error resume next

input = Inputbox ("Computer Name that you would like to Start or stop service on:"& vbCRLF & "Default is this pc", _
"Stop or Start service","localhost")

If input = "" Then
WScript.Quit
End If

returnvalue=MsgBox ("Do you want display a list of services on remote pc?"& vbCRLF & "List will show the Service Short Name, the current State and the Service Display Name", 36, "Show Services")
if returnvalue = 6 then

Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:services list.txt", ForWriting, True)
Set colServices =  GetObject("winmgmts://" & input).ExecQuery _
("Select * from Win32_Service")
objTextFile.WriteLine("Short Name") & VbTab & ("Current State") & VbTab & VbTab & ("Display Name")
For Each objService in colServices
objTextFile.WriteLine(objService.Name  & VbTab  & _
objService.State & VbTab & VbTab & objService.DisplayName)
Next
objTextFile.Close
WScript.Sleep 500
wShshell.Run "notepad c:services list.txt"
WScript.Sleep 500

If input = "" Then
WScript.Quit
End If

input2 = Inputbox ("Enter the Service name you want to start or stop:" & vbCRLF & "Use the services list.txt file to get service short name if you don't know it." & vbCRLF & "print spooler = spooler" & vbCRLF & "remote registry = remoteregistry" & vbCRLF & "Windows Event log = eventlog"& vbCRLF & "Default is Print Spooler" & vbCRLF & "","Service Name","spooler")

If input2 = "" Then
WScript.Quit
End If

SvrName = input
svcName = input2

Set service = GetObject("winmgmts:!\" & svrName & "rootcimv2")
svc = "Win32_Service=" & "'" & svcName & "'"
state = inputbox _
("Enter start or stop to Change the Status of Service"  & vbCRLF & "lowercase only" & vbCRLF & "Default is start","start or stop","start")

If state = "" Then
WScript.Quit
End If

if state = "start" then
Set objService = Service.Get(svc)
retVal = objService.StartService()

returnvalue=MsgBox ("Do you want re-open the services list.txt file and verify the state change?", 36, "Started the " & svcName & " service on " & SvrName)
if returnvalue = 6 then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:services list.txt", ForWriting, True)
Set colServices =  GetObject("winmgmts://" & input).ExecQuery _
("Select * from Win32_Service")
objTextFile.WriteLine("Short Name") & VbTab & ("Current State") & VbTab & ("Display Name")
For Each objService in colServices
objTextFile.WriteLine(objService.Name  & VbTab  & _
objService.State & VbTab  & objService.DisplayName)
Next
objTextFile.Close
WScript.Sleep 500
wShshell.Run "notepad c:services list.txt"
WScript.Sleep 500
end if
WScript.Quit

elseif state = "stop" then
Set objService = Service.Get(svc)
retVal = objService.StopService()
end if
returnvalue=MsgBox ("Do you want re-open the services list.txt file and verify the state change?", 36, "Stopped the " & svcName & " service on " & SvrName)
if returnvalue = 6 then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:services list.txt", ForWriting, True)
Set colServices =  GetObject("winmgmts://" & input).ExecQuery _
("Select * from Win32_Service")
objTextFile.WriteLine("Short Name") & VbTab & ("Current State") & VbTab & ("Display Name")
For Each objService in colServices
objTextFile.WriteLine(objService.Name  & VbTab  & _
objService.State & VbTab  & objService.DisplayName)
Next
objTextFile.Close
WScript.Sleep 500
wShshell.Run "notepad c:services list.txt"
WScript.Sleep 500
end if
WScript.Quit

end if
2011/12/23 | By | Reply More

Open Outlook 2003, 2007, 2010 or 2013 secure temp olk folder location.vbs script

A useful script, especially for those high maintenance users who insist on editing excel or word documents they open from Outlook and then frantically calling your help desk complaining they can’t locate files they saved while working in Outlook. Place the script on their desktop and have them run it first before calling your help desk.. Works with Outlook 2003, 2007, 2010 and now also with Outlook 2013.

Download Button5

' This script will open the Outlook Secure Temp folder location for Outlook
' 2003, 2007, 2010 and 2013

Dim WshShell, strValue, openlocation

Set WshShell = WScript.CreateObject(“WScript.Shell”)
const HKEY_CURRENT_USER = &H80000001
on error resume next
strComputer = “.”

Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\” &_
strComputer & “rootdefault:StdRegProv”)

strKeyPath = “SoftwareMicrosoftOffice11.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If IsNull(dwValue) Then

Else
strKeyPath = “SoftwareMicrosoftOffice11.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If

strKeyPath = “SoftwareMicrosoftOffice12.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If IsNull(dwValue) Then

Else
strKeyPath = “SoftwareMicrosoftOffice12.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If

strKeyPath = “SoftwareMicrosoftOffice14.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If IsNull(dwValue) Then

Else
strKeyPath = “SoftwareMicrosoftOffice14.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If

strKeyPath = “SoftwareMicrosoftOffice15.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

If IsNull(dwValue) Then

Else
strKeyPath = “SoftwareMicrosoftOffice15.0OutlookSecurity”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If

WScript.Quit


2011/12/16 | By | Reply More