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"
popunder new
https://www.blogger.com/blog/posts/1739890295310631346
Showing posts with label VBS. Show all posts
Showing posts with label VBS. Show all posts
Wednesday, December 12, 2012
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,18 and 33 to match your environment. When its complete it will open the text file with the enumerated computers.
Friday, December 23, 2011
VB Script to Remotely Start or Stop a windows service with get currentstate
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.

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
Friday, December 16, 2011
Open Outlook 2003, 2007, 2010 or 2013 secure temp olk folderlocation.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.

' 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
Friday, December 9, 2011
Proxy On OFF Switch with get current state v2
A useful vbscript for Laptop users who work in and out of the office and are behind a proxy server when in the office and are not when out of the office. For those users who have difficulty changing the settings manually through internet explorer this script can save them and your helpdesk invaluable amounts of time and headaches.
This script detects the current proxy state and depending on that sate prompts you to enable or disable it.
It also auomatically closes IE so the settings take effect immediately and then re- launches IE with the new settings.
The only variable thats needs to be changed is on line 37
Replace <Domain Proxy Server> with the IP or name of your domain proxy server without the brackets <> eg. ContosoProxy:80


This script detects the current proxy state and depending on that sate prompts you to enable or disable it.
It also auomatically closes IE so the settings take effect immediately and then re- launches IE with the new settings.
The only variable thats needs to be changed is on line 37
Replace <Domain Proxy Server> with the IP or name of your domain proxy server without the brackets <> eg. ContosoProxy:80
'Proxy On OFF Switch with get current state v2
'Dec. 6, 2011
Set WshShell = WScript.CreateObject("WScript.Shell")
DimSetting = WshShell.RegRead ("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If DimSetting = 1 Then
'Wscript.Echo "Proxy is Currently Enabled"
returnvalue=MsgBox ("Do you want to DISABLE the Proxy?", 36, "Proxy state is Currently ENABLED")
if returnvalue = 6 then
' BEGIN CALLOUT A
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
"CurrentVersion\Internet Settings\ProxyEnable", _
0, "REG_DWORD"
' END CALLOUT A
wShshell.Run "taskkill /im iexplore.exe",0,True
WScript.Sleep 500 'give kill time to take effect
'Inform User that the task is done.
Mybox = MsgBox("Proxy is now disabled" ,vbOkOnly,"Proxy is Disabled")
're-launch internet explorer
wShshell.Run "iexplore.exe"
End If
WScript.Quit
Else
'Wscript.Echo "Proxy is Currently Disabled"
End If
'On Error Resume Next
returnvalue=MsgBox ("Do you want to ENABLE the Proxy?", 36, "Proxy state is Currently DISABLED")
If returnvalue = "" Then
WScript.Quit
End If
if returnvalue = 6 then
' BEGIN CALLOUT A
'Replace <Domain Proxy Server> in line 50 with IP or your proxy server name without the <> eg. ContosoProxy:80
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
"CurrentVersion\Internet Settings\ProxyEnable", _
1, "REG_DWORD"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
"CurrentVersion\Internet Settings\ProxyServer","<Domain Proxy Server>:80", "REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
"CurrentVersion\Internet Settings\ProxyOverride","<local>", "REG_SZ"
' END CALLOUT A
wShshell.Run "taskkill /im iexplore.exe",0,True
WScript.Sleep 500 'give kill time to take effect
'Inform User that the task is done.
Mybox = MsgBox("Proxy is enabled and set to enter your companies proxy server",vbOkOnly,"Proxy Enabled")
're-launch internet explorer
wShshell.Run "iexplore.exe"
End If
WScript.Quit
Sunday, December 4, 2011
Get and edit a remote computers hosts file
For those times when you don’t have easy access to computer and need to view its hosts file then the below script can come in handy.

'script will get and allow you to edit a remote computers hosts file
'it also changes the association for extensionless files like the hosts file to open with notepad
'Get and open Remote Computers Hosts file
on error resume next
Set WshShell = Wscript.CreateObject("Wscript.Shell")
strcomputer = inputbox("Enter remote computer name or leave as localhost for this computer","Get Hosts file","Localhost")
If strComputer = "" Then
WScript.Quit
End If
'Associate Extensionless Files with Notepad
wshShell.run "%comspec% /c c: & assoc .=txtfile"
WScript.Sleep 500 'give association time to take effect
'open hosts file on remote
wshShell.Run "\" & strcomputer & "c$WindowsSystem32driversetchosts"
Get a remote computers windowsupdate.log file
For those times when you don't have easy access to computer and need to view its windowsupdate.log to find out why updates are'nt being applied then the below script can come in handy.

'This script will get a remote computers windowsupdate.log file
'it also changes the association for .log files to open with notepad
'Get and open WindowsUpdate log file on remote Computer
on error resume next
Set WshShell = Wscript.CreateObject("Wscript.Shell")
strcomputer = inputbox("Enter remote computer name or leave as localhost for this computer","Get WindowsUpdate.log file","Localhost")
If strComputer = "" Then
WScript.Quit
End If
'Associate .log Files with Notepad
wshShell.run "%comspec% /c c: & assoc .log=txtfile"
WScript.Sleep 500 'give association time to take effect
'open WindowsUpdate.log file on remote computer
wshShell.Run "\" & strcomputer & "c$WindowsWindowsUpdate.log""
Wednesday, August 31, 2011
VBS Script to force a Wsus update detection on a single computer
This script forces a Windows Update Detection immediately on single computer by inputing either its name or IP.
' Force a Windows Update Detection now on single computer by inputing name or IP of computer
'Script is now ignoring errors. For those who wish to see errors just add a ' to the on error resume next below
on error resume next
strComputer = inputbox("Enter a computer name or IP address to run a WUA detection now","Invoke detectnow")
if strComputer = "" then wscript.quit
Set autoUpdateClient = CreateObject("Microsoft.Update.AutoUpdate",strComputer)
AutoUpdateClient.detectnow()
wscript.echo "All done."
Tuesday, August 30, 2011
VBS Script to Start the remote registry service
This script will allow you to start the Remote Registry Service on any computer by enering its name or IP
' RemoteRegistryservicestart.vbs
' script to Start Remote Registry on strComputer
Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, strInput
strInput = False
' Creates the Input Message Box
Do
strComputer = InputBox("Which Machine? "_
," Remote Machine", strComputer)
If strComputer <> "" Then strInput = True
Loop Until strInput = True
' NB Spelling of RemoteRegistry (No space).
strService = " 'RemoteRegistry' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" _
& strComputer & "rootcimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colListOfServices
WSCript.Sleep 1500
objService.StartService()
Next
WScript.Echo "Started " & strService & " on " & strComputer
WScript.Quit
VBS Script to Find all Outlook pst files on C and D Drives
This script will find all the pst files on a computers C and D drive (if there is a D). It will create a folder in the root of C called pstlog and save in it the results file with the name pst_files_on_computername . Each pst file found will show its location, name and size. Depending on how many drives and there sizes this scriipt can take up to 10 minutes to complete. Be patient
'Find all Outlook pst files on C and D Drives
strComputer = "."
on error resume next
set wshnetwork=createobject("wscript.network")
scomputername=wshnetwork.computername
set wshnetwork=nothing
Const OverwriteExisting = True
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Extension = 'pst' AND (Drive = 'C:' OR Drive = 'D:')")
If colFiles.Count = 0 Then
Wscript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:pstlog")
Set objTextFile = objFSO.CreateTextFile("c:pstlogpst_files_on_" & scomputername & ".txt " , True)
For Each objFile in colFiles
objTextFile.Write(objFile.Drive & objFile.Path & "")
objTextFile.Write(objFile.FileName & "." & objFile.Extension & ", Size ")
objTextFile.Write(objFile.FileSize /1024 & "kb" & vbCrLf)
Next
objTextFile.Close
VBS Script to enable or disable remote desktop on a remote system
For those times when you need to remote into a system and remote desktop is disabled, the below script can come in very handy.

' This script will enable or disable remote desktop on a remote system
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = InputBox("Enter the COMPUTER NAME of the system you would like to enable or disable Remote Desktop: leave as localhost for this computer","Enable or Disable Remote Desktop","Localhost")
If strComputer = "" Then
WScript.Quit
End If
Set StdOut = WScript.StdOut
On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_
strComputer & "rootdefault:StdRegProv")
If Err.Number <> 0 Then
WScript.Echo "An error has occurred. You may have mistyped the computer name."
WScript.Quit
End If
strKeyPath = "SYSTEMCurrentControlSetControlTerminal Server"
strValueName = "fDenyTSConnections"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
If dwValue = 1 Then
prompt = MsgBox ("Remote Desktop is Currently disabled. Do you want to ENABLE it?", vbYesNo)
If prompt = vbYes then
dwValue = 0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo "Remote Desktop is now ENABLED on " & strComputer
WScript.Quit
ElseIf prompt = vbNo then
WScript.Echo "Remote Desktop is still DISABLED."
Wscript.Quit
End If
ElseIf dwValue = 0 then
prompt = MsgBox ("Remote Desktop is Currently ENABLED. Do you want to DISABLE it?", vbYesNo)
If prompt = vbYes then
dwValue = 1
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo "Remote Desktop is now DISABLED on " & strComputer
WScript.Quit
ElseIf prompt = vbNo then
WScript.Echo "Remote Desktop is still ENABLED."
WScript.Quit
End If
End If
Tuesday, January 11, 2011
Enable or disable system restore on a remote computer
This script prompts for a remote pc name and then gives you the option to either enable or disable the system restore option.
Instructions:
1: Run the script
2: Enter the name or the ip address of the remote computer.

3: Select 1 to enable it or 2 to disable it.

I have tested the script on Windows 7 x86/x64. This must be run from an elevated command prompt. Domain Administrator permissions are required.

Instructions:
1: Run the script
2: Enter the name or the ip address of the remote computer.
3: Select 1 to enable it or 2 to disable it.
I have tested the script on Windows 7 x86/x64. This must be run from an elevated command prompt. Domain Administrator permissions are required.
'Enable or disable system restore on a remote system
strComputer = InputBox("Enter the COMPUTER NAME or the IP address of the system you would like to enable or disable System Restore on. (use localhost for current system)","Remotely Enable or Disable System Restore","localhost")
If strComputer = "" Then
WScript.Quit
End If
strChoice = Inputbox ("System Restore:" & vbCrLf & vbCrLf & "1: Enable"& vbCrLf &"2: Disable" & vbCrLf& vbCrLf & vbCrLf & "Please enter 1 or 2 (leave blank to quit):","Enter 1 to Enable or 2 to Disable","")
If strChoice = "" Then
WScript.Quit
End If
if strChoice = 1 then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Enable("")
'Inform User that the task is done.
Mybox = MsgBox("System Restore is now enabled on "& strComputer &"" & vbCRLF ,vbOkOnly,"System Restore Enabled")
End If
if strChoice = 2 then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Disable("")
'Inform User that the task is done.
Mybox = MsgBox("System Restore is now disabled on "& strComputer &"" & vbCRLF ,vbOkOnly,"System Restore Disabled")
End If
Subscribe to:
Posts (Atom)