#!/bin/bash
# Samba-TNG                                            get_win_version
# --------------------------------------------------------------------

# --------------------------------------------------------------------
# print usage

if [ "$2" = "" ]; then
  echo "Usage: $(basename $0) <machine> <admin-passwd>"
  exit 0
fi

# --------------------------------------------------------------------
# begin

winversion=`rpcclient -S $1 -W $1 -U Administrator%$2 -c 'regqueryval "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion"' | grep CurrentVersion|awk '{print $12}'`
resversion="unknown. cause: wrong password, nonexisting hostname or non Windows OS"

# check for WinNT (NT3)
if [ "$winversion" = "3..." ]; then
	resversion="Microsoft Windows NT 3.x"
fi

# check for WinNT (NT4)
if [ "$winversion" = "4..." ]; then
	resversion="Microsoft Windows NT 4.0"
fi

# check for Win2k (NT5)
if [ "$winversion" = "5..." ]; then
	resversion="Microsoft Windows 2000"
fi

echo "Operating System is $resversion. (Host=$1)"

exit 0

# --------------------------------------------------------------------
