Sign in to follow this  
Followers 0
aseitz

Refresh a form

11 posts in this topic

#1 ·  Posted (edited)

I have created a form with fields that are populated through registry reads. The form can be edited and saved. There are 2 buttons at the bottom my form, a "Save" button that saves the fields back to the registry and a "Discard" button that is supposed to reset the form back to the registry values.

I am unable to reset the display of the form, I just can't quite figure it out. I have the new values for the GuiCrtrlInput fields read in and ready to go.

Here is the function I am stumped on:

;################################################################################
; Function RefreshRegView
;################################################################################
; Refresh the Computer Tab view
Func RefreshRegView()
GetRegValues()
GUISetState()
EndFunc ;==> End RefreshRegView()

This should be simple, right? I have searched Help and the Forums, but I must be missing the answer.

Thanks in advance. :)

Edited by aseitz

Share this post


Link to post
Share on other sites



Could you please post the whole script? With the posted snippet it is impossible to see where the problem is.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Pasted

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=ITHelp.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Added conditional include to fix windows xp -- (Build: 1300) -- Adam Seitz 11/07/2012
Global $CheckUAC = 0
$CheckUAC = RegRead("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem", "EnableLUA")
If $CheckUAC > 0 Then
#RequireAdmin ; Added UAC Support -- (Build: 1203) -- Adam Seitz 10/12/2012
EndIf

#Include <AD.au3>
#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIListView.au3>
#Include <GuiStatusBar.au3>
#Include <INet.au3>
#Include <Process.au3>
#Include <WindowsConstants.au3>

; *********************************************************************************************************
; File........: ITHelp.au3
; Author......: Adam Seitz (aseitz@pps.net)
; Auto IT.....: 3.3.8.1
;
; Purpose: To help End Users get help and support quickly and easily.
; *********************************************************************************************************
;Tray Icon (0=show, 1=hide)
Opt("TrayIconHide", 1)

; Version Info
Global $PPSVersion = "v1.3"
Global $PPSBuild = "1305"
Global $PPSDate = "11/15/2012"
Global $PPSTitle = "IT Help"

; User Interface Window Formatting and Handling
Global $GUIImages = @ScriptDir & "images", $GUIFont = "Arial", $GUIFontSize = 8.5, $GUIBackGroundColor = "0xFFFFFF"
Global $GUIEvent_1, $GUIEvent_2

; Buttons
Global $Button_1, $Button_2, $Button_3, $Button_4, $Button_5, $Button_6, $Button_7, $Button_8

; Hardware Info
Global $HDDVolume, $HDDSerial, $HDDTotal, $HDDFree

; Labels
Global $Label_Row_Offset = 25, $Label_Col_Offset = 25, $Label_Length = 200, $Label_Height = 20
Global $Data_Row_Offset = 165, $Data_Col_Offset = 25, $Data_Length = 300, $Data_Height = 20

; Tabs
Global $Tab_1, $Tab_2, $Tab_3, $Tab_4, $Tab_5, $Tab_6

; Labels / Input Fields
Global $Input_ComputerName, $Input_CurrentUserName, $Input_OperatingSystem, $Input_DomainStatus
Global $Input_ServicePack, $Input_VolumeLabel, $Input_SerialNumber, $Input_TotalSpace, $Input_FreeSpace, $Input_IpAddress, $Input_StartupDirectory
Global $Input_WindowsDirectory, $Input_SystemFolderDirectory, $Input_DesktopDirectory, $Input_MyDocumentsDirectory, $Input_ProgramFilesDirectory
Global $Input_StartMenuDirectory, $Input_TemporaryFileDirectory, $Input_DesktopWidth, $Input_DesktopHeight, $Input_Date, $Input_Time, $SafeMode = 0
Global $Input_RoomNumber, $Input_PurchaseOrder, $Input_ManagedBy

; Registry Reading Variables
Global $PPS_Key, $Reg_RoomNumber, $Reg_PurchaseOrder, $Reg_ManagedBy


; Printers tab
Global $aLocalPrinters[1][4], $ListView, $Selection

; Arbitrary Variables
Global $Meridian = "AM"

; Network Setup Variables
Global $DNSD = "ad.ppsnet", $DNSR = True, $IPAddressCount = 0

; WMI Variables
Global $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $WMICheck=1, $WMI_Repair_Path

; Check for WMI Errors
Global $objWMIService = ObjGet('winmgmts:' & @ComputerName & 'rootCIMV2')
if @error then
$WMICheck=2
If IsObj($objWMIService) then
$WMICheck = 1
EndIf
EndIf

;################################################################################
; Function GetRegValues()
;################################################################################
; This is the function that reads the PPS custom reg values.
Func GetRegValues()
; Set Registry Path to PPS Key
If @OsArch = "X64" Then
$PPS_Key = 'HKLM64SoftwarePPS'
Else
$PPS_Key = 'HKLMSoftwarePPS'
EndIf

$Reg_RoomNumber = RegRead($PPS_Key,'RoomNumber')
$Reg_PurchaseOrder = RegRead($PPS_Key,'PurchaseOrder')
$Reg_ManagedBy = RegRead($PPS_Key,'ManagedBy')

EndFunc ;<== End GetRegValues()

;################################################################################
; Function SetRegValues()
;################################################################################
; This is the function that writes the PPS custom registry values.
Func SetRegValues()
Local $value

; RoomNumber Value
$value = GUICtrlRead($Input_RoomNumber)
RegWrite($PPS_Key, 'RoomNumber', 'REG_SZ', $value)

; PurchaseOrder Value
$value = GUICtrlRead($Input_PurchaseOrder)
RegWrite($PPS_Key, 'PurchaseOrder', 'REG_SZ', $value)

; ManagedBy Value
$value = GUICtrlRead($Input_ManagedBy)
RegWrite($PPS_Key, 'ManagedBy', 'REG_SZ', $value)

EndFunc ;<== End SetRegValues()

;################################################################################
; Function RefreshRegView
;################################################################################
; Refresh the Computer Tab view
Func RefreshRegView()

GetRegValues()
GUISetState()

EndFunc ;==> End RefreshRegView()

;################################################################################
; Function WMIStringToDate($dtmDate)
;################################################################################
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2) & " on: " & StringMid($dtmDate, 5, 2) & "/" & StringMid($dtmDate, 7, 2) & "/" & StringMid($dtmDate, 1, 4))
EndFunc ;==>WMIDateStringToDate

;################################################################################
; Function __StringToDate($dtmDate)
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func __StringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc ;<== End __StringToDate()

;################################################################################
; Function RestartPrint()
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func RestartPrint()
RunWait(@ComSpec & " /c " & 'start /wait /min net stop "Print Spooler"', @WindowsDir, @SW_HIDE)
RunWait(@ComSpec & " /c " & 'start /wait /min net start "Print Spooler"', @WindowsDir, @SW_HIDE)
EndFunc ;<== End RestartPrint()

;################################################################################
; Function GetLocalPrinters()
;################################################################################
; Get Locally Installed Printers
Func GetLocalPrinters()

; Delete Array if it aleady exists
If $aLocalPrinters[0][0] > 0 Then
; Reintalize the array
Dim $aLocalPrinters[1][4]
EndIf

Local $ctr = 1
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
For $objItem In $colItems
ReDim $aLocalPrinters[UBound($aLocalPrinters) + 1][4]
$aLocalPrinters[$ctr][0] = $objItem.Name
$aLocalPrinters[$ctr][1] = $objItem.Default
$aLocalPrinters[$ctr][2] = $objItem.Comment
$aLocalPrinters[$ctr][3] = "Local"

; Check if Printer is Networked or Not
If StringinStr($aLocalPrinters[$ctr][0],"ipp://") Then
$aLocalPrinters[$ctr][3] = "iPrint"
ElseIf StringinStr($aLocalPrinters[$ctr][0],"") Then
$aLocalPrinters[$ctr][3] = "Networked"
Endif

$ctr += 1
Next
$aLocalPrinters[0][0] = UBound($aLocalPrinters) - 1
If $aLocalPrinters[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aLocalPrinters)

EndFunc ;==>GetLocalPrinters()

;################################################################################
; Function DeletePrinter()
;################################################################################
Func DeletePrinter()
; If the printer is a network printer, never use this type of delete
If Not StringinStr($Selection, "") Then
; Delete Local
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dl /n "' & $Selection & '"', "", @SW_HIDE)
EndIf

; Delete Network
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dn /n "' & $Selection & '"', "", @SW_HIDE)

; Delete Per-Machine
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /gd /n "' & $Selection & '"', "", @SW_HIDE)

EndFunc ;==> End DeletePrinter()

;################################################################################
; Function GetMemoryBanks()
;################################################################################
; Returns number of banks regardless of whether there is memory installed
Func GetMemoryBanks()
Local $colMemory = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemoryArray")

For $objMemory in $colMemory
Return ($objMemory.MemoryDevices)
Next
EndFunc ;==> End GetMemoryBanks()

;################################################################################
; Function GetMemoryInfo()
;################################################################################
; Get Memory information
Func GetMemoryInfo()
Local $aMemoryInfo[1][6], $ctr = 1
Local $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemory")

; Preform Query
If IsObj($colItems) Then
For $objItem In $colItems
; This fixes the HP 5700, since it had a ROM that was type "0"
; and messing up the array Build 1100 AS 2/6/12
If $objItem.FormFactor > "0" Then
ReDim $aMemoryInfo[UBound($aMemoryInfo) + 1][6]
$aMemoryInfo[$ctr][0] = $objItem.BankLabel
$aMemoryInfo[$ctr][1] = $objItem.Name
$aMemoryInfo[$ctr][2] = $objItem.Capacity
$aMemoryInfo[$ctr][3] = $objItem.FormFactor
$aMemoryInfo[$ctr][4] = $objItem.MemoryType
$aMemoryInfo[$ctr][5] = $objItem.Speed
EndIf
$ctr += 1
Next
$aMemoryInfo[0][0] = UBound($aMemoryInfo) - 1
If $aMemoryInfo[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aMemoryInfo)
EndFunc ;==>GetMemoryInfo()

;################################################################################
; Function RefreshListView
;################################################################################
; Refreshs the ListView
Func RefreshListView()
Local $ctr = 1

; Clean Up Existing ListView
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))

; Build Repopulate ListView
_GUICtrlListView_AddArray(GUICtrlGetHandle($ListView), $aLocalPrinters)

; Delete first element since it shows the count
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListView), 0)

While $ctr <= $aLocalPrinters[0][0]
; Printer Name
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 0, $LVSCW_AUTOSIZE)

; Is Printer Default? (Yes / No)
If $aLocalPrinters[$ctr][1] = True Then
_GUICtrlListView_SetItemSelected(GUICtrlGetHandle($ListView), $ctr - 1)
EndIf
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 1, $LVSCW_AUTOSIZE_USEHEADER)

; Printer Caption
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 2, $LVSCW_AUTOSIZE)

; Printer Type
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 3, $LVSCW_AUTOSIZE)

$ctr += 1
WEnd
Return($ListView)
EndFunc ;==> End RefreshListView()

; *********************************************************************************************************
; Check WMI Health
; *********************************************************************************************************
; WMI error - Lets try to fix it
If $WMICheck = 2 Then
; Only works on Windows XP Pro 32-Bit
If @OSVersion = "WIN_XP" And @OSArch = "x86" Then
$WMI_Repair_Path = @WindowsDir & 'ServicePackFilesI386'

; If admin then fix stuff
If IsAdmin() Then
; WMI is busted, notify the user.
ProgressOn("WMI Repair","WMI Repair","Repairing Local WMI Database", -1, -1, 16)
If FileExists($WMI_Repair_Path) Then

ProgressSet( 90, "Stopping SMS Agent Service")
RunWait('net stop ccmexec')

ProgressSet( 15, "Stopping Firewall/ICS Service")
RunWait('net stop sharedaccess')

ProgressSet( 30, "Stopping WMI Service")
RunWait('net stop winmgmt')

ProgressSet( 45, "Removing Corrupt WMI Database")
DirRemove(@WindowsDir & 'System32WbemRepository', 1)

ProgressSet( 60, "Rebuilding Clean WMI Database")
RunWait('winmgmt /resetRepository')

ProgressSet( 90, "Starting SMS Agent Service")
RunWait('net start ccmexec')

ProgressSet( 90, "Starting Firewall/ICS Service")
RunWait('net start sharedaccess')

ProgressSet( 75, "Starting WMI Service")
RunWait('net start winmgmt')

Sleep(10000)
Else
; We Failed, lets mark it with a "1" and use that for safe-mode
$SafeMode = 1
EndIf
Else
$SafeMode = 1
EndIf
ProgressOff()
Else
$SafeMode = 1
EndIf
EndIf

; *********************************************************************************************************
; Get Remotely Available Printers
; *********************************************************************************************************
If $SafeMode = 0 Then
; Adding Build version to initial load screen -- (Build: 1301) -- Adam Seitz 11/07/2012
ProgressOn( "IT Help Tool " & $PPSVersion & " (Build: " & $PPSBuild & ")","IT Help Tool Loading...","Loading", -1, -1, 16)
ProgressSet( 0, "Detecting Print Server Name")

Global $PercentDone, $PrintServer, $aPrintQueues, $aPrintDetails[1][1], $aIPAddress, $aIPAddress1, $aIPAddress2, $aIPAddress3, $aIPAddress4, $aTemp1, $aTemp2

; Initialize TCP Functionality
TCPStartup()

; Open Connection to the Active Directory
If _AD_Open() Then

; Grab All IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
$aIPAddress1 = StringSplit(@IPAddress1, ".")
$aIPAddress2 = StringSplit(@IPAddress2, ".")
$aIPAddress3 = StringSplit(@IPAddress3, ".")
$aIPAddress4 = StringSplit(@IPAddress4, ".")

; Count IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
If $aIPAddress1[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress2[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress3[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress4[1] > 0 Then
$IPAddressCount += 1
EndIf

; Evaluate IP Addresses to determine if one is a PPS address
For $ctr = 1 to $IPAddressCount Step 1
; Set $aIPAddress to current IP Address
If $ctr = 1 Then
$aIPAddress = $aIPAddress1
ElseIf $ctr = 2 Then
$aIPAddress = $aIPAddress2
ElseIf $ctr = 3 Then
$aIPAddress = $aIPAddress3
ElseIf $ctr = 4 Then
$aIPAddress = $aIPAddress4
EndIf

; Assign Print Server Based on IP Address at some sites and discovery at the others.
If $aIPAddress[1] = "159" Then
;WNPRINT is not a standard address nor are the clients
$PrintServer = _TCPIpToName ('10.128.10.119')

; Added 127 (Build: 1203) -- Adam Seitz 10/11/2012
ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "127") Then
$PrintServer = _TCPIpToName ('10.128.10.119')

ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "128") Then
$PrintServer = _TCPIpToName ('10.128.10.119')
Else
;<SITE>-PRINT is a standard naming convention, all servers use IP 10.<site>.8.7
; So by using the clients first two octets and appending 8.7 we get a valid ip to
; use as the print server.
$PrintServer = _TCPIpToName ( $aIPAddress[1] & '.' & $aIPAddress[2] & '.8.7' )
If @error Then
$PrintServer = False
EndIf
EndIf
Next

If Not $PrintServer = False Then
ProgressSet( 0, "Counting Printers on: " & $PrintServer & ".ad.ppsnet")

; The Name returned by _TCPIpToName() is FQDN we need a simple name.
$aTemp1 = StringSplit($PrintServer, ".")
$PrintServer = $aTemp1[1]

; Get a list of all PrintQueues in the AD tree
$aPrintQueues = _AD_ListPrintQueues($PrintServer)

; Verify the Returned Printers is actually valid
If Not IsArray($aPrintQueues) Then
$PrintServer = False
Else

; Order list by alphabet
_ArraySort($aPrintQueues)

; Get Printer Details
For $i = 1 to $aPrintQueues[0][0] Step 1
; Calculate Remaining Percentage of Bar
$PercentDone = (100 / $aPrintQueues[0][0]) * $i
ProgressSet( $PercentDone, "Querying Printer " & $i & " of " & $aPrintQueues[0][0] & ": " & $aPrintQueues[$i][0])

; Build Array
Redim $aPrintDetails[UBound($aPrintDetails) + 1][1]
$aTemp2 = _AD_GetObjectProperties($aPrintQueues[$i][2])
$aPrintDetails[$i][0] = $aTemp2[2][1]
Next
EndIf
; Close Connection to the Active Directory
_AD_Close()
EndIf
Else
$PrintServer = False
EndIf

; Close Progress Bar
ProgressOff()

; Turn off TCP Service to prevent Memory Leak
TCPShutdown()
EndIf

; *********************************************************************************************************
; Get CPU Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Cpu_Core = 0, $Cpu_Arc, $Temp
Global $Cpu_Name = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","ProcessorNameString")
Global $Cpu_Clock = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","~MHz")

; Format CPU Information as Human Readable
If (@CPUArch = "X86") Then
$Cpu_Arc = "32-Bit"
ElseIf (@CPUArch = "X64") Then
$Cpu_Arc = "64-Bit"
Else
$Cpu_Arc = @CPUArch
EndIf

For $i= 1 to 1000
$Temp = RegEnumKey("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor", $i)
If @error <> 0 then
ExitLoop
EndIf
$Cpu_Core += 1
Next
EndIf

; *********************************************************************************************************
; Get MEM Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $aMemoryInfo[1][100], $Mem_Num, $Mem_Text, $Mem_Percentage, $Mem_Readable, $Mem_Banks, $colMemory
Global $Readable_FormFactor[24] = ["Unknown","Other", "SIP","DIP","ZIP","SOJ","Proprietary","SIMM","DIMM","TSOP","PGA","RIMM","SODIMM","SRIMM","SMD","SSSMP","QFP","TQFP","SOIC","LCC","PLCC","BGA","FPBGA","LGA"]
Global $Readable_MemoryType[22] = ["Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM","RAM","ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR-2"]
Global $Mem_Count = 0, $Mem_Raw = MemGetStats()

; Clean Up the Text returned so it is presented a bit more readable
If ($Mem_Raw[1] > 0) and ($Mem_Raw[1] < 1000) Then
$Mem_Num = $Mem_Raw[1]
$Mem_Text = " KB"
ElseIf ($Mem_Raw[1] > 1000) and ($Mem_Raw[1] < 100000) Then
$Mem_Num = $Mem_Raw[1] /1024
$Mem_Text = " MB"
Else
$Mem_Num = $Mem_Raw[1] / 1024 / 1024
$Mem_Text = " GB"
EndIf

; Round Cleaner Number for final display text
$Mem_Percentage = $Mem_Raw[0]
$Mem_Readable = Round($Mem_Num, 2) & $Mem_Text

; Get Number of Physical Memory Banks on this motherboard
$aMemoryInfo = GetMemoryInfo()

; Get Number of Physical Memory Banks on this motherboard
$Mem_Banks = GetMemoryBanks()

EndIf

; *********************************************************************************************************
; Get HDD Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$HDDVolume = DriveGetLabel("C:")
$HDDSerial = DriveGetSerial("C:")
$HDDTotal = DriveSpaceTotal("C:")
$HDDFree = DriveSpaceFree("C:")
Global $HDD_Percentage = Round(( $HDDFree / $HDDTotal ) * 100)
EndIf

; *********************************************************************************************************
; Get Uptime
; *********************************************************************************************************
If $SafeMode = "0" Then
Global $LastBootUp, $LocalDateTime, $colItems
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$LastBootUp = WMIDateStringToDate($objItem.LastBootUpTime)
$LocalDateTime = WMIDateStringToDate($objItem.LocalDateTime)
Next
EndIf
EndIf

; *********************************************************************************************************
; Get Domain Membership
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $DOM_Hover, $DOM_Status = "No"
$colItems = $objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem")
For $obj In $colItems
If $obj.DomainRole = 1 Then
$DOM_Status = "Yes"
$DOM_Hover = "Machine is joined to Domain"
EndIf
Next
EndIf

; *********************************************************************************************************
; Get Network Card Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Network_Card[1][50], $Network_Card_Count = 0

$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
$i = 1

If IsObj($colItems) Then
For $obj In $colItems
ReDim $Network_Card[UBound($Network_Card) + 1][50]
$Network_Card[$i][0] = $obj.Description
$Network_Card[$i][1] = $obj.DHCPEnabled
$Network_Card[$i][2] = $obj.MACAddress
$i += 1
Next
$Network_Card[0][0] = UBound($Network_Card) - 1
If $Network_Card[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf
EndIf

; *********************************************************************************************************
; Create Human Readable Information
; *********************************************************************************************************
Global $WINVER
If (@OSVersion = "WIN_2000") Then
$WINVER = "Windows 2000"
ElseIf (@OSVersion = "WIN_7") Then
$WINVER = "Windows 7"
ElseIf (@OSVersion = "WIN_8") Then ; -- (Build: 1203) -- Adam Seitz 10/12/2012
$WINVER = "Windows 8"
ElseIf (@OSVersion = "WIN_XP") Then
$WINVER = "Windows XP"
Else
$WINVER = @OSVersion
EndIf

; Set Windows Service Pack to Human Readable
Global $WINSPK = @OSServicePack

; Evaluate (and make human readable) the service pack level -- (Build: 1203) -- Adam Seitz 10/12/2012
If (IsString($WINSPK)) Then
$aTemp1 = StringSplit($WINSPK, " ")
If($aTemp1[1] = "Service") Then
$WINSPK = @OSServicePack
Else
$WINSPK = "Release"
EndIf
EndIf

; *********************************************************************************************************
; Get VNC Status
; *********************************************************************************************************
Global $VNC_Hover, $VNC_Status

If ProcessExists("tvncserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
ElseIf ProcessExists("tvnserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
Else
$VNC_Status = "Not Available"
$VNC_Hover = "Service is not running or application is not installed."
EndIf

; *********************************************************************************************************
; Get RDP Status
; *********************************************************************************************************
Global $RDP_Hover, $RDP_Status, $RDP_Check = RegRead("HKLMSYSTEMCurrentControlSetControlTerminal Server", "fDenyTSConnections")

; Check the Registry for Enable / Disable of RDP
; 0 = Available
; 1 = Disabled
If $RDP_Check = "0" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
Else
$RDP_Check = "Not Available"
$RDP_Hover = "Service is Not Running"
EndIf

; If Machine is on Domain the Registry key is not used any more, GPO sets it.
If $SafeMode = 0 And $DOM_Status = "Yes" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
EndIf

; If Machine is on Windows 2000, then RDP does not exist.
If (@OSVersion = "WIN_2000") Then
$RDP_Status = "Not Available"
$RDP_Hover = "Windows 2000 does not support RDP."
EndIf

; *********************************************************************************************************
; Get Absolute Manage Status
; *********************************************************************************************************
Global $ABS_Status, $ABS_Hover_1, $ABS_Hover_2, $ABS_File, $ABS_Ver

; See if it is installed
If FileExists(@ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe") Then
$ABS_File = @ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe"
$ABS_Ver = RegRead("HKLMSOFTWAREPole Position SoftwareLANrev Agent","AgentVersion")
Else
$ABS_File = 0
$ABS_Ver = 0
EndIf

; Windows 2000 Only
If @OSVersion = "WIN_2000" Then
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
EndIf

; Windows XP and later
Else
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5 requires an upgrade to function."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 requires an update to function"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1"
$ABS_Status = "Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3"
$ABS_Status = "Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3"
$ABS_Status = "Available"
EndIf
EndIf

; Determine if process is running
If ProcessExists("LANrev Agent.exe") Then
$ABS_Status = "Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Running"
Else
$ABS_Status = "Not Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Not Running."
EndIf

; *********************************************************************************************************
; Get Microsoft Forefront Status
; *********************************************************************************************************
Global $FEP_Status, $FEP_Hover

; Determine if process is running
If ProcessExists("MsMpEng.exe") Then
$FEP_Status = "Available"
$FEP_Hover = " Process is Running"
Else
$FEP_Status = "Not Available"
$FEP_Hover = " Process is Not Running."
EndIf

; *********************************************************************************************************
; Create Window
; *********************************************************************************************************
Global $MainGUI, $AddPrinterGUI, $AddPrinterExit, $AddPrinterList

$MainGUI = GuiCreate($PPSTitle & " - " & $PPSVersion & " (Build: " & $PPSBuild & ")", 500, 400) ; Window Style
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon
GUISetBkColor($GUIBackGroundColor)
GuiCtrlCreatePic($GUIImages & "Support_Info.jpg",0,0, 500, 100)

; Set Font Back to Larger for Banner
GUISetFont(12,0,0, $GUIFont)
GUICtrlCreateLabel("Computer Name:", 110, 10, 300, 20)

; Bold + Underline Computer Name
GUISetFont(12,400, 4, $GUIFont)
GUICtrlCreateLabel(@ComputerName, 235, 10, 300, 20)

; Back to Larger Font - No Underline or Bold
GUISetFont(12, 0, 0, $GUIFont)
GUICtrlCreateLabel("* Primary IP Address: " & @IPAddress1, 110, 40, 300, 20)

If @IPAddress2 > 0 Then
GUICtrlCreateLabel("* Secondary IP Address: " & @IPAddress2, 110, 60, 300, 20)
EndIf

; Set Font Back to Regular
GUISetFont($GUIFontSize, 0, 0, $GUIFont)

; *********************************************************************************************************
; Create Tabbed User Window (Below Banner)
; *********************************************************************************************************
Global $Col_Num, $Row_Num, $tabbed, $hTab
$tabbed = GUICtrlCreateTab(5, 100, 490, 295)
$hTab = GUICtrlGetHandle($tabbed) ; get the handle for use in the notify events
If $SafeMode = 0 Then
GUICtrlCreateLabel( "",304,97,195,23) ; A blank White label to cover the tab ui grey'd background
Else
GUICtrlCreateLabel( "    IT Help Is Running In Safemode",125,97,370,23) ; A blank White label to cover the tab ui grey'd background
EndIf
; *********************************************************************************************************
; Tab 1: Support Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_1 = GUICtrlCreateTabItem("Support")
Else
$Tab_1 = GUICtrlCreateTabItem("SAFE MODE: Enabled")
If IsAdmin() Then
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "Rebooting your computer may clear this up.")
Else
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "An Attempt to fix it was made but you are not an Administrator on this machine.")
EndIf
EndIf

; Row 1: Contact Information
$Row_Num = 5.1
GUICtrlCreateLabel("Service Desk Phone:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("(503) 916-3375", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 2: Contact Information
$Row_Num = 6.1
GUICtrlCreateLabel("Service Desk Email:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("itservicedesk@pps.net", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 3: Buttons
$Row_Num = 7.1
$Button_1 = GuiCtrlCreateButton("IT Homepage", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length-50, $Label_Height)
GuiCtrlSetTip(-1, '[url="http://www.pps.net/departments/information-technology"]http://www.pps.net/departments/information-technology[/url]')

; Group 1: Left Column
GuiCtrlCreateGroup("Vital Signs", 10, 200, 200, 150)

; Column 1 - 1: VNC Service
$Col_Num = 1
$Row_Num = 8.9
GUICtrlCreateLabel("VNC Remote Control:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $VNC_Hover)
If $VNC_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 2: RDP Service
$Col_Num = 1
$Row_Num = 9.9
GUICtrlCreateLabel("Remote Desktop Protocol:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $RDP_Hover)
If $RDP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 3: Domain Check
$Row_Num = 10.9
$Col_Num = 1
GUICtrlCreateLabel("Domain Status:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlSetTip(-1, $DOM_Hover)
If $DOM_Status = "Yes" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf
EndIf

; Column 1 - 4: Absolute Manage Client
$Row_Num = 11.9
$Col_Num = 1
GUICtrlCreateLabel("Absolute Manage Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $ABS_Hover_2)
If $ABS_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 5: Microsoft Forefront Endpoint Protection
$Row_Num = 12.9
$Col_Num = 1
GUICtrlCreateLabel("Forefront Endpoint Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $FEP_Hover)
If $FEP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Group 2: Right Column
GuiCtrlCreateGroup("System Information", 210, 200, 275, 150)

; Column 2 - 1: Last Rebooted Information
$Row_Num = 8.9
$Col_Num = 190
GUICtrlCreateLabel("Last Rebooted:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($LastBootUp, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 2: Processor Information
$Row_Num = 9.9
$Col_Num = 190
GUICtrlCreateLabel("Processor is a:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Cpu_Arc & " (" & $Cpu_Core & " Core): " & Round($Cpu_Clock / 1000, 2) & " GHz", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 3: Memory Information
$Row_Num = 10.9
$Col_Num = 190
GUICtrlCreateLabel("Memory:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Mem_Readable & " (" & $Mem_Percentage & "% Used)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 4: Drive Free Space
$Row_Num = 11.9
$Col_Num = 190
GUICtrlCreateLabel("Free Space:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput("" & Round($HDDFree /1024,1) & " GB" & " (" & $HDD_Percentage & "% Free)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 5: Print Server
$Row_Num = 12.9
$Col_Num = 190
GUICtrlCreateLabel("Print Server:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($PrintServer, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; *********************************************************************************************************
; Tab 2: Computer Information
; *********************************************************************************************************
If $SafeMode = 0 Then

; Read in the Registry Values
GetRegValues()

$Tab_2 = GUICtrlCreateTabItem("Computer")

; Row 1: Room Number
$Row_Num = 5.1
GUICtrlCreateLabel("Room Number:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_RoomNumber = GUICtrlCreateInput("" & $Reg_RoomNumber, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: Purchase Order
$Row_Num = 6.1
GUICtrlCreateLabel("Purchase Order:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_PurchaseOrder = GUICtrlCreateInput("" & $Reg_PurchaseOrder, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Managed By
$Row_Num = 7.1
GUICtrlCreateLabel("Managed By:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_ManagedBy = GUICtrlCreateInput("" & $Reg_ManagedBy, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 14: Buttons
$Row_Num = 14.2

; Row 14: Button 7: Save Changes
$Button_7 = GuiCtrlCreateButton("Save", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Save changes to above fields.')
If IsAdmin() = False Then
GUICtrlSetState($Button_7, $GUI_DISABLE)
EndIf

; Row 14: Button 8: Discard Changes
$Button_8 = GuiCtrlCreateButton("Discard", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Discard Changes and reload default settings.')

EndIf

; *********************************************************************************************************
; Tab 3: Print Manager
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_6 = GUICtrlCreateTabItem("Printer")
Global $answer, $Command, $Radio, $Combo, $ComboBox, $Input_PrintServer, $Input_DefaultPrinter

; Progress Bar Window position centered, near bottom.
Global $iGuiHeight = 100
Global $iGuiWidth = 100
Global $iGuiXPos = (@DesktopWidth/2)-$iGuiWidth-50
Global $iGuiYPos = (@DesktopHeight/2)-$iGuiHeight/2

; List All Printers
$Row_Num = 5.1

$ListView = GUICtrlCreateListView( "Name|Default|Description|Type", 9, 124, 479, 220, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

; Get List of Installed Printers
$aLocalPrinters = GetLocalPrinters()

; Display the Printers on the ListView
RefreshListView()

$Row_Num = 14.2
; Button: Delete Selected Printer
$Button_2 = GuiCtrlCreateButton("Delete Printer", $Label_Row_Offset + 360, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Deletes Highlighted Printer.')
GUICtrlSetState($Button_2, $GUI_DISABLE)

; Button: Add Printers
$Button_3 = GuiCtrlCreateButton("Add Printer", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Add a new printer.')
If $PrintServer = False Then
GUICtrlSetState($Button_3, $GUI_DISABLE)
EndIf

; Button: Make Default
$Button_4 = GuiCtrlCreateButton("Set Default", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Sets Highlighted Printer as Default Machine Printer.')

EndIf

; *********************************************************************************************************
; Tab 4: User Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_3 = GUICtrlCreateTabItem("User")

; Row 1: Current User Name
$Row_Num = 5
GUICtrlCreateLabel("User Name:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_CurrentUserName = GUICtrlCreateInput("" & @UserName, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: My Documents
$Row_Num = 6
GUICtrlCreateLabel("My Documents:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_MyDocumentsDirectory = GUICtrlCreateInput("" & @MyDocumentsDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Desktop Directory
$Row_Num = 7
GUICtrlCreateLabel("Desktop Directory: ", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_DesktopDirectory = GUICtrlCreateInput("" & @DesktopDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 4: Start Menu Directory
$Row_Num = 8
GUICtrlCreateLabel("Start Menu Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_StartMenuDirectory = GUICtrlCreateInput("" & @StartMenuDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 5: Temporary File Directory
$Row_Num = 9
GUICtrlCreateLabel("Temporary File Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_TemporaryFileDirectory = GUICtrlCreateInput("" & @TempDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)
EndIf

; *********************************************************************************************************
; Tab 5: Network Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_4 = GUICtrlCreateTabItem("Network")
$Row_Num = 5

For $i = 1 to $Network_Card[0][0]
GuiCtrlCreateLabel($Network_Card[$i][0], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * MAC Address: " & $Network_Card[$i][2], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * DHCP Enabled: " & $Network_Card[$i][1], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 1
Next
EndIf

; *********************************************************************************************************
; Tab 6: Memory Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_5 = GUICtrlCreateTabItem("Memory")
$Row_Num = 5.1
Global $Mem_Temp
GuiCtrlCreateLabel($aMemoryInfo[0][0] & " of " & $Mem_Banks & " Memory Banks Used", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
For $i = 1 to $Mem_Banks Step 1
$Row_Num += 1
If $i > $aMemoryInfo[0][0] Then
$Mem_Temp = "[ BANK " & $i & "] is Empty"
Else
$Mem_Temp = "[ BANK " & $i & "] " & $aMemoryInfo[$i][2] / 1024 / 1024 & " MB "& $Readable_MemoryType[$aMemoryInfo[$i][4]]& " " & $Readable_FormFactor[$aMemoryInfo[$i][3]] & " Running at "& $aMemoryInfo[$i][5] & " MHz"
EndIf
GuiCtrlCreateLabel($Mem_Temp, $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
Next
EndIf

; *********************************************************************************************************
; Show / Update the GUI
; *********************************************************************************************************
GuiSetState(@SW_SHOW)

; End Tabbing
GUICtrlCreateTabItem("")

; Run the GUI until the dialog is closed
While 1
$GUIEvent_1 = GUIGetMsg()
Select
; Window Closed with "Close" window control
Case $GUIEvent_1 = $GUI_EVENT_CLOSE
ExitLoop

; BUTTON_1: Link Button on "Support" Tab
Case $GUIEvent_1 = $Button_1
Run(@ProgramFilesDir & "Internet Exploreriexplore.exe [url="http://www.pps.net/departments/information-technology/"]http://www.pps.net/departments/information-technology/"[/url])

; BUTTON_2: Delete Selected Printer on "Print" Tab
Case $GUIEvent_1 = $Button_2 And $SafeMode = 0 ; <---- Delete printers by check box
If IsAdmin() Then
For $i = 1 to $aLocalPrinters[0][0] Step 1
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]
EndIf
Next
$answer = MsgBox(BitOr(0x4, 0x20),"Delete Printers","Are you sure you want to delete: " & $Selection)
If $answer = "6" Then
; Begin progress bar
ProgressOn("Deleting Printer","Removing: " & $Selection,"Removing", -1, -1, 16)
ProgressSet(25, "Removing: " & $Selection)

; Delete the printer for all of the places in the registry it is possible to see it installed
DeletePrinter()

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 75 to 100 Step 5
Sleep(1000) ;1 Second
ProgressSet($i, "Updating System")
Next

; Update UI
ProgressSet(100, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressOff()

EndIf
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_7: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_7 And $SafeMode = 0
MsgBox(0,"Save","Saved changes")
; Update UI
ProgressSet(100, "Refreshing Window")
SetRegValues()
RefreshRegView()
ProgressOff()

; BUTTON_8: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_8 And $SafeMode = 0
MsgBox(0,"Discard","Discarded changes")
; Update UI
ProgressSet(100, "Refreshing Window")
GetRegValues()
RefreshRegView()
ProgressOff()

; BUTTON_3: Add a Printer on "Print" Tab
Case $GUIEvent_1 = $Button_3 And $SafeMode = 0
If IsAdmin() Then
; Build Add Printer Wizard GUI
$AddPrinterGUI = GUICreate( "Add Printer Wizard", 350, 110, -1, -1)
GuiCtrlCreateLabel($PrintServer & ".ad.ppsnet", 5, 5, 100, $Label_Height)
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon

; Drop-Down Listbox of Printers
$ComboBox = GUICtrlCreateCombo("", 25, 25, 300, 30) ; create first item

; Loop to populate listBox with printers from the printer queue
For $i = 1 to $aPrintQueues[0][0] Step 1
GUICtrlSetData($ComboBox, $aPrintQueues[$i][0])
Next

; BUTTON_5: Exit Button on "Print" Tab -> Add Printer Wizard
$Button_5 = GUICtrlCreateButton("Exit", 160, 65, 100, 30)
GuiCtrlSetTip(-1, 'Exits the Add Printer Wizard')

; INSTALL Button
$Button_6 = GUICtrlCreateButton("Install", 50, 65, 100, 30)
GuiCtrlSetTip(-1, 'Installs the Selected Printer')

; Set GUI Visible and disable the install printer button
GUISetState(@SW_SHOW)
GUICtrlSetState($Button_6, $GUI_DISABLE)

; Loop until exited
While 2

; Update $GUIEvent_2 with whatever has happened since last loop
$GUIEvent_2 = GUIGetMsg()

; Switch on $GUIEvent_2 messages for work to be done.
Select
; Close Window was clicked
Case $GUIEvent_2 = $GUI_EVENT_CLOSE And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; Exit Button was Clicked
Case $GUIEvent_2 = $Button_5 And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; ComboBox was Updated
Case $GUIEvent_2 = $ComboBox And $SafeMode = 0
$Selection = GUICtrlRead($ComboBox)

; If the Selection was BLANK it's not valid
If Not $Selection = "" Then
If GUICtrlGetState($Button_6) = 144 Then
GUICtrlSetState($Button_6, $GUI_ENABLE)
EndIf
EndIf

; Install Printer button was pressed
Case $GUIEvent_2 = $Button_6 And $SafeMode = 0
; Notify the User of install progress
ProgressOn("Add Printer","Adding: " & $Selection,"Adding", -1, -1, 16)
GUIDelete($AddPrinterGUI)

ProgressSet(25, "Adding: " &$Selection)
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /q /ga /c' & @ComputerName & ' /n "' & $PrintServer & ".ad.ppsnet" & $Selection & '"', @WindowsDir, @SW_HIDE)

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 50 to 75 Step 5

ProgressSet($i, "Updating System")
GetLocalPrinters()
RefreshListView()

Sleep(500) ;0.5 Seconds

Next

; Update UI
ProgressSet(100, "Done")
ProgressOff()
GetLocalPrinters()
RefreshListView()
ExitLoop

EndSelect
WEnd

; Update UI
GetLocalPrinters()
RefreshListView()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_4: Set Default Printer Button on "Print" Tab
Case $GUIEvent_1 = $Button_4 And $SafeMode = 0
If IsAdmin() Then
For $i = 0 to $aLocalPrinters[0][0] Step 1
ProgressOn( 'Default','Setting Default','Default', -1, -1, 16)
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
ProgressSet(33, "Running Command")
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /y /n "' & $aLocalPrinters[$i + 1][0] & '"', @WindowsDir, @SW_HIDE)
ProgressSet(66, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressSet(100, "Completed")
Sleep(1000)
EndIf
Next
ProgressOff()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; Processes to Monitor while ListView is inactive
Case $ListView And $SafeMode = 0
; Check to see what is selected
For $i = 0 to $aLocalPrinters[0][0] Step 1

; Look for current selection
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]

; If the Selection "iPrint" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "iPrint" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Local" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Local" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Networked" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Networked" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

;If the Selection "Protected" Disable Button (if not already disabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Protected" Then
If GUICtrlGetState($Button_2) = 80 Then
GUICtrlSetState($Button_2, $GUI_DISABLE)
EndIf
EndIf
EndIf
Next
EndSelect
WEnd
Edited by aseitz

Share this post


Link to post
Share on other sites

Can you put a

MsgBox(0, "", "RefreshRegView called!")
into function RefreshRegView to make sure it is called when you press the button?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=ITHelp.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Added conditional include to fix windows xp -- (Build: 1300) -- Adam Seitz 11/07/2012
Global $CheckUAC = 0
$CheckUAC = RegRead("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem", "EnableLUA")
If $CheckUAC > 0 Then
#RequireAdmin ; Added UAC Support -- (Build: 1203) -- Adam Seitz 10/12/2012
EndIf

#Include <AD.au3>
#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIListView.au3>
#Include <GuiStatusBar.au3>
#Include <INet.au3>
#Include <Process.au3>
#Include <WindowsConstants.au3>

; *********************************************************************************************************
;  File........: ITHelp.au3
;  Author......: Adam Seitz (aseitz@pps.net)
;  Auto IT.....: 3.3.8.1
;
;  Purpose: To help End Users get help and support quickly and easily.
; *********************************************************************************************************
;Tray Icon (0=show, 1=hide)
Opt("TrayIconHide", 1)

; Version Info
Global $PPSVersion = "v1.3"
Global $PPSBuild = "1305"
Global $PPSDate = "11/15/2012"
Global $PPSTitle = "IT Help"

; User Interface Window Formatting and Handling
Global $GUIImages = @ScriptDir & "images", $GUIFont = "Arial", $GUIFontSize = 8.5, $GUIBackGroundColor = "0xFFFFFF"
Global $GUIEvent_1, $GUIEvent_2

; Buttons
Global $Button_1, $Button_2, $Button_3, $Button_4, $Button_5, $Button_6, $Button_7, $Button_8

; Hardware Info
Global $HDDVolume, $HDDSerial, $HDDTotal, $HDDFree

; Labels
Global $Label_Row_Offset = 25, $Label_Col_Offset = 25, $Label_Length = 200, $Label_Height = 20
Global $Data_Row_Offset = 165, $Data_Col_Offset = 25, $Data_Length = 300, $Data_Height = 20

; Tabs
Global $Tab_1, $Tab_2, $Tab_3, $Tab_4, $Tab_5, $Tab_6

; Labels / Input Fields
Global $Input_ComputerName, $Input_CurrentUserName, $Input_OperatingSystem, $Input_DomainStatus
Global $Input_ServicePack, $Input_VolumeLabel, $Input_SerialNumber, $Input_TotalSpace, $Input_FreeSpace, $Input_IpAddress, $Input_StartupDirectory
Global $Input_WindowsDirectory, $Input_SystemFolderDirectory, $Input_DesktopDirectory, $Input_MyDocumentsDirectory, $Input_ProgramFilesDirectory
Global $Input_StartMenuDirectory, $Input_TemporaryFileDirectory, $Input_DesktopWidth, $Input_DesktopHeight, $Input_Date, $Input_Time, $SafeMode = 0
Global $Input_RoomNumber, $Input_PurchaseOrder, $Input_ManagedBy

; Registry Reading Variables
Global $PPS_Key, $Reg_RoomNumber, $Reg_PurchaseOrder, $Reg_ManagedBy

; Printers tab
Global $aLocalPrinters[1][4], $ListView, $Selection

; Arbitrary Variables
Global $Meridian = "AM"

; Network Setup Variables
Global $DNSD = "ad.ppsnet", $DNSR = True, $IPAddressCount = 0

; WMI Variables
Global $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $WMICheck=1, $WMI_Repair_Path

; Check for WMI Errors
Global $objWMIService = ObjGet('winmgmts:' & @ComputerName & 'rootCIMV2')
if @error then
$WMICheck=2
If IsObj($objWMIService) then
$WMICheck = 1
EndIf
EndIf

;################################################################################
;  Function GetRegValues()
;################################################################################
; This is the function that reads the PPS custom reg values.
Func GetRegValues()
; Set Registry Path to PPS Key
If @OsArch = "X64" Then
$PPS_Key = 'HKLM64SoftwarePPS'
Else
$PPS_Key = 'HKLMSoftwarePPS'
EndIf

$Reg_RoomNumber = RegRead($PPS_Key,'RoomNumber')
$Reg_PurchaseOrder = RegRead($PPS_Key,'PurchaseOrder')
$Reg_ManagedBy = RegRead($PPS_Key,'ManagedBy')

EndFunc ;<== End GetRegValues()

;################################################################################
;  Function SetRegValues()
;################################################################################
; This is the function that writes the PPS custom registry values.
Func SetRegValues()
Local $value

; RoomNumber Value
$value = GUICtrlRead($Input_RoomNumber)
RegWrite($PPS_Key, 'RoomNumber', 'REG_SZ', $value)

; PurchaseOrder Value
$value = GUICtrlRead($Input_PurchaseOrder)
RegWrite($PPS_Key, 'PurchaseOrder', 'REG_SZ', $value)

; ManagedBy Value
$value = GUICtrlRead($Input_ManagedBy)
RegWrite($PPS_Key, 'ManagedBy', 'REG_SZ', $value)

EndFunc ;<== End SetRegValues()

;################################################################################
;  Function RefreshRegView
;################################################################################
; Refresh the Computer Tab view
Func RefreshRegView()

; Get the values from the registry
GetRegValues()

; Write the vakues to the input fields
$Input_RoomNumber = $Reg_RoomNumber
$Input_PurchaseOrder = $Reg_PurchaseOrder
$Input_ManagedBy = $Reg_ManagedBy

; Update the GUI
GUISetState()

; Debug
msgbox(0,"debug","RefreshRegView()!!")

EndFunc ;==> End RefreshRegView()

;################################################################################
;  Function WMIStringToDate($dtmDate)
;################################################################################
Func WMIDateStringToDate($dtmDate)
   Return (StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2)  & ":" & StringMid($dtmDate, 13, 2) & " on: " & StringMid($dtmDate, 5, 2) & "/" & StringMid($dtmDate, 7, 2) & "/" & StringMid($dtmDate, 1, 4))
EndFunc  ;==>WMIDateStringToDate

;################################################################################
;  Function __StringToDate($dtmDate)
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func __StringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc ;<== End __StringToDate()

;################################################################################
;  Function RestartPrint()
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func RestartPrint()
RunWait(@ComSpec & " /c " & 'start /wait /min net stop "Print Spooler"', @WindowsDir, @SW_HIDE)
RunWait(@ComSpec & " /c " & 'start /wait /min net start "Print Spooler"', @WindowsDir, @SW_HIDE)
EndFunc ;<== End RestartPrint()

;################################################################################
;  Function GetLocalPrinters()
;################################################################################
; Get Locally Installed Printers
Func GetLocalPrinters()

; Delete Array if it aleady exists
If $aLocalPrinters[0][0] > 0 Then
; Reintalize the array
Dim $aLocalPrinters[1][4]
EndIf

Local $ctr = 1
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
For $objItem In $colItems
ReDim $aLocalPrinters[UBound($aLocalPrinters) + 1][4]
$aLocalPrinters[$ctr][0] = $objItem.Name
$aLocalPrinters[$ctr][1] = $objItem.Default
$aLocalPrinters[$ctr][2] = $objItem.Comment
$aLocalPrinters[$ctr][3] = "Local"

; Check if Printer is Networked or Not
If StringinStr($aLocalPrinters[$ctr][0],"ipp://") Then
$aLocalPrinters[$ctr][3] = "iPrint"
ElseIf StringinStr($aLocalPrinters[$ctr][0],"") Then
$aLocalPrinters[$ctr][3] = "Networked"
Endif

$ctr += 1
Next
$aLocalPrinters[0][0] = UBound($aLocalPrinters) - 1
If $aLocalPrinters[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aLocalPrinters)

EndFunc ;==>GetLocalPrinters()

;################################################################################
;  Function DeletePrinter()
;################################################################################
Func DeletePrinter()
; If the printer is a network printer, never use this type of delete
If Not StringinStr($Selection, "") Then
; Delete Local
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dl /n "' & $Selection & '"', "", @SW_HIDE)
EndIf

; Delete Network
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dn /n "' & $Selection & '"', "", @SW_HIDE)

; Delete Per-Machine
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /gd /n "' & $Selection & '"', "", @SW_HIDE)

EndFunc ;==> End DeletePrinter()

;################################################################################
;  Function GetMemoryBanks()
;################################################################################
; Returns number of banks regardless of whether there is memory installed
Func GetMemoryBanks()
Local $colMemory = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemoryArray")

For $objMemory in $colMemory
Return ($objMemory.MemoryDevices)
Next
EndFunc ;==> End GetMemoryBanks()

;################################################################################
;  Function GetMemoryInfo()
;################################################################################
; Get Memory information
Func GetMemoryInfo()
Local $aMemoryInfo[1][6], $ctr = 1
Local $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemory")

; Preform Query
If IsObj($colItems) Then
For $objItem In $colItems
; This fixes the HP 5700, since it had a ROM that was type "0"
; and messing up the array Build 1100 AS 2/6/12
If $objItem.FormFactor > "0" Then
ReDim $aMemoryInfo[UBound($aMemoryInfo) + 1][6]
$aMemoryInfo[$ctr][0] = $objItem.BankLabel
$aMemoryInfo[$ctr][1] = $objItem.Name
$aMemoryInfo[$ctr][2] = $objItem.Capacity
$aMemoryInfo[$ctr][3] = $objItem.FormFactor
$aMemoryInfo[$ctr][4] = $objItem.MemoryType
$aMemoryInfo[$ctr][5] = $objItem.Speed
EndIf
$ctr += 1
Next
$aMemoryInfo[0][0] = UBound($aMemoryInfo) - 1
If $aMemoryInfo[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aMemoryInfo)
EndFunc ;==>GetMemoryInfo()

;################################################################################
;  Function RefreshListView
;################################################################################
; Refreshs the ListView
Func RefreshListView()
Local $ctr = 1

; Clean Up Existing ListView
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))

; Build Repopulate ListView
_GUICtrlListView_AddArray(GUICtrlGetHandle($ListView), $aLocalPrinters)

; Delete first element since it shows the count
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListView), 0)

While $ctr <= $aLocalPrinters[0][0]
; Printer Name
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 0, $LVSCW_AUTOSIZE)

; Is Printer Default? (Yes / No)
If $aLocalPrinters[$ctr][1] = True Then
_GUICtrlListView_SetItemSelected(GUICtrlGetHandle($ListView), $ctr - 1)
EndIf
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 1, $LVSCW_AUTOSIZE_USEHEADER)

; Printer Caption
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 2, $LVSCW_AUTOSIZE)

; Printer Type
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 3, $LVSCW_AUTOSIZE)

$ctr += 1
WEnd
Return($ListView)
EndFunc ;==> End RefreshListView()

; *********************************************************************************************************
;  Check WMI Health
; *********************************************************************************************************
; WMI error - Lets try to fix it
If $WMICheck = 2 Then
; Only works on Windows XP Pro 32-Bit
If @OSVersion = "WIN_XP" And @OSArch = "x86" Then
$WMI_Repair_Path = @WindowsDir & 'ServicePackFilesI386'

; If admin then fix stuff
If IsAdmin() Then
; WMI is busted, notify the user.
ProgressOn("WMI Repair","WMI Repair","Repairing Local WMI Database", -1, -1, 16)
If FileExists($WMI_Repair_Path) Then

ProgressSet( 90, "Stopping SMS Agent Service")
RunWait('net stop ccmexec')

ProgressSet( 15, "Stopping Firewall/ICS Service")
RunWait('net stop sharedaccess')

ProgressSet( 30, "Stopping WMI Service")
RunWait('net stop winmgmt')

ProgressSet( 45, "Removing Corrupt WMI Database")
DirRemove(@WindowsDir & 'System32WbemRepository', 1)

ProgressSet( 60, "Rebuilding Clean WMI Database")
RunWait('winmgmt /resetRepository')

ProgressSet( 90, "Starting SMS Agent Service")
RunWait('net start ccmexec')

ProgressSet( 90, "Starting Firewall/ICS Service")
RunWait('net start sharedaccess')

ProgressSet( 75, "Starting WMI Service")
RunWait('net start winmgmt')

Sleep(10000)
Else
; We Failed, lets mark it with a "1" and use that for safe-mode
$SafeMode = 1
EndIf
Else
$SafeMode = 1
EndIf
ProgressOff()
Else
$SafeMode = 1
EndIf
EndIf

; *********************************************************************************************************
;  Get Remotely Available Printers
; *********************************************************************************************************
If $SafeMode = 0 Then
; Adding Build version to initial load screen -- (Build: 1301) -- Adam Seitz 11/07/2012
ProgressOn( "IT Help Tool " & $PPSVersion & " (Build: " & $PPSBuild & ")","IT Help Tool Loading...","Loading", -1, -1, 16)
ProgressSet( 0, "Detecting Print Server Name")

Global $PercentDone, $PrintServer, $aPrintQueues, $aPrintDetails[1][1], $aIPAddress, $aIPAddress1, $aIPAddress2, $aIPAddress3, $aIPAddress4, $aTemp1, $aTemp2

; Initialize TCP Functionality
TCPStartup()

; Open Connection to the Active Directory
If _AD_Open() Then

; Grab All IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
$aIPAddress1 = StringSplit(@IPAddress1, ".")
$aIPAddress2 = StringSplit(@IPAddress2, ".")
$aIPAddress3 = StringSplit(@IPAddress3, ".")
$aIPAddress4 = StringSplit(@IPAddress4, ".")

; Count IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
If $aIPAddress1[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress2[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress3[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress4[1] > 0 Then
$IPAddressCount += 1
EndIf

; Evaluate IP Addresses to determine if one is a PPS address
For $ctr = 1 to $IPAddressCount Step 1
; Set $aIPAddress to current IP Address
If $ctr = 1 Then
$aIPAddress = $aIPAddress1
ElseIf $ctr = 2 Then
$aIPAddress = $aIPAddress2
ElseIf $ctr = 3 Then
$aIPAddress = $aIPAddress3
ElseIf $ctr = 4 Then
$aIPAddress = $aIPAddress4
EndIf

; Assign Print Server Based on IP Address at some sites and discovery at the others.
If $aIPAddress[1] = "159" Then
;WNPRINT is not a standard address nor are the clients
$PrintServer = _TCPIpToName ('10.128.10.119')

; Added 127 (Build: 1203) -- Adam Seitz 10/11/2012
ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "127") Then
$PrintServer = _TCPIpToName ('10.128.10.119')

ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "128") Then
$PrintServer = _TCPIpToName ('10.128.10.119')
Else
;<SITE>-PRINT is a standard naming convention, all servers use IP 10.<site>.8.7
; So by using the clients first two octets and appending 8.7 we get a valid ip to
; use as the print server.
$PrintServer = _TCPIpToName ( $aIPAddress[1] & '.' & $aIPAddress[2] & '.8.7' )
If @error Then
$PrintServer = False
EndIf
EndIf
Next

If Not $PrintServer = False Then
ProgressSet( 0, "Counting Printers on: " & $PrintServer & ".ad.ppsnet")

; The Name returned by _TCPIpToName() is FQDN we need a simple name.
$aTemp1 = StringSplit($PrintServer, ".")
$PrintServer = $aTemp1[1]

; Get a list of all PrintQueues in the AD tree
$aPrintQueues = _AD_ListPrintQueues($PrintServer)

; Verify the Returned Printers is actually valid
If Not IsArray($aPrintQueues) Then
$PrintServer = False
Else

; Order list by alphabet
_ArraySort($aPrintQueues)

; Get Printer Details
For $i = 1 to $aPrintQueues[0][0] Step 1
; Calculate Remaining Percentage of Bar
$PercentDone = (100 / $aPrintQueues[0][0]) * $i
ProgressSet( $PercentDone, "Querying Printer " & $i & " of " & $aPrintQueues[0][0] & ": " & $aPrintQueues[$i][0])

; Build Array
Redim $aPrintDetails[UBound($aPrintDetails) + 1][1]
$aTemp2 = _AD_GetObjectProperties($aPrintQueues[$i][2])
$aPrintDetails[$i][0] = $aTemp2[2][1]
Next
EndIf
; Close Connection to the Active Directory
_AD_Close()
EndIf
Else
$PrintServer = False
EndIf

; Close Progress Bar
ProgressOff()

; Turn off TCP Service to prevent Memory Leak
TCPShutdown()
EndIf

; *********************************************************************************************************
;  Get CPU Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Cpu_Core = 0, $Cpu_Arc, $Temp
Global $Cpu_Name = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","ProcessorNameString")
Global $Cpu_Clock = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","~MHz")

; Format CPU Information as Human Readable
If (@CPUArch = "X86") Then
$Cpu_Arc = "32-Bit"
ElseIf (@CPUArch = "X64") Then
$Cpu_Arc = "64-Bit"
Else
$Cpu_Arc = @CPUArch
EndIf

For $i= 1 to 1000
$Temp = RegEnumKey("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor", $i)
If @error <> 0 then
ExitLoop
EndIf
$Cpu_Core += 1
Next
EndIf

; *********************************************************************************************************
;  Get MEM Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $aMemoryInfo[1][100], $Mem_Num, $Mem_Text, $Mem_Percentage, $Mem_Readable, $Mem_Banks, $colMemory
Global $Readable_FormFactor[24] = ["Unknown","Other", "SIP","DIP","ZIP","SOJ","Proprietary","SIMM","DIMM","TSOP","PGA","RIMM","SODIMM","SRIMM","SMD","SSSMP","QFP","TQFP","SOIC","LCC","PLCC","BGA","FPBGA","LGA"]
Global $Readable_MemoryType[22] = ["Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM","RAM","ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR-2"]
Global $Mem_Count = 0, $Mem_Raw = MemGetStats()

; Clean Up the Text returned so it is presented a bit more readable
If ($Mem_Raw[1] > 0) and ($Mem_Raw[1] < 1000) Then
$Mem_Num = $Mem_Raw[1]
$Mem_Text = " KB"
ElseIf ($Mem_Raw[1] > 1000) and ($Mem_Raw[1] < 100000) Then
$Mem_Num = $Mem_Raw[1] /1024
$Mem_Text = " MB"
Else
$Mem_Num = $Mem_Raw[1] / 1024 / 1024
$Mem_Text = " GB"
EndIf

; Round Cleaner Number for final display text
$Mem_Percentage = $Mem_Raw[0]
$Mem_Readable = Round($Mem_Num, 2) & $Mem_Text

; Get Number of Physical Memory Banks on this motherboard
$aMemoryInfo = GetMemoryInfo()

; Get Number of Physical Memory Banks on this motherboard
$Mem_Banks = GetMemoryBanks()

EndIf

; *********************************************************************************************************
;  Get HDD Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$HDDVolume = DriveGetLabel("C:")
$HDDSerial = DriveGetSerial("C:")
$HDDTotal = DriveSpaceTotal("C:")
$HDDFree = DriveSpaceFree("C:")
Global $HDD_Percentage =  Round(( $HDDFree / $HDDTotal ) * 100)
EndIf

; *********************************************************************************************************
;  Get Uptime
; *********************************************************************************************************
If $SafeMode = "0" Then
Global $LastBootUp, $LocalDateTime, $colItems
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$LastBootUp = WMIDateStringToDate($objItem.LastBootUpTime)
$LocalDateTime = WMIDateStringToDate($objItem.LocalDateTime)
Next
EndIf
EndIf

; *********************************************************************************************************
;  Get Domain Membership
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $DOM_Hover, $DOM_Status = "No"
$colItems = $objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem")
For $obj In $colItems
If $obj.DomainRole = 1 Then
$DOM_Status = "Yes"
$DOM_Hover = "Machine is joined to Domain"
EndIf
Next
EndIf

; *********************************************************************************************************
;  Get Network Card Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Network_Card[1][50], $Network_Card_Count = 0

$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
$i = 1

If IsObj($colItems) Then
For $obj In $colItems
ReDim $Network_Card[UBound($Network_Card) + 1][50]
$Network_Card[$i][0] = $obj.Description
$Network_Card[$i][1] = $obj.DHCPEnabled
$Network_Card[$i][2] = $obj.MACAddress
$i += 1
Next
$Network_Card[0][0] = UBound($Network_Card) - 1
If $Network_Card[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf
EndIf

; *********************************************************************************************************
;  Create Human Readable Information
; *********************************************************************************************************
Global $WINVER
If (@OSVersion = "WIN_2000") Then
$WINVER = "Windows 2000"
ElseIf (@OSVersion = "WIN_7") Then
$WINVER = "Windows 7"
ElseIf (@OSVersion = "WIN_8") Then ; -- (Build: 1203) -- Adam Seitz 10/12/2012
$WINVER = "Windows 8"
ElseIf (@OSVersion = "WIN_XP") Then
$WINVER = "Windows XP"
Else
$WINVER = @OSVersion
EndIf

;  Set Windows Service Pack to Human Readable
Global $WINSPK = @OSServicePack

; Evaluate (and make human readable) the service pack level  -- (Build: 1203) -- Adam Seitz 10/12/2012
If (IsString($WINSPK)) Then
$aTemp1 = StringSplit($WINSPK, " ")
If($aTemp1[1] = "Service") Then
$WINSPK = @OSServicePack
Else
$WINSPK = "Release"
EndIf
EndIf

; *********************************************************************************************************
;  Get VNC Status
; *********************************************************************************************************
Global $VNC_Hover, $VNC_Status

If ProcessExists("tvncserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
ElseIf ProcessExists("tvnserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
Else
$VNC_Status = "Not Available"
$VNC_Hover = "Service is not running or application is not installed."
EndIf

; *********************************************************************************************************
;  Get RDP Status
; *********************************************************************************************************
Global $RDP_Hover, $RDP_Status, $RDP_Check = RegRead("HKLMSYSTEMCurrentControlSetControlTerminal Server", "fDenyTSConnections")

; Check the Registry for Enable / Disable of RDP
;  0 = Available
;  1 = Disabled
If $RDP_Check = "0" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
Else
$RDP_Check = "Not Available"
$RDP_Hover = "Service is Not Running"
EndIf

; If Machine is on Domain the Registry key is not used any more, GPO sets it.
If $SafeMode = 0 And $DOM_Status = "Yes" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
EndIf

; If Machine is on Windows 2000, then RDP does not exist.
If (@OSVersion = "WIN_2000") Then
$RDP_Status = "Not Available"
$RDP_Hover = "Windows 2000 does not support RDP."
EndIf

; *********************************************************************************************************
;  Get Absolute Manage Status
; *********************************************************************************************************
Global $ABS_Status, $ABS_Hover_1, $ABS_Hover_2, $ABS_File, $ABS_Ver

; See if it is installed
If FileExists(@ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe") Then
$ABS_File = @ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe"
$ABS_Ver = RegRead("HKLMSOFTWAREPole Position SoftwareLANrev Agent","AgentVersion")
Else
$ABS_File = 0
$ABS_Ver = 0
EndIf

; Windows 2000 Only
If @OSVersion = "WIN_2000" Then
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
EndIf

; Windows XP and later
Else
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5 requires an upgrade to function."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 requires an update to function"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1"
$ABS_Status = "Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3"
$ABS_Status = "Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3"
$ABS_Status = "Available"
EndIf
EndIf

; Determine if process is running
If ProcessExists("LANrev Agent.exe") Then
$ABS_Status = "Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Running"
Else
$ABS_Status = "Not Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Not Running."
EndIf

; *********************************************************************************************************
;  Get Microsoft Forefront Status
; *********************************************************************************************************
Global $FEP_Status, $FEP_Hover

; Determine if process is running
If ProcessExists("MsMpEng.exe") Then
$FEP_Status = "Available"
$FEP_Hover = " Process is Running"
Else
$FEP_Status = "Not Available"
$FEP_Hover = " Process is Not Running."
EndIf

; *********************************************************************************************************
;  Create Window
; *********************************************************************************************************
Global $MainGUI, $AddPrinterGUI, $AddPrinterExit, $AddPrinterList

$MainGUI = GuiCreate($PPSTitle & " - " & $PPSVersion & " (Build: " & $PPSBuild & ")", 500, 400) ; Window Style
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon
GUISetBkColor($GUIBackGroundColor)
GuiCtrlCreatePic($GUIImages & "Support_Info.jpg",0,0, 500, 100)

; Set Font Back to Larger for Banner
GUISetFont(12,0,0, $GUIFont)
GUICtrlCreateLabel("Computer Name:", 110, 10, 300, 20)

; Bold + Underline Computer Name
GUISetFont(12,400, 4, $GUIFont)
GUICtrlCreateLabel(@ComputerName, 235, 10, 300, 20)

; Back to Larger Font - No Underline or Bold
GUISetFont(12, 0, 0, $GUIFont)
GUICtrlCreateLabel("* Primary IP Address: " & @IPAddress1, 110, 40, 300, 20)

If @IPAddress2 > 0 Then
GUICtrlCreateLabel("* Secondary IP Address: " & @IPAddress2, 110, 60, 300, 20)
EndIf

; Set Font Back to Regular
GUISetFont($GUIFontSize, 0, 0, $GUIFont)

; *********************************************************************************************************
;  Create Tabbed User Window (Below Banner)
; *********************************************************************************************************
Global $Col_Num, $Row_Num, $tabbed, $hTab
$tabbed = GUICtrlCreateTab(5, 100, 490, 295)
$hTab = GUICtrlGetHandle($tabbed) ; get the handle for use in the notify events
If $SafeMode = 0 Then
GUICtrlCreateLabel( "",304,97,195,23) ; A blank White label to cover the tab ui grey'd background
Else
GUICtrlCreateLabel( "      IT Help Is Running In Safemode",125,97,370,23) ; A blank White label to cover the tab ui grey'd background
EndIf
; *********************************************************************************************************
; Tab 1: Support Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_1 = GUICtrlCreateTabItem("Support")
Else
$Tab_1 = GUICtrlCreateTabItem("SAFE MODE: Enabled")
If IsAdmin() Then
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "Rebooting your computer may clear this up.")
Else
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "An Attempt to fix it was made but you are not an Administrator on this machine.")
EndIf
EndIf

; Row 1: Contact Information
$Row_Num = 5.1
GUICtrlCreateLabel("Service Desk Phone:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("(503) 916-3375", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 2: Contact Information
$Row_Num = 6.1
GUICtrlCreateLabel("Service Desk Email:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("itservicedesk@pps.net", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 3: Buttons
$Row_Num = 7.1
$Button_1 = GuiCtrlCreateButton("IT Homepage", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length-50, $Label_Height)
GuiCtrlSetTip(-1, 'http://www.pps.net/departments/information-technology')

; Group 1: Left Column
GuiCtrlCreateGroup("Vital Signs", 10, 200, 200, 150)

; Column 1 - 1: VNC Service
$Col_Num = 1
$Row_Num = 8.9
GUICtrlCreateLabel("VNC Remote Control:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $VNC_Hover)
If $VNC_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 2: RDP Service
$Col_Num = 1
$Row_Num = 9.9
GUICtrlCreateLabel("Remote Desktop Protocol:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $RDP_Hover)
If $RDP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 3: Domain Check
$Row_Num = 10.9
$Col_Num = 1
GUICtrlCreateLabel("Domain Status:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlSetTip(-1, $DOM_Hover)
If $DOM_Status = "Yes" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf
EndIf

; Column 1 - 4: Absolute Manage Client
$Row_Num = 11.9
$Col_Num = 1
GUICtrlCreateLabel("Absolute Manage Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $ABS_Hover_2)
If $ABS_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 5: Microsoft Forefront Endpoint Protection
$Row_Num = 12.9
$Col_Num = 1
GUICtrlCreateLabel("Forefront Endpoint Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $FEP_Hover)
If $FEP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Group 2: Right Column
GuiCtrlCreateGroup("System Information", 210, 200, 275, 150)

; Column 2 - 1: Last Rebooted Information
$Row_Num = 8.9
$Col_Num = 190
GUICtrlCreateLabel("Last Rebooted:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($LastBootUp, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 2: Processor Information
$Row_Num = 9.9
$Col_Num = 190
GUICtrlCreateLabel("Processor is a:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Cpu_Arc & " (" & $Cpu_Core & " Core): " & Round($Cpu_Clock / 1000, 2) & " GHz", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 3: Memory Information
$Row_Num = 10.9
$Col_Num = 190
GUICtrlCreateLabel("Memory:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Mem_Readable & " (" & $Mem_Percentage & "% Used)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 4: Drive Free Space
$Row_Num = 11.9
$Col_Num = 190
GUICtrlCreateLabel("Free Space:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput("" & Round($HDDFree /1024,1) & " GB" & " (" & $HDD_Percentage & "% Free)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 5: Print Server
$Row_Num = 12.9
$Col_Num = 190
GUICtrlCreateLabel("Print Server:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($PrintServer, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; *********************************************************************************************************
; Tab 2: Computer Information
; *********************************************************************************************************
If $SafeMode = 0 Then

; Read in the Registry Values
GetRegValues()

$Tab_2 = GUICtrlCreateTabItem("Computer")

; Row 1: Room Number
$Row_Num = 5.1
GUICtrlCreateLabel("Room Number:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_RoomNumber = GUICtrlCreateInput("" & $Reg_RoomNumber, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: Purchase Order
$Row_Num = 6.1
GUICtrlCreateLabel("Purchase Order:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_PurchaseOrder = GUICtrlCreateInput("" & $Reg_PurchaseOrder, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Managed By
$Row_Num = 7.1
GUICtrlCreateLabel("Managed By:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_ManagedBy = GUICtrlCreateInput("" & $Reg_ManagedBy, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 14: Buttons
$Row_Num = 14.2

; Row 14: Button 7: Save Changes
$Button_7 = GuiCtrlCreateButton("Save", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Save changes to above fields.')
If IsAdmin() = False Then
GUICtrlSetState($Button_7, $GUI_DISABLE)
EndIf

; Row 14: Button 8: Discard Changes
$Button_8 = GuiCtrlCreateButton("Discard", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Discard Changes and reload default settings.')

EndIf

; *********************************************************************************************************
; Tab 3: Print Manager
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_6 = GUICtrlCreateTabItem("Printer")
Global $answer, $Command, $Radio, $Combo, $ComboBox, $Input_PrintServer, $Input_DefaultPrinter

; Progress Bar Window position centered, near bottom.
Global $iGuiHeight = 100
Global $iGuiWidth = 100
Global $iGuiXPos = (@DesktopWidth/2)-$iGuiWidth-50
Global $iGuiYPos = (@DesktopHeight/2)-$iGuiHeight/2

; List All Printers
$Row_Num = 5.1

$ListView = GUICtrlCreateListView( "Name|Default|Description|Type", 9, 124, 479, 220, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

; Get List of Installed Printers
$aLocalPrinters = GetLocalPrinters()

; Display  the Printers on the ListView
RefreshListView()

$Row_Num = 14.2
; Button: Delete Selected Printer
$Button_2 = GuiCtrlCreateButton("Delete Printer", $Label_Row_Offset + 360, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Deletes Highlighted Printer.')
GUICtrlSetState($Button_2, $GUI_DISABLE)

; Button: Add Printers
$Button_3 = GuiCtrlCreateButton("Add Printer", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Add a new printer.')
If $PrintServer = False Then
GUICtrlSetState($Button_3, $GUI_DISABLE)
EndIf

; Button: Make Default
$Button_4 = GuiCtrlCreateButton("Set Default", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Sets Highlighted Printer as Default Machine Printer.')

EndIf

; *********************************************************************************************************
; Tab 4: User Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_3 = GUICtrlCreateTabItem("User")

; Row 1: Current User Name
$Row_Num = 5
GUICtrlCreateLabel("User Name:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_CurrentUserName = GUICtrlCreateInput("" & @UserName, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: My Documents
$Row_Num = 6
GUICtrlCreateLabel("My Documents:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_MyDocumentsDirectory = GUICtrlCreateInput("" & @MyDocumentsDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Desktop Directory
$Row_Num = 7
GUICtrlCreateLabel("Desktop Directory: ", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_DesktopDirectory = GUICtrlCreateInput("" & @DesktopDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 4: Start Menu Directory
$Row_Num = 8
GUICtrlCreateLabel("Start Menu Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_StartMenuDirectory = GUICtrlCreateInput("" & @StartMenuDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 5: Temporary File Directory
$Row_Num = 9
GUICtrlCreateLabel("Temporary File Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_TemporaryFileDirectory = GUICtrlCreateInput("" & @TempDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)
EndIf

; *********************************************************************************************************
; Tab 5: Network Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_4 = GUICtrlCreateTabItem("Network")
$Row_Num = 5

For $i = 1 to $Network_Card[0][0]
GuiCtrlCreateLabel($Network_Card[$i][0], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * MAC Address: " & $Network_Card[$i][2], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * DHCP Enabled: " & $Network_Card[$i][1], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 1
Next
EndIf

; *********************************************************************************************************
; Tab 6: Memory Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_5 = GUICtrlCreateTabItem("Memory")
$Row_Num = 5.1
Global $Mem_Temp
GuiCtrlCreateLabel($aMemoryInfo[0][0] & " of " & $Mem_Banks & " Memory Banks Used", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
For $i = 1 to $Mem_Banks Step 1
$Row_Num += 1
If $i > $aMemoryInfo[0][0] Then
$Mem_Temp = "[ BANK " & $i & "] is Empty"
Else
$Mem_Temp = "[ BANK " & $i & "] " & $aMemoryInfo[$i][2] / 1024 / 1024 & " MB "& $Readable_MemoryType[$aMemoryInfo[$i][4]]& " " & $Readable_FormFactor[$aMemoryInfo[$i][3]] & " Running at "& $aMemoryInfo[$i][5] & " MHz"
EndIf
GuiCtrlCreateLabel($Mem_Temp, $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
Next
EndIf

; *********************************************************************************************************
;  Show / Update the GUI
; *********************************************************************************************************
GuiSetState(@SW_SHOW)

; End Tabbing
GUICtrlCreateTabItem("")

; Run the GUI until the dialog is closed
While 1
$GUIEvent_1 = GUIGetMsg()
Select
; Window Closed with "Close" window control
Case $GUIEvent_1 = $GUI_EVENT_CLOSE
ExitLoop

; BUTTON_1: Link Button on "Support" Tab
Case $GUIEvent_1 = $Button_1
Run(@ProgramFilesDir & "Internet Exploreriexplore.exe http://www.pps.net/departments/information-technology/")

; BUTTON_2: Delete Selected Printer on "Print" Tab
Case $GUIEvent_1 = $Button_2 And $SafeMode = 0 ; <---- Delete printers by check box
If IsAdmin() Then
For $i = 1 to $aLocalPrinters[0][0] Step 1
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]
EndIf
Next
$answer = MsgBox(BitOr(0x4, 0x20),"Delete Printers","Are you sure you want to delete: " & $Selection)
If $answer = "6" Then
; Begin progress bar
ProgressOn("Deleting Printer","Removing: " & $Selection,"Removing", -1, -1, 16)
ProgressSet(25, "Removing: " & $Selection)

; Delete the printer for all of the places in the registry it is possible to see it installed
DeletePrinter()

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 75 to 100 Step 5
Sleep(1000) ;1 Second
ProgressSet($i, "Updating System")
Next

; Update UI
ProgressSet(100, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressOff()

EndIf
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_7: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_7 And $SafeMode = 0
MsgBox(0,"Save","Saved changes")
; Update UI
ProgressSet(100, "Refreshing Window")
SetRegValues()
RefreshRegView()
ProgressOff()

; BUTTON_8: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_8 And $SafeMode = 0
MsgBox(0,"Discard","Discarded changes")
; Update UI
ProgressSet(100, "Refreshing Window")
GetRegValues()
RefreshRegView()
msgbox(0,"debug",$Input_RoomNumber)
ProgressOff()

; BUTTON_3: Add a Printer on "Print" Tab
Case $GUIEvent_1 = $Button_3 And $SafeMode = 0
If IsAdmin() Then
; Build Add Printer Wizard GUI
$AddPrinterGUI = GUICreate( "Add Printer Wizard", 350, 110, -1, -1)
GuiCtrlCreateLabel($PrintServer & ".ad.ppsnet", 5, 5, 100, $Label_Height)
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon

; Drop-Down Listbox of Printers
$ComboBox = GUICtrlCreateCombo("", 25, 25, 300, 30) ; create first item

; Loop to populate listBox with printers from the printer queue
For $i = 1 to $aPrintQueues[0][0] Step 1
GUICtrlSetData($ComboBox, $aPrintQueues[$i][0])
Next

; BUTTON_5: Exit Button on "Print" Tab -> Add Printer Wizard
$Button_5 = GUICtrlCreateButton("Exit", 160, 65, 100, 30)
GuiCtrlSetTip(-1, 'Exits the Add Printer Wizard')

; INSTALL Button
$Button_6 = GUICtrlCreateButton("Install", 50, 65, 100, 30)
GuiCtrlSetTip(-1, 'Installs the Selected Printer')

; Set GUI Visible and disable the install printer button
GUISetState(@SW_SHOW)
GUICtrlSetState($Button_6, $GUI_DISABLE)

; Loop until exited
While 2

; Update $GUIEvent_2 with whatever has happened since last loop
$GUIEvent_2 = GUIGetMsg()

; Switch on $GUIEvent_2 messages for work to be done.
Select
; Close Window was clicked
Case $GUIEvent_2 = $GUI_EVENT_CLOSE And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; Exit Button was Clicked
Case $GUIEvent_2 = $Button_5 And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; ComboBox was Updated
Case $GUIEvent_2 = $ComboBox And $SafeMode = 0
$Selection = GUICtrlRead($ComboBox)

; If the Selection was BLANK it's not valid
If Not $Selection = "" Then
If GUICtrlGetState($Button_6) = 144 Then
GUICtrlSetState($Button_6, $GUI_ENABLE)
EndIf
EndIf

; Install Printer button was pressed
Case $GUIEvent_2 = $Button_6 And $SafeMode = 0
; Notify the User of install progress
ProgressOn("Add Printer","Adding: " & $Selection,"Adding", -1, -1, 16)
GUIDelete($AddPrinterGUI)

ProgressSet(25, "Adding: " &$Selection)
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /q /ga /c' & @ComputerName & ' /n "' & $PrintServer & ".ad.ppsnet" & $Selection & '"', @WindowsDir, @SW_HIDE)

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 50 to 75 Step 5

ProgressSet($i, "Updating System")
GetLocalPrinters()
RefreshListView()

Sleep(500) ;0.5 Seconds

Next

; Update UI
ProgressSet(100, "Done")
ProgressOff()
GetLocalPrinters()
RefreshListView()
ExitLoop

EndSelect
WEnd

; Update UI
GetLocalPrinters()
RefreshListView()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_4:  Set Default Printer Button on "Print" Tab
Case $GUIEvent_1 = $Button_4 And $SafeMode = 0
If IsAdmin() Then
For $i = 0 to $aLocalPrinters[0][0] Step 1
ProgressOn( 'Default','Setting Default','Default', -1, -1, 16)
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
ProgressSet(33, "Running Command")
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /y /n "' & $aLocalPrinters[$i + 1][0] & '"', @WindowsDir, @SW_HIDE)
ProgressSet(66, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressSet(100, "Completed")
Sleep(1000)
EndIf
Next
ProgressOff()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; Processes to Monitor while ListView is inactive
Case $ListView And $SafeMode = 0
; Check to see what is selected
For $i = 0 to $aLocalPrinters[0][0] Step 1

; Look for current selection
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]

; If the Selection "iPrint" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "iPrint" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Local" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Local" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Networked" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Networked" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

;If the Selection "Protected" Disable Button (if not already disabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Protected" Then
If GUICtrlGetState($Button_2) = 80 Then
GUICtrlSetState($Button_2, $GUI_DISABLE)
EndIf
EndIf
EndIf
Next
EndSelect
WEnd

Edited by aseitz

Share this post


Link to post
Share on other sites

Function GetRegValues() only reads the values from the registry into variables. But the function never sets the content of the controls.

You need to add something like

GUICtrlSetData($Input_RoomNumber, $Reg_RoomNumber)
for every control you want to set.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Function GetRegValues() only reads the values from the registry into variables. But the function never sets the content of the controls.

You need to add something like

GUICtrlSetData($Input_RoomNumber, $Reg_RoomNumber)
for every control you want to set.

I was missing that entirely, but I have it added in now, however the refresh is still not working. Thanks for this! :)

Here is the updated code with a couple additional msgbox's for debugging.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=ITHelp.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Added conditional include to fix windows xp -- (Build: 1300) -- Adam Seitz 11/07/2012
Global $CheckUAC = 0
$CheckUAC = RegRead("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem", "EnableLUA")
If $CheckUAC > 0 Then
#RequireAdmin ; Added UAC Support -- (Build: 1203) -- Adam Seitz 10/12/2012
EndIf

#Include <AD.au3>
#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIListView.au3>
#Include <GuiStatusBar.au3>
#Include <INet.au3>
#Include <Process.au3>
#Include <WindowsConstants.au3>

; *********************************************************************************************************
;  File........: ITHelp.au3
;  Author......: Adam Seitz (aseitz@pps.net)
;  Auto IT.....: 3.3.8.1
;
;  Purpose: To help End Users get help and support quickly and easily.
; *********************************************************************************************************
;Tray Icon (0=show, 1=hide)
Opt("TrayIconHide", 1)

; Version Info
Global $PPSVersion = "v1.3"
Global $PPSBuild = "1305"
Global $PPSDate = "11/15/2012"
Global $PPSTitle = "IT Help"

; User Interface Window Formatting and Handling
Global $GUIImages = @ScriptDir & "images", $GUIFont = "Arial", $GUIFontSize = 8.5, $GUIBackGroundColor = "0xFFFFFF"
Global $GUIEvent_1, $GUIEvent_2

; Buttons
Global $Button_1, $Button_2, $Button_3, $Button_4, $Button_5, $Button_6, $Button_7, $Button_8

; Hardware Info
Global $HDDVolume, $HDDSerial, $HDDTotal, $HDDFree

; Labels
Global $Label_Row_Offset = 25, $Label_Col_Offset = 25, $Label_Length = 200, $Label_Height = 20
Global $Data_Row_Offset = 165, $Data_Col_Offset = 25, $Data_Length = 300, $Data_Height = 20

; Tabs
Global $Tab_1, $Tab_2, $Tab_3, $Tab_4, $Tab_5, $Tab_6

; Labels / Input Fields
Global $Input_ComputerName, $Input_CurrentUserName, $Input_OperatingSystem, $Input_DomainStatus
Global $Input_ServicePack, $Input_VolumeLabel, $Input_SerialNumber, $Input_TotalSpace, $Input_FreeSpace, $Input_IpAddress, $Input_StartupDirectory
Global $Input_WindowsDirectory, $Input_SystemFolderDirectory, $Input_DesktopDirectory, $Input_MyDocumentsDirectory, $Input_ProgramFilesDirectory
Global $Input_StartMenuDirectory, $Input_TemporaryFileDirectory, $Input_DesktopWidth, $Input_DesktopHeight, $Input_Date, $Input_Time, $SafeMode = 0
Global $Input_RoomNumber, $Input_PurchaseOrder, $Input_ManagedBy

; Registry Reading Variables
Global $PPS_Key, $Reg_RoomNumber, $Reg_PurchaseOrder, $Reg_ManagedBy

; Printers tab
Global $aLocalPrinters[1][4], $ListView, $Selection

; Arbitrary Variables
Global $Meridian = "AM"

; Network Setup Variables
Global $DNSD = "ad.ppsnet", $DNSR = True, $IPAddressCount = 0

; WMI Variables
Global $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $WMICheck=1, $WMI_Repair_Path

; Check for WMI Errors
Global $objWMIService = ObjGet('winmgmts:' & @ComputerName & 'rootCIMV2')
if @error then
$WMICheck=2
If IsObj($objWMIService) then
$WMICheck = 1
EndIf
EndIf

;################################################################################
;  Function GetRegValues()
;################################################################################
; This is the function that reads the PPS custom reg values.
Func GetRegValues()
; Set Registry Path to PPS Key
If @OsArch = "X64" Then
$PPS_Key = 'HKLM64SoftwarePPS'
Else
$PPS_Key = 'HKLMSoftwarePPS'
EndIf

$Reg_RoomNumber = RegRead($PPS_Key,'RoomNumber')
$Reg_PurchaseOrder = RegRead($PPS_Key,'PurchaseOrder')
$Reg_ManagedBy = RegRead($PPS_Key,'ManagedBy')

EndFunc ;<== End GetRegValues()

;################################################################################
;  Function SetRegValues()
;################################################################################
; This is the function that writes the PPS custom registry values.
Func SetRegValues()
Local $value

; RoomNumber Value
$value = GUICtrlRead($Input_RoomNumber)
RegWrite($PPS_Key, 'RoomNumber', 'REG_SZ', $value)

; PurchaseOrder Value
$value = GUICtrlRead($Input_PurchaseOrder)
RegWrite($PPS_Key, 'PurchaseOrder', 'REG_SZ', $value)

; ManagedBy Value
$value = GUICtrlRead($Input_ManagedBy)
RegWrite($PPS_Key, 'ManagedBy', 'REG_SZ', $value)

EndFunc ;<== End SetRegValues()

;################################################################################
;  Function RefreshRegView
;################################################################################
; Refresh the Computer Tab view
Func RefreshRegView()

; Get the values from the registry
GetRegValues()

; Write the vakues to the input fields
$Input_RoomNumber = $Reg_RoomNumber
$Input_PurchaseOrder = $Reg_PurchaseOrder
$Input_ManagedBy = $Reg_ManagedBy

; Update the GUI
GUISetState()

; Debug
msgbox(0,"debug","RefreshRegView()!!")

EndFunc ;==> End RefreshRegView()

;################################################################################
;  Function WMIStringToDate($dtmDate)
;################################################################################
Func WMIDateStringToDate($dtmDate)
   Return (StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2)  & ":" & StringMid($dtmDate, 13, 2) & " on: " & StringMid($dtmDate, 5, 2) & "/" & StringMid($dtmDate, 7, 2) & "/" & StringMid($dtmDate, 1, 4))
EndFunc  ;==>WMIDateStringToDate

;################################################################################
;  Function __StringToDate($dtmDate)
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func __StringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc ;<== End __StringToDate()

;################################################################################
;  Function RestartPrint()
;################################################################################
; This is the function that Stops / Starts the Printe Spooler service.
Func RestartPrint()
RunWait(@ComSpec & " /c " & 'start /wait /min net stop "Print Spooler"', @WindowsDir, @SW_HIDE)
RunWait(@ComSpec & " /c " & 'start /wait /min net start "Print Spooler"', @WindowsDir, @SW_HIDE)
EndFunc ;<== End RestartPrint()

;################################################################################
;  Function GetLocalPrinters()
;################################################################################
; Get Locally Installed Printers
Func GetLocalPrinters()

; Delete Array if it aleady exists
If $aLocalPrinters[0][0] > 0 Then
; Reintalize the array
Dim $aLocalPrinters[1][4]
EndIf

Local $ctr = 1
Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
For $objItem In $colItems
ReDim $aLocalPrinters[UBound($aLocalPrinters) + 1][4]
$aLocalPrinters[$ctr][0] = $objItem.Name
$aLocalPrinters[$ctr][1] = $objItem.Default
$aLocalPrinters[$ctr][2] = $objItem.Comment
$aLocalPrinters[$ctr][3] = "Local"

; Check if Printer is Networked or Not
If StringinStr($aLocalPrinters[$ctr][0],"ipp://") Then
$aLocalPrinters[$ctr][3] = "iPrint"
ElseIf StringinStr($aLocalPrinters[$ctr][0],"") Then
$aLocalPrinters[$ctr][3] = "Networked"
Endif

$ctr += 1
Next
$aLocalPrinters[0][0] = UBound($aLocalPrinters) - 1
If $aLocalPrinters[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aLocalPrinters)

EndFunc ;==>GetLocalPrinters()

;################################################################################
;  Function DeletePrinter()
;################################################################################
Func DeletePrinter()
; If the printer is a network printer, never use this type of delete
If Not StringinStr($Selection, "") Then
; Delete Local
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dl /n "' & $Selection & '"', "", @SW_HIDE)
EndIf

; Delete Network
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /dn /n "' & $Selection & '"', "", @SW_HIDE)

; Delete Per-Machine
RunWait('"' & @ComSpec & '" /c rundll32 printui.dll,PrintUIEntry /q /gd /n "' & $Selection & '"', "", @SW_HIDE)

EndFunc ;==> End DeletePrinter()

;################################################################################
;  Function GetMemoryBanks()
;################################################################################
; Returns number of banks regardless of whether there is memory installed
Func GetMemoryBanks()
Local $colMemory = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemoryArray")

For $objMemory in $colMemory
Return ($objMemory.MemoryDevices)
Next
EndFunc ;==> End GetMemoryBanks()

;################################################################################
;  Function GetMemoryInfo()
;################################################################################
; Get Memory information
Func GetMemoryInfo()
Local $aMemoryInfo[1][6], $ctr = 1
Local $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PhysicalMemory")

; Preform Query
If IsObj($colItems) Then
For $objItem In $colItems
; This fixes the HP 5700, since it had a ROM that was type "0"
; and messing up the array Build 1100 AS 2/6/12
If $objItem.FormFactor > "0" Then
ReDim $aMemoryInfo[UBound($aMemoryInfo) + 1][6]
$aMemoryInfo[$ctr][0] = $objItem.BankLabel
$aMemoryInfo[$ctr][1] = $objItem.Name
$aMemoryInfo[$ctr][2] = $objItem.Capacity
$aMemoryInfo[$ctr][3] = $objItem.FormFactor
$aMemoryInfo[$ctr][4] = $objItem.MemoryType
$aMemoryInfo[$ctr][5] = $objItem.Speed
EndIf
$ctr += 1
Next
$aMemoryInfo[0][0] = UBound($aMemoryInfo) - 1
If $aMemoryInfo[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf

Return($aMemoryInfo)
EndFunc ;==>GetMemoryInfo()

;################################################################################
;  Function RefreshListView
;################################################################################
; Refreshs the ListView
Func RefreshListView()
Local $ctr = 1

; Clean Up Existing ListView
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))

; Build Repopulate ListView
_GUICtrlListView_AddArray(GUICtrlGetHandle($ListView), $aLocalPrinters)

; Delete first element since it shows the count
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($ListView), 0)

While $ctr <= $aLocalPrinters[0][0]
; Printer Name
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 0, $LVSCW_AUTOSIZE)

; Is Printer Default? (Yes / No)
If $aLocalPrinters[$ctr][1] = True Then
_GUICtrlListView_SetItemSelected(GUICtrlGetHandle($ListView), $ctr - 1)
EndIf
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 1, $LVSCW_AUTOSIZE_USEHEADER)

; Printer Caption
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 2, $LVSCW_AUTOSIZE)

; Printer Type
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($ListView), 3, $LVSCW_AUTOSIZE)

$ctr += 1
WEnd
Return($ListView)
EndFunc ;==> End RefreshListView()

; *********************************************************************************************************
;  Check WMI Health
; *********************************************************************************************************
; WMI error - Lets try to fix it
If $WMICheck = 2 Then
; Only works on Windows XP Pro 32-Bit
If @OSVersion = "WIN_XP" And @OSArch = "x86" Then
$WMI_Repair_Path = @WindowsDir & 'ServicePackFilesI386'

; If admin then fix stuff
If IsAdmin() Then
; WMI is busted, notify the user.
ProgressOn("WMI Repair","WMI Repair","Repairing Local WMI Database", -1, -1, 16)
If FileExists($WMI_Repair_Path) Then

ProgressSet( 90, "Stopping SMS Agent Service")
RunWait('net stop ccmexec')

ProgressSet( 15, "Stopping Firewall/ICS Service")
RunWait('net stop sharedaccess')

ProgressSet( 30, "Stopping WMI Service")
RunWait('net stop winmgmt')

ProgressSet( 45, "Removing Corrupt WMI Database")
DirRemove(@WindowsDir & 'System32WbemRepository', 1)

ProgressSet( 60, "Rebuilding Clean WMI Database")
RunWait('winmgmt /resetRepository')

ProgressSet( 90, "Starting SMS Agent Service")
RunWait('net start ccmexec')

ProgressSet( 90, "Starting Firewall/ICS Service")
RunWait('net start sharedaccess')

ProgressSet( 75, "Starting WMI Service")
RunWait('net start winmgmt')

Sleep(10000)
Else
; We Failed, lets mark it with a "1" and use that for safe-mode
$SafeMode = 1
EndIf
Else
$SafeMode = 1
EndIf
ProgressOff()
Else
$SafeMode = 1
EndIf
EndIf

; *********************************************************************************************************
;  Get Remotely Available Printers
; *********************************************************************************************************
If $SafeMode = 0 Then
; Adding Build version to initial load screen -- (Build: 1301) -- Adam Seitz 11/07/2012
ProgressOn( "IT Help Tool " & $PPSVersion & " (Build: " & $PPSBuild & ")","IT Help Tool Loading...","Loading", -1, -1, 16)
ProgressSet( 0, "Detecting Print Server Name")

Global $PercentDone, $PrintServer, $aPrintQueues, $aPrintDetails[1][1], $aIPAddress, $aIPAddress1, $aIPAddress2, $aIPAddress3, $aIPAddress4, $aTemp1, $aTemp2

; Initialize TCP Functionality
TCPStartup()

; Open Connection to the Active Directory
If _AD_Open() Then

; Grab All IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
$aIPAddress1 = StringSplit(@IPAddress1, ".")
$aIPAddress2 = StringSplit(@IPAddress2, ".")
$aIPAddress3 = StringSplit(@IPAddress3, ".")
$aIPAddress4 = StringSplit(@IPAddress4, ".")

; Count IP Addresses -- (Build: 1203) -- Adam Seitz 10/12/2012
If $aIPAddress1[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress2[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress3[1] > 0 Then
$IPAddressCount += 1
EndIf
If $aIPAddress4[1] > 0 Then
$IPAddressCount += 1
EndIf

; Evaluate IP Addresses to determine if one is a PPS address
For $ctr = 1 to $IPAddressCount Step 1
; Set $aIPAddress to current IP Address
If $ctr = 1 Then
$aIPAddress = $aIPAddress1
ElseIf $ctr = 2 Then
$aIPAddress = $aIPAddress2
ElseIf $ctr = 3 Then
$aIPAddress = $aIPAddress3
ElseIf $ctr = 4 Then
$aIPAddress = $aIPAddress4
EndIf

; Assign Print Server Based on IP Address at some sites and discovery at the others.
If $aIPAddress[1] = "159" Then
;WNPRINT is not a standard address nor are the clients
$PrintServer = _TCPIpToName ('10.128.10.119')

; Added 127 (Build: 1203) -- Adam Seitz 10/11/2012
ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "127") Then
$PrintServer = _TCPIpToName ('10.128.10.119')

ElseIf ($aIPAddress[1] = "10") And ($aIPAddress[2] = "128") Then
$PrintServer = _TCPIpToName ('10.128.10.119')
Else
;<SITE>-PRINT is a standard naming convention, all servers use IP 10.<site>.8.7
; So by using the clients first two octets and appending 8.7 we get a valid ip to
; use as the print server.
$PrintServer = _TCPIpToName ( $aIPAddress[1] & '.' & $aIPAddress[2] & '.8.7' )
If @error Then
$PrintServer = False
EndIf
EndIf
Next

If Not $PrintServer = False Then
ProgressSet( 0, "Counting Printers on: " & $PrintServer & ".ad.ppsnet")

; The Name returned by _TCPIpToName() is FQDN we need a simple name.
$aTemp1 = StringSplit($PrintServer, ".")
$PrintServer = $aTemp1[1]

; Get a list of all PrintQueues in the AD tree
$aPrintQueues = _AD_ListPrintQueues($PrintServer)

; Verify the Returned Printers is actually valid
If Not IsArray($aPrintQueues) Then
$PrintServer = False
Else

; Order list by alphabet
_ArraySort($aPrintQueues)

; Get Printer Details
For $i = 1 to $aPrintQueues[0][0] Step 1
; Calculate Remaining Percentage of Bar
$PercentDone = (100 / $aPrintQueues[0][0]) * $i
ProgressSet( $PercentDone, "Querying Printer " & $i & " of " & $aPrintQueues[0][0] & ": " & $aPrintQueues[$i][0])

; Build Array
Redim $aPrintDetails[UBound($aPrintDetails) + 1][1]
$aTemp2 = _AD_GetObjectProperties($aPrintQueues[$i][2])
$aPrintDetails[$i][0] = $aTemp2[2][1]
Next
EndIf
; Close Connection to the Active Directory
_AD_Close()
EndIf
Else
$PrintServer = False
EndIf

; Close Progress Bar
ProgressOff()

; Turn off TCP Service to prevent Memory Leak
TCPShutdown()
EndIf

; *********************************************************************************************************
;  Get CPU Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Cpu_Core = 0, $Cpu_Arc, $Temp
Global $Cpu_Name = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","ProcessorNameString")
Global $Cpu_Clock = RegRead ("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor0","~MHz")

; Format CPU Information as Human Readable
If (@CPUArch = "X86") Then
$Cpu_Arc = "32-Bit"
ElseIf (@CPUArch = "X64") Then
$Cpu_Arc = "64-Bit"
Else
$Cpu_Arc = @CPUArch
EndIf

For $i= 1 to 1000
$Temp = RegEnumKey("HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessor", $i)
If @error <> 0 then
ExitLoop
EndIf
$Cpu_Core += 1
Next
EndIf

; *********************************************************************************************************
;  Get MEM Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $aMemoryInfo[1][100], $Mem_Num, $Mem_Text, $Mem_Percentage, $Mem_Readable, $Mem_Banks, $colMemory
Global $Readable_FormFactor[24] = ["Unknown","Other", "SIP","DIP","ZIP","SOJ","Proprietary","SIMM","DIMM","TSOP","PGA","RIMM","SODIMM","SRIMM","SMD","SSSMP","QFP","TQFP","SOIC","LCC","PLCC","BGA","FPBGA","LGA"]
Global $Readable_MemoryType[22] = ["Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM","RAM","ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR-2"]
Global $Mem_Count = 0, $Mem_Raw = MemGetStats()

; Clean Up the Text returned so it is presented a bit more readable
If ($Mem_Raw[1] > 0) and ($Mem_Raw[1] < 1000) Then
$Mem_Num = $Mem_Raw[1]
$Mem_Text = " KB"
ElseIf ($Mem_Raw[1] > 1000) and ($Mem_Raw[1] < 100000) Then
$Mem_Num = $Mem_Raw[1] /1024
$Mem_Text = " MB"
Else
$Mem_Num = $Mem_Raw[1] / 1024 / 1024
$Mem_Text = " GB"
EndIf

; Round Cleaner Number for final display text
$Mem_Percentage = $Mem_Raw[0]
$Mem_Readable = Round($Mem_Num, 2) & $Mem_Text

; Get Number of Physical Memory Banks on this motherboard
$aMemoryInfo = GetMemoryInfo()

; Get Number of Physical Memory Banks on this motherboard
$Mem_Banks = GetMemoryBanks()

EndIf

; *********************************************************************************************************
;  Get HDD Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$HDDVolume = DriveGetLabel("C:")
$HDDSerial = DriveGetSerial("C:")
$HDDTotal = DriveSpaceTotal("C:")
$HDDFree = DriveSpaceFree("C:")
Global $HDD_Percentage =  Round(( $HDDFree / $HDDTotal ) * 100)
EndIf

; *********************************************************************************************************
;  Get Uptime
; *********************************************************************************************************
If $SafeMode = "0" Then
Global $LastBootUp, $LocalDateTime, $colItems
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$LastBootUp = WMIDateStringToDate($objItem.LastBootUpTime)
$LocalDateTime = WMIDateStringToDate($objItem.LocalDateTime)
Next
EndIf
EndIf

; *********************************************************************************************************
;  Get Domain Membership
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $DOM_Hover, $DOM_Status = "No"
$colItems = $objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem")
For $obj In $colItems
If $obj.DomainRole = 1 Then
$DOM_Status = "Yes"
$DOM_Hover = "Machine is joined to Domain"
EndIf
Next
EndIf

; *********************************************************************************************************
;  Get Network Card Information
; *********************************************************************************************************
If $SafeMode = 0 Then
Global $Network_Card[1][50], $Network_Card_Count = 0

$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
$i = 1

If IsObj($colItems) Then
For $obj In $colItems
ReDim $Network_Card[UBound($Network_Card) + 1][50]
$Network_Card[$i][0] = $obj.Description
$Network_Card[$i][1] = $obj.DHCPEnabled
$Network_Card[$i][2] = $obj.MACAddress
$i += 1
Next
$Network_Card[0][0] = UBound($Network_Card) - 1
If $Network_Card[0][0] < 1 Then
SetError(1, 1, 0)
EndIf
Else
SetError(1, 2, 0)
EndIf
EndIf

; *********************************************************************************************************
;  Create Human Readable Information
; *********************************************************************************************************
Global $WINVER
If (@OSVersion = "WIN_2000") Then
$WINVER = "Windows 2000"
ElseIf (@OSVersion = "WIN_7") Then
$WINVER = "Windows 7"
ElseIf (@OSVersion = "WIN_8") Then ; -- (Build: 1203) -- Adam Seitz 10/12/2012
$WINVER = "Windows 8"
ElseIf (@OSVersion = "WIN_XP") Then
$WINVER = "Windows XP"
Else
$WINVER = @OSVersion
EndIf

;  Set Windows Service Pack to Human Readable
Global $WINSPK = @OSServicePack

; Evaluate (and make human readable) the service pack level  -- (Build: 1203) -- Adam Seitz 10/12/2012
If (IsString($WINSPK)) Then
$aTemp1 = StringSplit($WINSPK, " ")
If($aTemp1[1] = "Service") Then
$WINSPK = @OSServicePack
Else
$WINSPK = "Release"
EndIf
EndIf

; *********************************************************************************************************
;  Get VNC Status
; *********************************************************************************************************
Global $VNC_Hover, $VNC_Status

If ProcessExists("tvncserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
ElseIf ProcessExists("tvnserver.exe") Then
$VNC_Status = "Available"
$VNC_Hover = "Service is Running"
Else
$VNC_Status = "Not Available"
$VNC_Hover = "Service is not running or application is not installed."
EndIf

; *********************************************************************************************************
;  Get RDP Status
; *********************************************************************************************************
Global $RDP_Hover, $RDP_Status, $RDP_Check = RegRead("HKLMSYSTEMCurrentControlSetControlTerminal Server", "fDenyTSConnections")

; Check the Registry for Enable / Disable of RDP
;  0 = Available
;  1 = Disabled
If $RDP_Check = "0" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
Else
$RDP_Check = "Not Available"
$RDP_Hover = "Service is Not Running"
EndIf

; If Machine is on Domain the Registry key is not used any more, GPO sets it.
If $SafeMode = 0 And $DOM_Status = "Yes" Then
$RDP_Status = "Available"
$RDP_Hover = "Service is Running"
EndIf

; If Machine is on Windows 2000, then RDP does not exist.
If (@OSVersion = "WIN_2000") Then
$RDP_Status = "Not Available"
$RDP_Hover = "Windows 2000 does not support RDP."
EndIf

; *********************************************************************************************************
;  Get Absolute Manage Status
; *********************************************************************************************************
Global $ABS_Status, $ABS_Hover_1, $ABS_Hover_2, $ABS_File, $ABS_Ver

; See if it is installed
If FileExists(@ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe") Then
$ABS_File = @ProgramFilesDir & "Pole Position SoftwareLANrevAgentLANrev Agent.exe"
$ABS_Ver = RegRead("HKLMSOFTWAREPole Position SoftwareLANrev Agent","AgentVersion")
Else
$ABS_File = 0
$ABS_Ver = 0
EndIf

; Windows 2000 Only
If @OSVersion = "WIN_2000" Then
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1 is not supported on Windows 2000."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3 is not supported on Windows 2000."
$ABS_Status = "Not Available"
EndIf

; Windows XP and later
Else
If $ABS_Ver = "0" Then
$ABS_Hover_1 = "Absolute Manage Damaged / Missing."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.2.5" Then
$ABS_Hover_1 = "Absolute Manage 5.2.5 requires an upgrade to function."
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.3.1" Then
$ABS_Hover_1 = "Absolute Manage 5.3.1 requires an update to function"
$ABS_Status = "Not Available"
ElseIf $ABS_Ver = "5.4.1" Then
$ABS_Hover_1 = "Absolute Manage 5.4.1"
$ABS_Status = "Available"
ElseIf $ABS_Ver = "6.0.3" Then
$ABS_Hover_1 = "Absolute Manage 6.0.3"
$ABS_Status = "Available"
; Added Support for 6.1.3 -- (Build: 1301) -- Adam Seitz 11/07/2012
ElseIf $ABS_Ver = "6.1.3" Then
$ABS_Hover_1 = "Absolute Manage 6.1.3"
$ABS_Status = "Available"
EndIf
EndIf

; Determine if process is running
If ProcessExists("LANrev Agent.exe") Then
$ABS_Status = "Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Running"
Else
$ABS_Status = "Not Available"
$ABS_Hover_2 = $ABS_Hover_1 & " Process is Not Running."
EndIf

; *********************************************************************************************************
;  Get Microsoft Forefront Status
; *********************************************************************************************************
Global $FEP_Status, $FEP_Hover

; Determine if process is running
If ProcessExists("MsMpEng.exe") Then
$FEP_Status = "Available"
$FEP_Hover = " Process is Running"
Else
$FEP_Status = "Not Available"
$FEP_Hover = " Process is Not Running."
EndIf

; *********************************************************************************************************
;  Create Window
; *********************************************************************************************************
Global $MainGUI, $AddPrinterGUI, $AddPrinterExit, $AddPrinterList

$MainGUI = GuiCreate($PPSTitle & " - " & $PPSVersion & " (Build: " & $PPSBuild & ")", 500, 400) ; Window Style
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon
GUISetBkColor($GUIBackGroundColor)
GuiCtrlCreatePic($GUIImages & "Support_Info.jpg",0,0, 500, 100)

; Set Font Back to Larger for Banner
GUISetFont(12,0,0, $GUIFont)
GUICtrlCreateLabel("Computer Name:", 110, 10, 300, 20)

; Bold + Underline Computer Name
GUISetFont(12,400, 4, $GUIFont)
GUICtrlCreateLabel(@ComputerName, 235, 10, 300, 20)

; Back to Larger Font - No Underline or Bold
GUISetFont(12, 0, 0, $GUIFont)
GUICtrlCreateLabel("* Primary IP Address: " & @IPAddress1, 110, 40, 300, 20)

If @IPAddress2 > 0 Then
GUICtrlCreateLabel("* Secondary IP Address: " & @IPAddress2, 110, 60, 300, 20)
EndIf

; Set Font Back to Regular
GUISetFont($GUIFontSize, 0, 0, $GUIFont)

; *********************************************************************************************************
;  Create Tabbed User Window (Below Banner)
; *********************************************************************************************************
Global $Col_Num, $Row_Num, $tabbed, $hTab
$tabbed = GUICtrlCreateTab(5, 100, 490, 295)
$hTab = GUICtrlGetHandle($tabbed) ; get the handle for use in the notify events
If $SafeMode = 0 Then
GUICtrlCreateLabel( "",304,97,195,23) ; A blank White label to cover the tab ui grey'd background
Else
GUICtrlCreateLabel( "      IT Help Is Running In Safemode",125,97,370,23) ; A blank White label to cover the tab ui grey'd background
EndIf
; *********************************************************************************************************
; Tab 1: Support Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_1 = GUICtrlCreateTabItem("Support")
Else
$Tab_1 = GUICtrlCreateTabItem("SAFE MODE: Enabled")
If IsAdmin() Then
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "Rebooting your computer may clear this up.")
Else
MsgBox(0,"Safe Mode","SAFE MODE Information: " & @CRLF & @CRLF & "The IT Help Tool is running in safe mode because the Windows Managment Instrumentation sub-system on this computer is broken." & @CRLF & @CRLF & "An Attempt to fix it was made but you are not an Administrator on this machine.")
EndIf
EndIf

; Row 1: Contact Information
$Row_Num = 5.1
GUICtrlCreateLabel("Service Desk Phone:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("(503) 916-3375", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 2: Contact Information
$Row_Num = 6.1
GUICtrlCreateLabel("Service Desk Email:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlCreateInput("itservicedesk@pps.net", $Data_Row_Offset-20, $Data_Col_Offset*$Row_Num, $Data_Length+40, $Data_Height)

; Row 3: Buttons
$Row_Num = 7.1
$Button_1 = GuiCtrlCreateButton("IT Homepage", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length-50, $Label_Height)
GuiCtrlSetTip(-1, 'http://www.pps.net/departments/information-technology')

; Group 1: Left Column
GuiCtrlCreateGroup("Vital Signs", 10, 200, 200, 150)

; Column 1 - 1: VNC Service
$Col_Num = 1
$Row_Num = 8.9
GUICtrlCreateLabel("VNC Remote Control:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $VNC_Hover)
If $VNC_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 2: RDP Service
$Col_Num = 1
$Row_Num = 9.9
GUICtrlCreateLabel("Remote Desktop Protocol:", $Label_Row_Offset*$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $RDP_Hover)
If $RDP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset*$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 3: Domain Check
$Row_Num = 10.9
$Col_Num = 1
GUICtrlCreateLabel("Domain Status:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlSetTip(-1, $DOM_Hover)
If $DOM_Status = "Yes" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf
EndIf

; Column 1 - 4: Absolute Manage Client
$Row_Num = 11.9
$Col_Num = 1
GUICtrlCreateLabel("Absolute Manage Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $ABS_Hover_2)
If $ABS_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Column 1 - 5: Microsoft Forefront Endpoint Protection
$Row_Num = 12.9
$Col_Num = 1
GUICtrlCreateLabel("Forefront Endpoint Client:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
GUICtrlSetTip(-1, $FEP_Hover)
If $FEP_Status = "Available" Then
GuiCtrlCreatePic($GUIImages & "Green_Check.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
Else
GuiCtrlCreatePic($GUIImages & "Red_X.jpg",$Data_Row_Offset+$Col_Num, $Data_Col_Offset*$Row_Num, 20, 20)
EndIf

; Group 2: Right Column
GuiCtrlCreateGroup("System Information", 210, 200, 275, 150)

; Column 2 - 1: Last Rebooted Information
$Row_Num = 8.9
$Col_Num = 190
GUICtrlCreateLabel("Last Rebooted:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($LastBootUp, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 2: Processor Information
$Row_Num = 9.9
$Col_Num = 190
GUICtrlCreateLabel("Processor is a:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Cpu_Arc & " (" & $Cpu_Core & " Core): " & Round($Cpu_Clock / 1000, 2) & " GHz", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 3: Memory Information
$Row_Num = 10.9
$Col_Num = 190
GUICtrlCreateLabel("Memory:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($Mem_Readable & " (" & $Mem_Percentage & "% Used)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 4: Drive Free Space
$Row_Num = 11.9
$Col_Num = 190
GUICtrlCreateLabel("Free Space:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput("" & Round($HDDFree /1024,1) & " GB" & " (" & $HDD_Percentage & "% Free)", $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; Column 2 - 5: Print Server
$Row_Num = 12.9
$Col_Num = 190
GUICtrlCreateLabel("Print Server:", $Label_Row_Offset+$Col_Num, $Label_Col_Offset*$Row_Num+3, $Label_Length, $Label_Height)
If $SafeMode = 0 Then
GUICtrlCreateInput($PrintServer, $Data_Row_Offset+$Col_Num-65, $Label_Col_Offset*$Row_Num, $Label_Length-10, $Label_Height)
EndIf

; *********************************************************************************************************
; Tab 2: Computer Information
; *********************************************************************************************************
If $SafeMode = 0 Then

; Read in the Registry Values
GetRegValues()

$Tab_2 = GUICtrlCreateTabItem("Computer")

; Row 1: Room Number
$Row_Num = 5.1
GUICtrlCreateLabel("Room Number:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_RoomNumber = GUICtrlCreateInput("" & $Reg_RoomNumber, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: Purchase Order
$Row_Num = 6.1
GUICtrlCreateLabel("Purchase Order:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_PurchaseOrder = GUICtrlCreateInput("" & $Reg_PurchaseOrder, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Managed By
$Row_Num = 7.1
GUICtrlCreateLabel("Managed By:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_ManagedBy = GUICtrlCreateInput("" & $Reg_ManagedBy, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 14: Buttons
$Row_Num = 14.2

; Row 14: Button 7: Save Changes
$Button_7 = GuiCtrlCreateButton("Save", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Save changes to above fields.')
If IsAdmin() = False Then
GUICtrlSetState($Button_7, $GUI_DISABLE)
EndIf

; Row 14: Button 8: Discard Changes
$Button_8 = GuiCtrlCreateButton("Discard", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Discard Changes and reload default settings.')

EndIf

; *********************************************************************************************************
; Tab 3: Print Manager
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_6 = GUICtrlCreateTabItem("Printer")
Global $answer, $Command, $Radio, $Combo, $ComboBox, $Input_PrintServer, $Input_DefaultPrinter

; Progress Bar Window position centered, near bottom.
Global $iGuiHeight = 100
Global $iGuiWidth = 100
Global $iGuiXPos = (@DesktopWidth/2)-$iGuiWidth-50
Global $iGuiYPos = (@DesktopHeight/2)-$iGuiHeight/2

; List All Printers
$Row_Num = 5.1

$ListView = GUICtrlCreateListView( "Name|Default|Description|Type", 9, 124, 479, 220, -1, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

; Get List of Installed Printers
$aLocalPrinters = GetLocalPrinters()

; Display  the Printers on the ListView
RefreshListView()

$Row_Num = 14.2
; Button: Delete Selected Printer
$Button_2 = GuiCtrlCreateButton("Delete Printer", $Label_Row_Offset + 360, $Label_Col_Offset*$Row_Num, 100, 30)
GuiCtrlSetTip(-1, 'Deletes Highlighted Printer.')
GUICtrlSetState($Button_2, $GUI_DISABLE)

; Button: Add Printers
$Button_3 = GuiCtrlCreateButton("Add Printer", $Label_Row_Offset - 13, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Add a new printer.')
If $PrintServer = False Then
GUICtrlSetState($Button_3, $GUI_DISABLE)
EndIf

; Button: Make Default
$Button_4 = GuiCtrlCreateButton("Set Default", $Label_Row_Offset + 87, $Label_Col_Offset*$Row_Num, 0, 30)
GuiCtrlSetTip(-1, 'Sets Highlighted Printer as Default Machine Printer.')

EndIf

; *********************************************************************************************************
; Tab 4: User Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_3 = GUICtrlCreateTabItem("User")

; Row 1: Current User Name
$Row_Num = 5
GUICtrlCreateLabel("User Name:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_CurrentUserName = GUICtrlCreateInput("" & @UserName, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 2: My Documents
$Row_Num = 6
GUICtrlCreateLabel("My Documents:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_MyDocumentsDirectory = GUICtrlCreateInput("" & @MyDocumentsDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 3: Desktop Directory
$Row_Num = 7
GUICtrlCreateLabel("Desktop Directory: ", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_DesktopDirectory = GUICtrlCreateInput("" & @DesktopDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 4: Start Menu Directory
$Row_Num = 8
GUICtrlCreateLabel("Start Menu Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_StartMenuDirectory = GUICtrlCreateInput("" & @StartMenuDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)

; Row 5: Temporary File Directory
$Row_Num = 9
GUICtrlCreateLabel("Temporary File Directory:", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, $Label_Length, $Label_Height)
$Input_TemporaryFileDirectory = GUICtrlCreateInput("" & @TempDir, $Data_Row_Offset, $Data_Col_Offset*$Row_Num, $Data_Length, $Data_Height)
EndIf

; *********************************************************************************************************
; Tab 5: Network Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_4 = GUICtrlCreateTabItem("Network")
$Row_Num = 5

For $i = 1 to $Network_Card[0][0]
GuiCtrlCreateLabel($Network_Card[$i][0], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * MAC Address: " & $Network_Card[$i][2], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 0.5
GuiCtrlCreateLabel(" * DHCP Enabled: " & $Network_Card[$i][1], $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)

$Row_Num = $Row_Num + 1
Next
EndIf

; *********************************************************************************************************
; Tab 6: Memory Information
; *********************************************************************************************************
If $SafeMode = 0 Then
$Tab_5 = GUICtrlCreateTabItem("Memory")
$Row_Num = 5.1
Global $Mem_Temp
GuiCtrlCreateLabel($aMemoryInfo[0][0] & " of " & $Mem_Banks & " Memory Banks Used", $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
For $i = 1 to $Mem_Banks Step 1
$Row_Num += 1
If $i > $aMemoryInfo[0][0] Then
$Mem_Temp = "[ BANK " & $i & "] is Empty"
Else
$Mem_Temp = "[ BANK " & $i & "] " & $aMemoryInfo[$i][2] / 1024 / 1024 & " MB "& $Readable_MemoryType[$aMemoryInfo[$i][4]]& " " & $Readable_FormFactor[$aMemoryInfo[$i][3]] & " Running at "& $aMemoryInfo[$i][5] & " MHz"
EndIf
GuiCtrlCreateLabel($Mem_Temp, $Label_Row_Offset, $Label_Col_Offset*$Row_Num, 400, $Label_Height)
Next
EndIf

; *********************************************************************************************************
;  Show / Update the GUI
; *********************************************************************************************************
GuiSetState(@SW_SHOW)

; End Tabbing
GUICtrlCreateTabItem("")

; Run the GUI until the dialog is closed
While 1
$GUIEvent_1 = GUIGetMsg()
Select
; Window Closed with "Close" window control
Case $GUIEvent_1 = $GUI_EVENT_CLOSE
ExitLoop

; BUTTON_1: Link Button on "Support" Tab
Case $GUIEvent_1 = $Button_1
Run(@ProgramFilesDir & "Internet Exploreriexplore.exe http://www.pps.net/departments/information-technology/")

; BUTTON_2: Delete Selected Printer on "Print" Tab
Case $GUIEvent_1 = $Button_2 And $SafeMode = 0 ; <---- Delete printers by check box
If IsAdmin() Then
For $i = 1 to $aLocalPrinters[0][0] Step 1
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]
EndIf
Next
$answer = MsgBox(BitOr(0x4, 0x20),"Delete Printers","Are you sure you want to delete: " & $Selection)
If $answer = "6" Then
; Begin progress bar
ProgressOn("Deleting Printer","Removing: " & $Selection,"Removing", -1, -1, 16)
ProgressSet(25, "Removing: " & $Selection)

; Delete the printer for all of the places in the registry it is possible to see it installed
DeletePrinter()

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 75 to 100 Step 5
Sleep(1000) ;1 Second
ProgressSet($i, "Updating System")
Next

; Update UI
ProgressSet(100, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressOff()

EndIf
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_7: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_7 And $SafeMode = 0
MsgBox(0,"Save","Saved changes")
; Update UI
ProgressSet(100, "Refreshing Window")
SetRegValues()
RefreshRegView()
ProgressOff()

; BUTTON_8: Save Changes on "Computer" Tab
Case $GUIEvent_1 = $Button_8 And $SafeMode = 0
MsgBox(0,"Discard","Discarded changes")
; Update UI
ProgressSet(100, "Refreshing Window")
GetRegValues()
RefreshRegView()
msgbox(0,"debug",$Input_RoomNumber)
ProgressOff()

; BUTTON_3: Add a Printer on "Print" Tab
Case $GUIEvent_1 = $Button_3 And $SafeMode = 0
If IsAdmin() Then
; Build Add Printer Wizard GUI
$AddPrinterGUI = GUICreate( "Add Printer Wizard", 350, 110, -1, -1)
GuiCtrlCreateLabel($PrintServer & ".ad.ppsnet", 5, 5, 100, $Label_Height)
GuiSetIcon($GUIImages & "PPS_Logo_16x16.ico", 0) ; Window small icon

; Drop-Down Listbox of Printers
$ComboBox = GUICtrlCreateCombo("", 25, 25, 300, 30) ; create first item

; Loop to populate listBox with printers from the printer queue
For $i = 1 to $aPrintQueues[0][0] Step 1
GUICtrlSetData($ComboBox, $aPrintQueues[$i][0])
Next

; BUTTON_5: Exit Button on "Print" Tab -> Add Printer Wizard
$Button_5 = GUICtrlCreateButton("Exit", 160, 65, 100, 30)
GuiCtrlSetTip(-1, 'Exits the Add Printer Wizard')

; INSTALL Button
$Button_6 = GUICtrlCreateButton("Install", 50, 65, 100, 30)
GuiCtrlSetTip(-1, 'Installs the Selected Printer')

; Set GUI Visible and disable the install printer button
GUISetState(@SW_SHOW)
GUICtrlSetState($Button_6, $GUI_DISABLE)

; Loop until exited
While 2

; Update $GUIEvent_2 with whatever has happened since last loop
$GUIEvent_2 = GUIGetMsg()

; Switch on $GUIEvent_2 messages for work to be done.
Select
; Close Window was clicked
Case $GUIEvent_2 = $GUI_EVENT_CLOSE And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; Exit Button was Clicked
Case $GUIEvent_2 = $Button_5 And $SafeMode = 0
GUIDelete($AddPrinterGUI)
ExitLoop

; ComboBox was Updated
Case $GUIEvent_2 = $ComboBox And $SafeMode = 0
$Selection = GUICtrlRead($ComboBox)

; If the Selection was BLANK it's not valid
If Not $Selection = "" Then
If GUICtrlGetState($Button_6) = 144 Then
GUICtrlSetState($Button_6, $GUI_ENABLE)
EndIf
EndIf

; Install Printer button was pressed
Case $GUIEvent_2 = $Button_6 And $SafeMode = 0
; Notify the User of install progress
ProgressOn("Add Printer","Adding: " & $Selection,"Adding", -1, -1, 16)
GUIDelete($AddPrinterGUI)

ProgressSet(25, "Adding: " &$Selection)
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /q /ga /c' & @ComputerName & ' /n "' & $PrintServer & ".ad.ppsnet" & $Selection & '"', @WindowsDir, @SW_HIDE)

; Restart Print Spooler
ProgressSet(50, "Restarting Print Spooler")
RestartPrint()

; Wait a bit for local processing to happen
ProgressSet(75, "Updating System")
For $i = 50 to 75 Step 5

ProgressSet($i, "Updating System")
GetLocalPrinters()
RefreshListView()

Sleep(500) ;0.5 Seconds

Next

; Update UI
ProgressSet(100, "Done")
ProgressOff()
GetLocalPrinters()
RefreshListView()
ExitLoop

EndSelect
WEnd

; Update UI
GetLocalPrinters()
RefreshListView()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; BUTTON_4:  Set Default Printer Button on "Print" Tab
Case $GUIEvent_1 = $Button_4 And $SafeMode = 0
If IsAdmin() Then
For $i = 0 to $aLocalPrinters[0][0] Step 1
ProgressOn( 'Default','Setting Default','Default', -1, -1, 16)
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
ProgressSet(33, "Running Command")
RunWait(@ComSpec & " /c " & 'start /wait /min rundll32 printui.dll,PrintUIEntry /y /n "' & $aLocalPrinters[$i + 1][0] & '"', @WindowsDir, @SW_HIDE)
ProgressSet(66, "Refreshing Window")
GetLocalPrinters()
RefreshListView()
ProgressSet(100, "Completed")
Sleep(1000)
EndIf
Next
ProgressOff()
Else
MsgBox(0,"Error","You are not an administrator on this machine")
EndIf

; Processes to Monitor while ListView is inactive
Case $ListView And $SafeMode = 0
; Check to see what is selected
For $i = 0 to $aLocalPrinters[0][0] Step 1

; Look for current selection
If _GUICtrlListView_GetItemSelected($ListView, $i) = "True" Then
$Selection = $aLocalPrinters[$i + 1][0]

; If the Selection "iPrint" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "iPrint" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Local" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Local" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

; If the Selection "Networked" Enable Button (if not already enabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Networked" Then
If GUICtrlGetState($Button_2) = 144 Then
GUICtrlSetState($Button_2, $GUI_ENABLE)
EndIf
EndIf

;If the Selection "Protected" Disable Button (if not already disabled)
If _GUICtrlListView_GetItemText($ListView, $i, 3) = "Protected" Then
If GUICtrlGetState($Button_2) = 80 Then
GUICtrlSetState($Button_2, $GUI_DISABLE)
EndIf
EndIf
EndIf
Next
EndSelect
WEnd
Edited by aseitz

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Variable $Input_RoomNumber holds the ControlId returned by GuiCtrlCreateInput. That's why just assigning a new value is wrong.

See my post #6. You need to use GuiCtrlSetData(<ControlId>, "New value")

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Ohh I see what you are saying, I didn't track tha very well. I am totally double using those variables. I'll fix that now.

Share this post


Link to post
Share on other sites

THANKS!!! That was a total over-sight on my part, thanks again! :)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Glad you got your problem solved :D

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0