Sander Timmerman Posted January 31, 2008 Share Posted January 31, 2008 (edited) I am trying to make a little program that does a bit of loadbalancing between terminalservers. It does this by querying the active sessions of an TS throug WMI. When I ran it on an server it went well! But on my XP client it gives errors What can I do? This is the code: expandcollapse popup#include <GUIConstants.au3> $Form1 = GUICreate("Centraal", 290, 113) $Label1 = GUICtrlCreateLabel("Test", 8, 8, 266, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Button1 = GUICtrlCreateButton("Maak verbinding met centraal", 50, 40, 179, 25, 0) $Label2 = GUICtrlCreateLabel("Client status:", 8, 88, 64, 17) GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif") $Label3 = GUICtrlCreateLabel("Wachtend op gebruiker...", 80, 88, 122, 17) GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) Dim $Result = "" While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1 balance() EndSelect WEnd ;Roep WMI query aan en bereken laagste load Func balance() GUICtrlSetData($Label3, "Querying WMI TS2") WMI("10.1.1.2") $ts2_s = $Result GUICtrlSetData($Label3, "Querying WMI TS3") WMI("10.1.1.3") $ts3_s = $Result GUICtrlSetData($Label3, "Querying WMI TS4") WMI("10.1.1.4") $ts4_s = $Result GUICtrlSetData($Label3, "Querying WMI TS5") WMI("10.1.1.1") $ts5_s = $Result GUICtrlSetData($Label3, "Berekenen laagste load...") Select Case $ts2_s < $ts3_s AND $ts4_s And $ts5_s $vrije_ts = "10.1.1.2" Case $ts3_s < $ts2_s And $ts4_s And $ts5_s $vrije_ts = "10.1.1.3" Case $ts4_s < $ts2_s And $ts3_s And $ts5_s $vrije_ts = "10.1.1.4" Case $ts5_s < $ts2_s And $ts3_s And $ts4_s $vrije_ts = "10.1.1.5" Case $ts2_s = $ts3_s And $ts4_s And $ts5_s $vrije_ts = "10.1.1.2" EndSelect MsgBox(0,"",$vrije_ts) GUICtrlSetData($Label3, "MSTC word gestart...") EndFunc ;WMI query Func WMI($strComputer) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $Output = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_TermService_TerminalServices", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) For $objItem In $colItems $Output = $objItem.ActiveSessions Next Global $Result = $Output EndFunc ;==>WMI Thanks in advance! Regards, Sander (Dutch) Edited January 31, 2008 by Sander Timmerman Link to comment Share on other sites More sharing options...
Sander Timmerman Posted January 31, 2008 Author Share Posted January 31, 2008 40 views but no one knows an anwser?! Come on experts!! Link to comment Share on other sites More sharing options...
rover Posted January 31, 2008 Share Posted January 31, 2008 I'll take a wild stab at it could it be because you are on a workgroup on your xp machine, whereas the server you ran it on has a domain server? I had to use either the @ComputerName macro or enter my computer name for $strComputer it would crash if IP used instead of computername you should add an error handler function and use 'Return' instead of Global for WMI() $ts2_s = WMI("ComputerName") ;.... Return $Output EndFunc ;==>WMI $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Func MyErrFunc() ;Return $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns1 Return Endfunc I see fascists... Link to comment Share on other sites More sharing options...
ptrex Posted January 31, 2008 Share Posted January 31, 2008 @Sander TimmermanThe error is the following you WMI cannot connect remotely to the server to get the details from the Objects.Therefore you need to make a REMOTE WMI call to the serverSome WMI SecretsThis will get you started.Groeten / Regardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Sander Timmerman Posted January 31, 2008 Author Share Posted January 31, 2008 Well, i've added the users to the WMI ACL list and gave them full control, but still it wont work I've tested in on a machine that is in the domain an can ping the server. I've attached a screenshot with the error. Can you help me with fixing the code?! I can do a little autoit, but this WMI stuff get's me crazy Thanks in advance Regards, Sander (Dutch) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now