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.

Click to download

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 & "\root\cimv2")
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

Advertisements

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

.

</span>
<div class="wlWriterEditableSmartContent" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:f904c224-cbf3-43a3-b7e6-3c6bcf3d2e92" style="float: none; margin: 0; display: inline; padding: 0;">
<pre>' 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 & “\root\default:StdRegProv”)
strKeyPath = “Software\Microsoft\Office\11.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If IsNull(dwValue) Then
Else
strKeyPath = “Software\Microsoft\Office\11.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If
strKeyPath = “Software\Microsoft\Office\12.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If IsNull(dwValue) Then
Else
strKeyPath = “Software\Microsoft\Office\12.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If
strKeyPath = “Software\Microsoft\Office\14.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If IsNull(dwValue) Then
Else
strKeyPath = “Software\Microsoft\Office\14.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If
strKeyPath = “Software\Microsoft\Office\15.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If IsNull(dwValue) Then
Else
strKeyPath = “Software\Microsoft\Office\15.0\Outlook\Security\”
strValueName = “OutlookSecureTempFolder”
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
openlocation = “EXPLORER.exe /e,” & strValue
wShshell.Run openlocation
End If
WScript.Quit

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 47
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
On Error Resume Next
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
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 in line 47 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",":80", "REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
"CurrentVersion\Internet Settings\ProxyOverride","", "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

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$\Windows\WindowsUpdate.log"

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$\Windows\System32\drivers\etc\hosts"