Scripts


 

Visual Basic


Set DNS Severs
Description: Set your DNS servers.
Submitted by: Josh Hyatt on September 17th, 2008


View Script
                        	 
strComputer = "."  
arrDNSServers = Array("4.2.2.1, 4.2.2.2")
    
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "\root\cimv2")  
      
Set colNetCards = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")  
      
For Each objNetCard in colNetCards  
      objNetCard.SetDNSServerSearchOrder(arrDNSServers)  
Next
 
                        
 

Change computer name
Description: This will prompt you for what name you want the computer to be then set it.
Submitted by: Josh Hyatt on September 17th, 2008


View Script
                        	 
Name = InputBox("What would you like the new computername to be?","What would you like the new computername to be?", "EXWKS01")

Set objWMIService = GetObject("Winmgmts:root\cimv2")

For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")

       Return = objComputer.rename(Name)
       If Return <> 0 Then
          WScript.Echo "Rename failed. Error = " & Err.Number
       Else
          WScript.Echo "Rename succeeded." & " Reboot for new name to go into effect"
       End If

Next 
                        
 

Disable XP Firewall
Description: Disable your Windows XP Firewall
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

objPolicy.FirewallEnabled = FALSE 
                        
 

Disable Offline Files
Description: Disable Offline Files on a Windows XP Machine
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
    Enabled = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\Enabled"
    DefCacheSize = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\DefCacheSize"
    enabledValue = "00000000"
    DefCacheSizeValue = "00000513"
    Set objShell = CreateObject("WScript.Shell")
    objShell.RegWrite Enabled, enabledValue, "REG_DWORD"
    objShell.RegWrite DefCacheSize, DefCacheSizeValue, "REG_DWORD"
	wscript.echo "Done" 
                        
 

Display Installed Applications
Description: Display the applications installed on a machine and output that to a HTML file.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
'########################
'Write Installed applications to a file
'Script Created by Josh Hyatt on 6-22-08
'########################
Option Explicit
Dim objFso, objFolder, objWMI, objShell, strEventLog, objWMIService, objFeature, objDesktop
Dim strFile, strComputer, strFolder, strFileName, strPath, colfeatures



'#############
'#Setup the Variables
'#############
strComputer = "."
Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("Desktop")
strFileName = "\installedapps.html"
strFolder = "c:\windows\temp"
strPath = strFolder & strFileName


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFeatures = objWMIService.ExecQuery ("Select * from Win32_Product")


'######################
'#Create Folder if it doesnt exist
'######################	
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolder) Then
Set objFolder = objFSO.GetFolder(strFolder)
Else
Set objFolder = objFSO.CreateFolder(strFolder)
Wscript.Echo "Folder created " & strFolder
End If



'###########################
'#Create the logfiles to start the process
'###########################	
Wscript.Echo "This may take a few minutes depending on how many applications you have installed." 
Set strFile = objFso.CreateTextFile(strPath, True)
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
	strFile.WriteLine("Installed Application - Script Created by Josh Hyatt - 6/22/2008")
	strFile.WriteLine("")



'######################################
'#Loop through installed applications and write them to the logfiles
'######################################	
For Each objFeature in colfeatures
	strFile.WriteLine("")
	strFile.WriteLine("")
	strFile.WriteLine("")
	strFile.WriteLine("")
	strFile.WriteLine("")
	strFile.WriteLine("")
	strFile.WriteLine("")
    strFile.WriteLine("")	
	strFile.WriteLine("")
	strFile.WriteLine("
Product Name: " & objFeature.Name & "
Vendor: " & objFeature.Vendor & "
Version: " & objFeature.Version & "


") Next '################### '#Close the remaining HTML Tags '################### strFile.WriteLine("") '########### '#Open the log file '########### objShell.run ("Explorer" &" " & strPath & "\" ) WScript.Quit
 

Get IP Information
Description: Get your ip information just for active network connections.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapter")
 
 
   For Each objItem In colItems
      
	  strConnectionStatus = objItem.NetConnectionStatus
  
	  If strConnectionStatus = 2 Then
	    strMacAddress = objItem.MACAddress
	  End If
   Next 
	 
 Set objAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True' AND MACAddress='" & strMacAddress & "'")
 
For Each objAdapter in objAdapters
   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
         WScript.Echo "IP address: " & objAdapter.IPAddress(i)
      Next
   End If
 
   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
         WScript.Echo "Subnet: " & objAdapter.IPSubnet(i)
      Next
   End If
 
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
         WScript.Echo "Default gateway: " & _
             objAdapter.DefaultIPGateway(i)
      Next
   End If

   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
         WScript.Echo "DNS: " & objAdapter.DNSServerSearchOrder(i)
      Next
   End If
   
      If Not IsNull( objAdapter.Caption ) Then
             strNICName = Left( objAdapter.Caption , 10)
             WScript.Echo "Connection Name: " & strNICName
      End If
   
Next


	  



     
  
 
                        
 

Enable Remote Desktop
Description: Enables Remote Desktop on a Windows XP Workstation.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
machine = "."
cimv2_string = "WINMGMTS:" & "\\" & machine & "\root\cimv2"
query = "select * from Win32_TerminalServiceSetting"
value_to_set = 1 ' 0=off, 1=on
set cimv2 = GetObject( cimv2_string )
set items = cimv2.ExecQuery( query )
for each item in items
item.SetAllowTSConnections( value_to_set )
next
 
                        
 

Remove HotFix Unistallers
Description: Removes all the Windows Hotfix uninstallers.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set OFWindows = oFSO.GetFolder("c:\windows")
Set OWinFolders = OFWindows.SubFolders
For Each OWinFolder in OWinFolders
if Ucase(left(OWinFolder.name , 14)) = "$NTUNINSTALLKB" then OWinFolder.delete force
Next 
                        
 

Get Script Path
Description: Gets the path to where the script is running without the script name.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
objScriptPath = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - Len(WScript.ScriptName))

wscript.echo objScriptPath 
                        
 

Download File
Description: Download files from either FTP or HTTP and save them to a location
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
' Set your settings
    strFileURL = inputbox("Whats the file url?")
    strHDLocation = inputbox("Where do you want to save it?")
 
' Fetch the file
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
 
    objXMLHTTP.open "GET", strFileURL, false
    objXMLHTTP.send()
 
    If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
 
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
 
      Set objFSO = Createobject("Scripting.FileSystemObject")
        If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
      Set objFSO = Nothing
 
      objADOStream.SaveToFile strHDLocation
      objADOStream.Close
      Set objADOStream = Nothing
    End if
 
    Set objXMLHTTP = Nothing 
                        
 

Disable System Restore
Description: Disable System Restore on a Windows XP Workstation
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
 errResults = objItem.disable("") 
                        
 

Add RunOnce
Description: Add a RunOnce key.
Submitted by: Josh Hyatt on September 18th, 2008


View Script
                        	 

    Set objShell = CreateObject("WScript.Shell") 

    RegLocRunOnce = "HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce\"
    keyRunOnce = "FinishSetupStep1"
    valRunOnce = "C:\test.exe"

    objShell.RegWrite ReglocRunOnce & keyRunOnce, 1, "REG_SZ"
    objShell.RegWrite ReglocRunOnce & keyRunOnce, valRunOnce, "REG_SZ" 
                        
 

Uninstall App
Description: Uninstall App. Use Display Install Apps to get app name.
Submitted by: Josh Hyatt on May 23rd, 2010


View Script
                        	 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product Where Name = 'Safari'")

For Each objSoftware in colSoftware
    objSoftware.Uninstall()
Next