Valiante Posted July 16, 2008 Share Posted July 16, 2008 I've searched the forums and have tried using example code word for word, but I'm persistently presented with the same error. Am I missing something?CODE:$strComputer = @ComputerName $strUser = "username" $strPassword = "password" $wmiLocator = ObjCreate("WbemScripting.SWbemLocator") $wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword)ERROR:>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "F:\AU3\wmiLocator.au3" F:\AU3\wmiLocator.au3 (6) : ==> The requested action with this object has failed.: $wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword) $wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword)^ ERROR >Exit code: 1 Time: 1.908 Link to comment Share on other sites More sharing options...
ptrex Posted July 16, 2008 Share Posted July 16, 2008 @Valiante This should get you going $strComputer = "." $strUser = "" $strDomain = "domain" $strPassword = "" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objSWbemLocator.ConnectServer($strComputer,"root\CIMV2",$strUser, $strPassword) ;, "MS_409", "ntlmdomain:" & $strDomain) $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") For $objItem in $colItems ConsoleWrite($Output & $objItem.Name & @LF & @LF) ; returns the local CMP name !! Next Regards, ptrex meoit 1 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...
Valiante Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks ptrex. Unfortunately that's pretty much the same code syntax-wise, and as such I get exactly the same error. Note: This function works with VBscript so I know it's not the system at fault here, but I have strong to desire to port this over to AutoIt for user-friendliness and expansion. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 16, 2008 Share Posted July 16, 2008 Thanks ptrex. Unfortunately that's pretty much the same code syntax-wise, and as such I get exactly the same error. Note: This function works with VBscript so I know it's not the system at fault here, but I have strong to desire to port this over to AutoIt for user-friendliness and expansion. Post the exact VBScript code for the same function for comparison. The code by ptrex works fine for me, because I am logged in as an Admin. If I put username/password credentials instead of "", it fails. So I wonder about impersonate flags, etc., giving permissions here. Seeing the working VBScript would help. muttley PS: This version of your AutoIt script also works fine with null username/password, but fails with valid credentials: $strComputer = @ComputerName $strUser = "" $strPassword = "" $wmiLocator = ObjCreate("WbemScripting.SWbemLocator") $wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword) If IsObj($wmiService) Then ConsoleWrite("Debug: $wmiService is an object type: " & ObjName($wmiService) & @LF) Else ConsoleWrite("Debug: Error: $wmiService is not an object.") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ptrex Posted July 16, 2008 Share Posted July 16, 2008 @all Without the COM error handler it is hard to know where you are going. Regards ptrex 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...
Valiante Posted July 16, 2008 Author Share Posted July 16, 2008 Haha - I was substituting the otherwise blank values with my username & password. If I literally copy & paste the above, leaving them blank, it does indeed work. But what do I do about connecting to another machine (which is the main aim of this script)? Link to comment Share on other sites More sharing options...
Valiante Posted July 16, 2008 Author Share Posted July 16, 2008 Sorry for the double-post, but I thought I should quote the VBScript as requested by PsaltyDS. Basically what it's for is to enable the Server service (which is disabled by policy in our domain) so we can temporarily do some remote admin where needed. This VBScript works; strComputer=InputBox("Please enter the target computername ",,"") strUser=InputBox("Please enter the username you wish to connect with ") strDomain=InputBox("Please enter the domain for " &strUser) strPassword=InputBox("Please enter the password for " & strDomain&"\"&strUser) Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",strUser, strPassword) If Err.Number<>"0" Then WScript.Echo "Cannot find machine: "& strComputer & WScript.Quit Set WindowsServices = objWMIService.ExecQuery("Select * from Win32_Service where Name='LanmanServer'") For each strService in WindowsServices StrService.ChangeStartMode("manual") strService.StartService() Next Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 16, 2008 Share Posted July 16, 2008 @all Without the COM error handler it is hard to know where you are going. Regards ptrex Good point: $strComputer = @ComputerName $strUser = "" $strPassword = "" $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler $wmiLocator = ObjCreate("WbemScripting.SWbemLocator") $wmiService = $wmiLocator.ConnectServer($strComputer, "root\cimv2", $strUser, $strPassword) If IsObj($wmiService) Then ConsoleWrite("Debug: $wmiService is an object type: " & ObjName($wmiService) & @LF) Else ConsoleWrite("Debug: Error: $wmiService is not an object.") EndIf ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) $g_eventerror = 1; something to check for when this function returns Endfunc I get error code 80020009 if using credentials, which is just query failed - I think. muttley Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 16, 2008 Share Posted July 16, 2008 Haha - I was substituting the otherwise blank values with my username & password. If I literally copy & paste the above, leaving them blank, it does indeed work. But what do I do about connecting to another machine (which is the main aim of this script)?Just noticed something new: I works fine on a remote computer with credentials. It only fails with credentials on the LOCAL computer! I suspect it just doesn't want to create DUPLICATE authentication to the same machine, since you're already logged in to it. Try logging on as a different user than the credentials you are using and see if that gets you access to the local stuff. muttley minimen456 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Valiante Posted July 17, 2008 Author Share Posted July 17, 2008 Hmm... interestingly, if I specify an XP workstation as the target machine, it works, with or without credentials, as I'm a local admin on all our XP workstations. However, if I target a Vista machine (with UAC on and Server service disabled) it errors as above.Next step: Try running the script from an XP workstation, then again from Vista with UAC switched off. I'll post the results. Link to comment Share on other sites More sharing options...
Valiante Posted July 17, 2008 Author Share Posted July 17, 2008 Ok, ignore that - the machine I was targeting originally was using a different IP address to the one registered in DNS (we have DNS issues here). I found a machine that was responding to ping with the correct address and when targeting that with admin credentials, all is well. So it was a networking issue after all. Dear me. 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