Thursday, 21 August 2014

VBS - write computer details to AD computer account description

original post, how to delegate permissions in AD
http://www.compit.se/?p=282


output:
martin.junge / SN: F4***R1 / Dell Latitude E6420 / Windows 8.1 Pro  x64 / Last Boot Time: 08.08.2014 / Last Update Time: 21.7.2014 / Bios vers.: A21 / bitlocker disabled


---my modified vbs file---

On Error Resume Next

strComputer = "."
Set objSysInfo = CreateObject( "WinNTSystemInfo" )
strUserName = objSysInfo.UserName


Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colcomputersystem = objWMIService.ExecQuery _
    ("Select * from Win32_computersystem")
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")

For each objcomputersystem in colcomputersystem
    Getcomputersystem = objcomputersystem.Model
    if Getcomputersystem = "VMware Virtual Platform" then Getcomputersystem = Right(Getcomputersystem, 17) end if

    if Getcomputersystem = "Virtual Machine" then
        Dim SysVarReg, Value
        Set SysVarReg = WScript.CreateObject("WScript.Shell")
        value = SysVarReg.RegRead ("HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\PhysicalHostName")
        Getcomputersystem = Getcomputersystem & " on " & value
    end if

    GetComputerManufacturer = objComputerSystem.Manufacturer
Next

'---get Manufacturer--------------------
   'String cleaning - Manufacturer includes only first word, and the serial removes any spaces.
txtCount = InStr(GetComputerManufacturer," ") - 1
GetComputerManufacturer = Left(GetComputerManufacturer,txtCount)
if GetComputerManufacturer = "Hewlett-Packard" then GetComputerManufacturer = "" end if
if GetComputerManufacturer = "TOSHIBA" then GetComputerManufacturer = "Toshiba" end if
if GetComputerManufacturer = "VMware," then GetComputerManufacturer = Left(GetComputerManufacturer, 6) end if

if GetComputerManufacturer = "LENOVO" then
    Dim objWMIService, colItems
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT Version FROM Win32_ComputerSystemProduct")
    For Each objItem in colItems
        Getcomputersystem = objItem.Version & " " & objItem.Name
    Next
    GetComputerManufacturer = "Lenovo"
end if

if GetComputerManufacturer = "Microsoft Virtual Machine" then
    VMHost = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\PhysicalHostName")
    GetComputerManufacturer = GetComputerManufacturer & "on " & VMHost
end if
'---end Manufacturer-------

'---get serialnumber and BIOS version----------
GetSerialNumber = Replace(GetSerialNumber, " ", "")
For each objBIOS in colBIOS
    GetSerialNumber = objBIOS.SerialNumber
    GetBiosVers = objBIOS.SMBIOSBIOSVersion
Next
if GetComputerManufacturer = "VMware" then GetSerialNumber = Left(GetSerialNumber, 6) end if

'---end serialnumber-------

'---get processor architecture type---
Dim WshShell
Dim OsType
Set WshShell = CreateObject("WScript.Shell")
OsType = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
if OsType = "AMD64" then
OsType = "x64"
end if
'---end processor architecture type---

'---get Operating system---
Dim OSVersion
OSVersion = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
if OSVersion = "Microsoft Windows XP" then OSVersion = "Windows XP" end if
if OSVersion = "Microsoft Windows 2000" then OSVersion = "Windows 2000" end if
if OSVersion = "Microsoft Windows Server 2003" then OSVersion = "Windows Server 2003" end if
if OSVersion = "Microsoft Windows Server 2003 R2" then OSVersion = "Windows Server 2003 R2" end if
'---end Operating system---

'---get service pack version---
Const Impersonate = "winmgmts:{impersonationLevel=impersonate}!\\"
Set oWMI = GetObject(Impersonate & strComputer & "\root\cimv2")
Set QueryWMI = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each oItem In QueryWMI
spVer = oItem.ServicePackMajorVersion
if spVer = 0 then spVer ="" else spVer = "SP" & spVer end if
Next
'---end service pack version---

'---get last boot time start----
Dim strBoot, strBootDate, strBootDay, strBootHour, strBootMins
Dim strBootMonth, strBootTime, strBootYear, strMsg, strQuery
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem", , 48 )
For Each objItem in colItems
strBootYear = Left( objItem.LastBootUpTime, 4 )
strBootMonth = Mid( objItem.LastBootUpTime, 5, 2 )
strBootDay = Mid( objItem.LastBootUpTime, 7, 2 )
strBootHour = Mid( objItem.LastBootUpTime, 9, 2 )
strBootMins = Mid( objItem.LastBootUpTime, 11, 2 )
strBootTime = strBootHour & ":" & strBootMins
Next
'---end last boot time----

'---get last windows update time------
Set objSession = CreateObject("Microsoft.Update.Session")
Set objSearcher = objSession.CreateUpdateSearcher
Set colHistory = objSearcher.QueryHistory(1, 1)
For Each objEntry in colHistory
 strHotfix = objEntry.Date
Next

'---end last windows update time------

'---get bitlocker status---

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume",,48)
For Each objItem in colItems
    bitlockerdiveletter = objItem.DriveLetter
    bitlockerstatus = objItem.ProtectionStatus
    if bitlockerdiveletter = "C:" then
        if bitlockerstatus=1 then bitlockerstatusnote = "bitlocker enabled" else bitlockerstatusnote = "bitlocker disabled" end if
    end if
next
'---end bitlocker status---

'---define AD description text for clients and servers
If InStr(OSVersion, "Server") Then
    strMessage = GetComputerManufacturer & " " & trim(Getcomputersystem) & " / " & "SN: " & trim(GetSerialNumber) & " / " & OSVersion & " " & spVer  & " " & OsType & " / " & "Last Boot Time: " & strBootDay & "." & strBootMonth & "." & strBootYear & " / Last Update Time: " &  day(strHotfix) & "." & month(strHotfix) & "." & year(strHotfix) & " / Bios vers.: " & GetBiosVers
else
    strMessage = strUserName & " / " & "SN: " & trim(GetSerialNumber) & " / " & GetComputerManufacturer & " " & trim(Getcomputersystem) & " / " & OSVersion & " " & spVer  & " " & OsType & " / " & "Last Boot Time: " & strBootDay & "." & strBootMonth & "." & strBootYear & " / Last Update Time: " &  day(strHotfix) & "." & month(strHotfix) & "." & year(strHotfix) & " / Bios vers.: " & GetBiosVers & " / " & bitlockerstatusnote
end if
'---end define---

'WScript.Echo strMessage   'for testing

objComputer.Description = strMessage
objComputer.SetInfo

'---eof---

CMD - stop / delete service on remoe machine in txt file

@echo off

set LISTFILE=clients.txt

for /f %%a in (%LISTFILE%) do (

    echo.
    echo --------------------------------
    echo.
    echo %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            echo.
                sc.exe \\%%a stop psexesvc
                sc.exe \\%%a delete psexesvc
            )
        if errorlevel 1 (
            echo %%a unavailable
            )
    )
pause

CMD - kill task on remote machines in txt file

@echo off

set LISTFILE=clients.txt

for /f %%a in (%LISTFILE%) do (

    echo.
    echo --------------------------------
    echo.
    echo. %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            TASKKILL /s %%a /IM iexplore.exe
            )
    )

pause

CMD - force windows update for all servers in txt file


4 files needed!

start-update.bat
servers.txt
updatehf.bat
updatehf.vbs
psexec.exe

---start-update.bat-----
@echo off

rem set LISTFILE=%1
set LISTFILE=servers.txt

for /f %%a in (%LISTFILE%) do (
    echo.
    echo ---------------------------------------
    echo.
    echo %%a
    ping -n 1 %%a | find "TTL="
        if not errorlevel 1 (
            echo copy updatehf.vbs to %%a
                xcopy c:\temp\updatehf.vbs "\\%%a\c$\temp\" /Y /Q
            echo copy updatehf.bat to %%a
                xcopy c:\temp\updatehf.bat "\\%%a\c$\temp\" /Y | find "0 File"
                if errorlevel 1 (
                    echo open a new cmd for %%a to run updatehf.bat
                    start /min cmd /k ""C:\Windows\psexec.exe" -accepteula -s -w "c:\temp" \\%%a "c:\temp\updatehf.bat" & exit"
                    )
            )
        if errorlevel 1 (
            echo %%a unavailable
            )
    )

----eof---


---updatehf.bat---
cscript c:\temp\updatehf.vbs action:install mode:silent email:youremail@yourdomain.com restart:0
exit

---eof---



---servers.txt---
server1
server2
server3
...
---eof---

Registry - Disable Writing to USB Drives


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies]
“WriteProtect”=dword:00000001

Registry - enable / disable USB storages devices


to disable USB storage devices

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t REG_DWORD /d 4 /f

to enable USB storage devices

REG ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR" /v Start /t REG_DWORD /d 3 /f

Registry - disable/ignore all client WSUS settings


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU]
"UseWUServer"=dword:00000000

Registry - Disable Windows Hidden Administrative Shares


Hive: HKEY_LOCAL_MACHINE
Key: SYSTEM\CurrentControlSet\Services\LanManServer\Parameters
Name: AutoShareServer for servers
Name: AutoShareWks for workstations
Type: REG_DWORD
Value: 0

CMD - enable remote desktop

local machine


REG.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0

for a remote machine


REG.exe ADD "\\MachineName\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0

Registry - fix VBS extension


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.vbs]
@="VBSFile"

[HKEY_CLASSES_ROOT\.vbs\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"


[HKEY_CLASSES_ROOT\VBSFile]
@="VBScript Script File"
"FriendlyTypeName"=hex(2):40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
  00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
  32,00,5c,00,77,00,73,00,68,00,65,00,78,00,74,00,2e,00,64,00,6c,00,6c,00,2c,\
  00,2d,00,34,00,38,00,30,00,32,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\DefaultIcon]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,53,00,\
  63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,2c,00,32,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\ScriptEngine]
@="VBScript"

[HKEY_CLASSES_ROOT\VBSFile\ScriptHostEncode]
@="{85131631-480C-11D2-B1F9-00C04F86C324}"

[HKEY_CLASSES_ROOT\VBSFile\Shell]

[HKEY_CLASSES_ROOT\VBSFile\Shell\Edit]
@="&Edit"

[HKEY_CLASSES_ROOT\VBSFile\Shell\Edit\Command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,6f,00,\
  74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,25,00,31,00,00,\
  00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open]
@="&Open"

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,53,00,\
  63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,00,31,\
  00,22,00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open2]
@="Open &with Command Prompt"

[HKEY_CLASSES_ROOT\VBSFile\Shell\Open2\Command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,43,00,53,00,\
  63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,00,31,\
  00,22,00,20,00,25,00,2a,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\Shell\Print]
@="&Print"

[HKEY_CLASSES_ROOT\VBSFile\Shell\Print\Command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,6f,00,\
  74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,70,00,20,\
  00,25,00,31,00,00,00

[HKEY_CLASSES_ROOT\VBSFile\ShellEx]

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\VBSFile\ShellEx\PropertySheetHandlers\WSHProps]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"