Jump to content

Determine OS Help


noob62
 Share

Recommended Posts

Trying to get a script up and running that will identify if a server or workstation is being managed by either SCCM or KACE. I keep running into a issue where it always seems to default to workstation no matter what with the below script. I'm sure it's an easy fix I'm just missing something simple:

 

Local $SCCM, $KACE, $Type, $OS

$OS = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" , "ProductType")

If $OS = "WinNT" Then
   $Type = "Workstation"
ElseIf $OS = "ServerNT" Then
   $Type = "Server"
ElseIf $OS = "LanmanNT" Then
   $Type = "Server"
EndIf


$SCCM = RegRead("HKLM64\SOFTWARE\Microsoft\SMS\Mobile Client" , "ProductVersion")
$KACE = RegRead("HKLM64\SOFTWARE\Dell\Kace" , "Installld")

If $Type = "Workstation" & @error = 1 Then
      MsgBox(4096, "INFO" , "SCCM Client: Not Installed")
   Elseif $Type = "Server" & @error = 1 Then
      MsgBox(4096, "INFO" , "KACE Client: Not Installed")
   Elseif $Type = "Workstation" & @error <> 1 Then
      MsgBox(4096, "INFO" , "SCCM Client: Installed")
   Elseif $Type = "Server" & @error <> 1 Then
      MsgBox(4096, "INFO" , "KACE Client: Installed")
EndIf

 

Link to comment
Share on other sites

You could probably simplify your last if statement.  That section looks a bit convoluted.  You should look into using Switch or Select statements in lieu of complex if then statements.  Also, for simple "binary" if statements you can employ ternary notation.  You can also have a look at the @OS... macros (@OSVersion in particular).  Macros are built at run-time and will save time from having to do the first reg lookup.  Sure, we're probably talking milliseconds, but hey...why not save time when you can?  Sorry....tangent.

;For example only - Untested
Local $SCCM, $KACE, $Type, $OS

$OS = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" , "ProductType")

Switch $OS
    Case "WinNt"
        $Type = "Workstation"
    Case "ServerNT"
        $Type = "Server"
    Case "LanmanNT"
        $Type = "Server"
EndSwitch

Select
    Case $Type = "Workstation"
        $SCCM = RegRead("HKLM64\SOFTWARE\Microsoft\SMS\Mobile Client" , "ProductVersion")
        ;ternary operator
        MsgBox(4096, "INFO" , (@error <> 0) ? ("SCCM Client: Not Installed") : ("SCCM Client: Installed"))
    Case $Type = "Server"
        $KACE = RegRead("HKLM64\SOFTWARE\Dell\Kace" , "Installld")
        ;ternary operator
        MsgBox(4096, "INFO" , (@error <> 0) ? ("KACE Client: Not Installed") : ("KACE Client: Installed"))
EndSelect


edit: corrected malformed ternary usage
 

Edited by spudw2k
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...