Thursday, February 3, 2011

Detection Deflection Reflection

Is the client 32-bit or 64-bit?

if exist "%windir%\SysWOW64" (
    echo "64-bit"
) else (
    echo "32-bit"
)

Is the client Windows 7?


Function IsWindows7()
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & _
strComputer & "\root\CIMV2") 
    Set colItems = objWMIService.ExecQuery(_
"SELECT * FROM Win32_OperatingSystem",,48) 
    For Each objItem in colItems
        cap = objItem.Caption
    Next
    If InStr(cap, "Windows 7") > 0 Then
        IsWindows7 = True
    End If
End Function

If IsWindows7() = True Then
    wscript.echo "Windows 7!"
Else
    wscript.echo "Not Windows 7"
End If

Is the client XP or Vista/7?

if exist "%systemdrive%\ProgramData" (
   echo "Windows Vista or Windows 7"
) else (
   echo "Windows XP"
)

Before you flip out on me, YES: I know this doesn't address Windows Server 2003, 2008, 2008 R2, and ignores Windows 2000. That's fine.  Feel free to modify any of this.  I was just throwing out some quick-and-dirty examples. I don't care about Windows 2000 anyway.

No comments: