Detecting and installing WSUS updates in Server 2008 Core

Posted on November 14th, 2009 in Deployment, Security, Server 2008 by alt-92

On a normal GUI-box, detecting or installing new updates after a fresh install is reasonably easy.
You just click the Updates Control panel item, or, for the more commandline orientated folks, run a wuauclt /detectnow and wait for the “There are new updates available” Systray icon to appear.

The problem with Server Core … there’s no way for you to see the “updates to install” notice in the system tray when you log on to the computer because, well, there’s no systray!

In comes a handy piece of VBscript that allows you to do a manual quick check and start off the installation process, using the in-box Windows Update Agent API.
http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx

Although the MSDN article states it does not run against SUS 1.0 servers, you don’t have to worry because both Windows Update (site) and WSUS 3.x employ the WUA API.

Save and run the script in the command prompt as “cscript ” since the default script host is graphical (wscript) on a Core box.

01
02
Set updateSession = CreateObject("Microsoft.Update.Session")
03
Set updateSearcher = updateSession.CreateupdateSearcher()
04
 
05
WScript.Echo "Searching for updates..." & vbCRLF
06
 
07
Set searchResult = _
08
updateSearcher.Search("IsInstalled=0 and Type='Software'")
09
 
10
WScript.Echo "List of applicable items on the machine:"
11
 
12
For I = 0 To searchResult.Updates.Count-1
13
    Set update = searchResult.Updates.Item(I)
14
    WScript.Echo I + 1 & "> " & update.Title
15
Next
16
 
17
If searchResult.Updates.Count = 0 Then
18
WScript.Echo "There are no applicable updates."
19
WScript.Quit
20
End If
21
 
22
WScript.Echo vbCRLF & "Creating collection of updates to download:"
23
 
24
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
25
 
26
For I = 0 to searchResult.Updates.Count-1
27
    Set update = searchResult.Updates.Item(I)
28
    WScript.Echo I + 1 & "> adding: " & update.Title 
29
    updatesToDownload.Add(update)
30
Next
31
 
32
WScript.Echo vbCRLF & "Downloading updates..."
33
 
34
Set downloader = updateSession.CreateUpdateDownloader() 
35
downloader.Updates = updatesToDownload
36
downloader.Download()
37
 
38
WScript.Echo  vbCRLF & "List of downloaded updates:"
39
 
40
For I = 0 To searchResult.Updates.Count-1
41
    Set update = searchResult.Updates.Item(I)
42
    If update.IsDownloaded Then
43
       WScript.Echo I + 1 & "> " & update.Title 
44
    End If
45
Next
46
 
47
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
48
 
49
WScript.Echo  vbCRLF & _
50
"Creating collection of downloaded updates to install:" 
51
 
52
For I = 0 To searchResult.Updates.Count-1
53
    set update = searchResult.Updates.Item(I)
54
    If update.IsDownloaded = true Then
55
       WScript.Echo I + 1 & "> adding:  " & update.Title 
56
       updatesToInstall.Add(update) 
57
    End If
58
Next
59
 
60
WScript.Echo  vbCRLF & "Would you like to install updates now? (Y/N)"
61
strInput = WScript.StdIn.Readline
62
WScript.Echo 
63
 
64
If (strInput = "N" or strInput = "n") Then 
65
WScript.Quit
66
ElseIf (strInput = "Y" or strInput = "y") Then
67
WScript.Echo "Installing updates..."
68
Set installer = updateSession.CreateUpdateInstaller()
69
installer.Updates = updatesToInstall
70
Set installationResult = installer.Install()
71
 
72
'Output results of install
73
WScript.Echo "Installation Result: " & _
74
installationResult.ResultCode 
75
WScript.Echo "Reboot Required: " & _ 
76
installationResult.RebootRequired & vbCRLF 
77
WScript.Echo "Listing of updates installed " & _
78
"and individual installation results:" 
79
 
80
For I = 0 to updatesToInstall.Count - 1
81
WScript.Echo I + 1 & "> " & _
82
updatesToInstall.Item(i).Title & _
83
": " & installationResult.GetUpdateResult(i).ResultCode 
84
Next
85
End If

DFS namespace query tool

Posted on July 29th, 2009 in Server 2003, Server 2008, Storage by alt-92

For quick lookups to find out where DFS links are pointing to, I’ve built dfsquery.exe in C++.
standalone executable, 64bits support and works on NT5.1 and up (including Windows 7).

Based on MSDN code sample from http://msdn.microsoft.com/en-us/library/bb524791(VS.85).aspx

01
02
#define UNICODE
03
#include <stdio.h>
04
#include <windows.h>
05
#include <lm.h>
06
#include <lmdfs.h>
07
 
08
void wmain(int argc, wchar_t *argv[ ])
09
{
10
   PDFS_INFO_4 pData;
11
   PDFS_STORAGE_INFO ps;
12
   DWORD er=0, tr=0, res, j;
13
 
14
   //
15
   // Check command line arguments.
16
   //
17
   if (argc<2)
18
      wprintf(L"Syntax: %s DfsEntryPath\n", argv[0]);
19
   else
20
   {
21
      //
22
      // Call the NetDfsGetInfo function, specifying level 4.
23
      //
24
      res = NetDfsGetInfo(argv[1], NULL, NULL,  4, (LPBYTE *) &pData);
25
      //
26
      // If the call succeeds, print the data.
27
      //
28
      if(res==0)
29
      {
30
 printf("Report for: %-30S\nStorages: %u\nComment: %S\n",pData->EntryPath, pData->NumberOfStorages, pData->Comment, pData->Timeout);
31
 printf("Timeout: %u\n",pData->Timeout);
32
 ps = pData->Storage;
33
         //
34
         // Loop through each target.
35
         //
36
         for(j=1;j<=pData->NumberOfStorages;j++)
37
         {
38
            //
39
            // Print the status (Offline/Online) and the name 
40
            // of each target referenced by the DFS link.
41
            //
42
 printf("Target %S  ", (ps->State == DFS_STORAGE_STATE_OFFLINE) ? TEXT("Offline:"): TEXT("Online :"));
43
            printf("\\\\%S\\%S\n",ps->ServerName,ps->ShareName);
44
            ps++;
45
         }
46
         //
47
         // Free the allocated memory.
48
         //
49
         NetApiBufferFree(pData);
50
      }
51
      else
52
         printf("Error: %u\n", res);
53
   }
54
   return;
55
}
56

It’s quick, it’s probably dirty, but it works just fine (and no admin privileges needed as it does the same as your average DFS client code).

Sample output:

D:\>dfsquery \\alt-92.net\files\0054
Report for: \\ALT-92\files\0054
Storages: 2
Comment:Department 54 data store
Timeout: 300
Target Online : \\ENDEAVOUR\data\0054
Target Offline: \\Equinoxe\data\0054

It shows timeout value, comments (description field in DFS console) the number of link targets and their individual link state.

Mounting VHD files in Vista

Posted on July 9th, 2009 in Server 2003, Server 2008, Storage, Virtualisation, Vista, Windows 7 by alt-92

Windows 7 features include attaching and detaching Virtual Harddrive files (.VHD) via Disk Management.
This allows you to mount and dismount your Complete PC Backup .vhd file to restore a single item from backup or prestage a Virtual PC/Server diskfile, or even your HyperV disks.

Vista does not have this feature, but there is a workaround available. Installing the VHDMount utility from Virtual Server 2005R2 SP1 lets you use the VHD storage driver and the vhdmount utility.

  1. Download the Virtual Server 2005 R2 SP1 setup from http://www.microsoft.com/windowsserversystem/virtualserver/downloads.aspx .
  2. Run setup and choose Custom Setup type:

    vhdmount1
    vhdmount2

  3. Verify the default selection for VHD Mount is marked:

    vhdmount3

    Click Next to install and finish the setup.

    vhdmount4

  4. You can use the command line vhdmount utility to attach a .VHD file, or alternatively, use these registry entries to create a context menu for the four actions.

    01
    Windows Registry Editor Version 5.00
    02
     
    03
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD]
    04
    @="Virtual Machine Hard Drive Image"
    05
     
    06
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\DefaultIcon]
    07
    @="C:\\Program Files\\Microsoft Virtual PC\\Virtual PC.exe,-327"
    08
     
    09
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell]
    10
    @="Mount"
    11
     
    12
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Commit]
    13
     
    14
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Commit\command]
    15
    @="\"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /c \"%1\""
    16
     
    17
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Discard]
    18
     
    19
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Discard\command]
    20
    @="\"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /d \"%1\""
    21
     
    22
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Dismount]
    23
     
    24
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Dismount\command]
    25
    @="\"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /u /d \"%1\""
    26
     
    27
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Mount]
    28
     
    29
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Virtual.Machine.HD\shell\Mount\command]
    30
    @="\"C:\\Program Files\\Microsoft Virtual Server\\Vhdmount\\vhdmount.exe\" /p \"%1\""
    The result is a context menu on right-clicking a .VHD file like this.

    vhdmount5

    Mounting your disk file is now as easy as a right-click away, and the VHD will show up as a new disk in Explorer.

Technet Direct Plus 3 month trial – update

Posted on February 26th, 2009 in Server 2003, Server 2008, Vista, Windows 7 by alt-92

Dutch Technet enthusiasts once again can register for a free 3 month trial of Technet Direct Plus.

[update] The offer period has expired and new entries are no longer available.
Normal subscriptions are of course still possible .

header_technet_plus

Just klick http://technet.microsoft.com/nl-nl/dd491981.aspx and enter your data, wait a couple of days for confirmation and you’ll get access to all the latest and greatest Server operating systems & software.

Prices are 370 € (ex VAT/BTW) for a full year, renewals are 270 € (ex VAT/BTW).
Technet Plus Direct means online access to the software library (download only – no CD shipments), two support calls (worth 299 €) and free e-learning courses.

For a list of available software, See the complete list on the TechNet Plus Subscriptions home page.

Diskspace checks and trend analysis

Posted on February 22nd, 2009 in Server 2003, Server 2008, Storage by alt-92

Simple Diskspace monitoring tools for home use.
Tools: VBscript & MS Access database

The script:

01
02
On Error Resume Next
03
Const HARD_DISK = 3
04
Const adOpenStatic = 3
05
Const adLockOptimistic = 3
06
 
07
strNamespace = "root\cimv2"
08
strDomain = "domain"
09
 
10
strDate = FormatDateTime(Now(), 2)
11
strTime = FormatDateTime(Now(), 4)
12
Set objNetwork = CreateObject("Wscript.Network")
13
' =====================================================================
14
arrComputers = Array("Server1","Server2","Server3")
15
 
16
For Each strComputer In arrComputers
17
Set objWMIService = GetObject("winmgmts:" &amp; strComputer &amp; "root\CIMV2")
18
Set colDisks = objWMIService.ExecQuery _
19
("SELECT * FROM Win32_LogicalDisk Where DriveType = " &amp; HARD_DISK &amp; "",,48)
20
 
21
Set objConnection = CreateObject("ADODB.Connection")
22
Set objRecordSet = CreateObject("ADODB.Recordset")
23
 
24
objConnection.Open _
25
"Provider = Microsoft.Jet.OLEDB.4.0; " &amp; _
26
"Data Source = c:\scripts\diskspace_database.mdb"
27
 
28
objRecordSet.Open "SELECT * FROM tbldiskspace" , _
29
objConnection, adOpenStatic, adLockOptimistic
30
For Each objDisk in colDisks
31
objRecordSet.AddNew
32
 
33
objRecordSet("server") = strComputer
34
objRecordSet("domain") = strDomain
35
objRecordSet("disk") = objDisk.VolumeName
36
objRecordSet("drive") = objDisk.DeviceID
37
objRecordSet("totalspace") = round(objDisk.Size /1024/1024,2)
38
objRecordSet("freespace") = round(objDisk.FreeSpace /1024/1024,2)
39
objRecordSet("percentage") = (objDisk.Freespace /objDisk.Size)*100
40
objRecordSet("date") = strDate
41
objRecordSet("time") = strTime
42
 
43
objRecordSet.Update
44
 
45
Next
46
Next
47
 
48
objRecordSet.Close
49
objConnection.Close
50
' =====================================================================
51

Access DB has a simple table layout, and a couple of queries and comboboxes.
Table:
table

Form:
form1

Using the queries and by generating a PivotTable view, it’s easy to spot growth trends on disks.
Graph showing available free space:
graph