#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Illinois
    Posts
    4
    Rep Power
    0

    Need alternative to Login Script check for OS version


    Environment:
    Windows 2008 AD
    Server 2003, 2008 & 2008 R2
    XP
    Windows 7

    I am trying to get a login script that only runs on windows 7 machines. I have code that checks for version numbers, but Server 2008 R2 and Win7 use the same version numbers = 6.1

    I don't want to create a new OU if I don't have to.

    Here is the partial code in question:
    PHP Code:
    If VerBig "6.1" Then 
    // Run my code here
    Else
    WScript.Quit
    End 
    If 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    This VB code, but you can make system calls to return a lot of information about the operating system.

    J.A. Coutts
    Code:
    Option Explicit
    
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion      As Long
        dwMinorVersion      As Long
        dwBuildNumber       As Long
        dwPlatformId        As Long
        szCSDVersion        As String * 128 ' Maintenance string for PSS usage
    End Type
    
    Dim myVer As OSVERSIONINFO
    
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
    
    Private Sub Form_Load()
        Dim lRet As Long
        myVer.dwOSVersionInfoSize = 148
        lRet = GetVersionEx(myVer)
    End Sub
    
    Private Sub Form_Activate()
        Print "Major Version = " & CStr(myVer.dwMajorVersion)
        Print "Minor Version = " & CStr(myVer.dwMinorVersion)
        Print "Build Number = " & CStr(myVer.dwBuildNumber)
        Print "Platform ID = " & CStr(myVer.dwPlatformId)
        Print "CSD Version = " & myVer.szCSDVersion
    End Sub
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Illinois
    Posts
    4
    Rep Power
    0
    That looks promising! Thanks.
    I have been tinkering with this ( it looks along the same idea) and so far it seems to work. It looks like a lot of work just to get a bit of info. I'm going to play with your code too.
    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
      '  Version = Right(objOperatingSystem.Caption,17)
    	Version = Mid(objOperatingSystem.Caption,19,14)
    	'Version = objOperatingSystem.Caption
    	'Wscript.Echo Version
    	'Wscript.Echo objOperatingSystem.Caption
    Next
    			
      If Version = "7 Professional" Then
    		MsgBox"Windows 7 found", vbInformation, "Script Info Box"
    		wscript.sleep 1
    		WScript.Quit
    		
     ElseIf Version = "Server 2008 R2" Then
    		MsgBox"Windows 2008 R2 found", vbInformation, "Script Info Box"
    		wscript.sleep 1
    		WScript.Quit
    	
    ' ElseIf Version = "Server 2008 " Then
    '		MsgBox"Windows" & chr(174) & " 2008 found", vbInformation, "Script Info Box"
    '		wscript.sleep 1
    '		WScript.Quit
    		
     ElseIf Version = "ws(R) Server 2" Then
    		MsgBox"Windows 2003 found", vbInformation, "Script Info Box"
    		wscript.sleep 1
    		WScript.Quit		
    		
        Else
    	MsgBox"Your code doesn't include my OS :-(", vbInformation, "Script Info Box"
    		WScript.Quit
        End If
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Illinois
    Posts
    4
    Rep Power
    0
    Originally Posted by couttsj
    This VB code, but you can make system calls to return a lot of information about the operating system.

    J.A. Coutts
    Code:
    Option Explicit
    
    Private Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion      As Long
        dwMinorVersion      As Long
        dwBuildNumber       As Long
        dwPlatformId        As Long
        szCSDVersion        As String * 128 ' Maintenance string for PSS usage
    End Type
    
    Dim myVer As OSVERSIONINFO
    
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
    
    Private Sub Form_Load()
        Dim lRet As Long
        myVer.dwOSVersionInfoSize = 148
        lRet = GetVersionEx(myVer)
    End Sub
    
    Private Sub Form_Activate()
        Print "Major Version = " & CStr(myVer.dwMajorVersion)
        Print "Minor Version = " & CStr(myVer.dwMinorVersion)
        Print "Build Number = " & CStr(myVer.dwBuildNumber)
        Print "Platform ID = " & CStr(myVer.dwPlatformId)
        Print "CSD Version = " & myVer.szCSDVersion
    End Sub
    I couldn't get this to work. I saved this as a .vbs file, but it failed to run. Error in line 3, char 9
  8. #5
  9. No Profile Picture
    Stumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    What's the error?
    ======
    Doug G
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Illinois
    Posts
    4
    Rep Power
    0
    That's a valid question, isn't it:

    Script: [script path]
    Line: 3
    Char: 9
    Error: Expected identifier
    Code: 800A03F2
    Source: MS VBScript complication error
  12. #7
  13. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,174
    Rep Power
    1469
    Originally Posted by danh231
    I couldn't get this to work. I saved this as a .vbs file, but it failed to run. Error in line 3, char 9
    The Type keyword is not supported in VBScript.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

IMN logo majestic logo threadwatch logo seochat tools logo