Jump to content

nikink

Active Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by nikink

  1. What about from a ps commandline? I have a PShell function I want to pass commands to, and return the PS console output. Like so: PShell_ConsoleCapture("Get-ADComputer -Identity PC-Name") ; example PS only Func PShell_ConsoleCapture($sCmdline) $sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command " & $sCmdline $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($pid, @CRLF) ; Close STDIN StdinWrite($pid) ; Get output from STDOUT $sSTDOUT = "" While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput ; Drops empty lines WEnd ; Get output from STDERR $sSTDERR = "" While 1 $sOutput = StderrRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput ; Drops empty lines WEnd ConsoleWrite("Output:" & @CRLF & $sOutput) ConsoleWrite("$sSTDERR:" & @CRLF & $sSTDERR) Return EndFunc Neither $sOutput nor $sSTDERR contain data. Any help would be appreciated.
  2. Thanks! It didn't work for me, but I appreciate the link. I'll respond in that thread.
  3. D'oh! Massive facepalm to me and thankyou! Works like a charm when you format it right! 😐
  4. Hi I'm trying to detect the existence of a computer object but _AD_ObjectExists is only returning 0. My code: _AD_Open() If @error Then Local $sError = @error, $sExtended = @extended Local $sAD_Hive = "HKLM", $sErrorMsg If @OSArch = "IA64" Or @OSArch = "X64" Then $sAD_Hive = "HKLM64" Local $sAD_OSVersion = RegRead($sAD_Hive & "\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion") $sAD_OSVersion = StringSplit($sAD_OSVersion, ".") If Int($sAD_OSVersion[1]) >= 6 Then ; Delivers detailed error information for Windows Vista and later if debugging is activated Local $aAD_Errors = _AD_GetLastADSIError() If $aAD_Errors[4] <> 0 Then $sErrorMsg = $aAD_Errors[5] EndIf LogMe("Error accessing the Active Directory. @Error: " & $sError & ", @extended: " & $sExtended & @CRLF & $sErrorMsg) Else LogMe('Connected to AD') EndIf Local $iResult = _AD_ObjectExists($sComputerName) LogMe("RESULT! [" & $iResult & "]") _AD_Close() $iResult is always 0. I've tried _AD_ObjectExists("$" & $sComputerName) as well. I'm sure it's something incredibly obvious but I just can't see it. Any help appreciated!
  5. I guess my ultimate goal is actually to detect whether a computer exists in our Active Directory or not. I've tried a powershell commandline because it was fast. My existing method relies on querying AD for all computer objects then searching the array of all objects. So yeah, inefficient. 😐
  6. Hi, I'm using Au3 to run a pshell cmdline and I can see the pshell output in the scite console but I can't capture it in a variable. What am I doing wrong? Func PShell($sCmdline) ;Invoke powershell commandline passed to this function ;Return Powershell Output string ; ALSO: REMOTE PSHELL: Invoke-Command -Computer XXXXX -ScriptBlock{CommandToRun} ;set up powershell cmdline Local $sCommands Local $RunThis = "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command " & $sCommands LogMe($RunThis) ; Run powershell cmdline Local $iPID = Run(@ComSpec & ' /c ' & $RunThis, "", @SW_HIDE , $stdout_child) Local $sOutput = "" ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($iPID) ; Capture powershell cmdline outputstream $sOutput = StdoutRead($iPID) If @error Then ; Powershell output stream has ended LogMe("Powershell output stream has ended - Stdoutread(" & $iPID & ": " & @error & ').' & @LF & 'Finished executing: ' & @LF & $RunThis & @LF & 'Note: This does NOT mean the cmdline worked, only that it finished executing.', $bDisplayMsg) EndIf Return $sOutput EndFunc $sOutput is returning "Error: Stoutread(7448: 1)" where 7448 is the PID I think. So yeah, scratching my head and hoping someone can help.
  7. Hi all, I've been trying to get my head around how this works and have come across a strange issue whereby I can't clear an input field anymore. When I was doing some preliminary testing I found that _WD_SetElementValue($sSession, $sInputElement, "") worked to clear existing data. But now, it doesn't? Not sure if I was simply mistaken before (entirely possible) or if the latest Firefox broke the behaviour somehow? EIther way, my goal is to clear an input field so I can put another string into it. Func Google_Navigation($sURL = "https://www.google.com") Local $XPath. $sInputElement _WD_Navigate($sSession, $sURL) ;;;;;;;;;;;;;;;;;; MY CODE :::::::::::::::: $XPath = "/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input" $sInputElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $XPath) ;should find the search input field ConsoleWrite("$sInputElement = " & $sInputElement & @CRLF) _WD_SetElementValue($sSession, $sInputElement, "stuff") MsgBox(0,"Check Google", "Input says 'Stuff'.") _WD_SetElementValue($sSession, $sInputElement, "") MsgBox(0,"Check Google", "Input should be blank...?") EndFunc Any help very appreciated. EDIT: D'Oh! _WD_ElementAction($sSession, $sInputElement, "Clear") works. Why did I have to find that just after posting for help?
  8. Absolutely correct on all counts, Mikell and Nine. Thanks for helping!
  9. That seems to work perfectly! Thanks so much! Obviously I was getting quite stuck on the tail - confusing myself utterly while your solution there is neat and on point.
  10. Hi all, I'm struggling to get some regex patterns right and am hoping someone better at them than me can help. I have a string that looks like: N: nikink-vm2, nikink-vm, xstf1111a9lt986 M: ABCDEFABCDEG, 12acac12acac O: 123 D: Stuff and details and things ON 1234 The O: is order number, the N: is name(s), the M: is mac address(es), the D : is old information (all alphanum plus colon, dash, and comma). The O/N/M/D fields are all optional - they may or may not exist, and they might be in any order. (My script is part of a move to ensure all fields are present even if empty) So if they *do* exist I want to parse out the values - for example GetOrderNumer returns "123", GetNames returns "nikink-vm2, nikink-vm, xstf1111a9lt986" and so on. My regex patters so far are: $NamesPattern = "(?:N:\s*([A-Za-z0-9-,\s]*)\s)" $MacssPattern = "(?:M:\s*([A-Za-z0-9-,\s]*)\s?[^O:|N:|M:|D:])" $OrderPattern = "(?:O:\s*([0-9]*)\s?)" $DetailsPattern = "(?:D:\s*([A-Za-z0-9-,\s]*)\s?[^O:|N:|M:])" And they are very close to working correctly! But for example, if I move the N: filed from the front to the end of that string, the pattern returns only "nikink-vm2, nikink-vm," (completely missing the third entry). If I move the Mac field to the end it returns "ABCDEFABCDEG, 12acac12aca" (cutting off the final 'c'). When I start refining the regex my lack of actual understanding shows. For example using: (?:(N:\s*([A-Za-z0-9-]*(,?(\s)*)?)*\s*[^M:])) to capture names gives me a leading N: (which I don't want if it can be avoided). The [^M:] at the end is just my attempt to stop the pattern from returning the following 'M' and because the fields could be in any order that needs to account for O and D as well and I'm having a hell of a time getting that to work as well. In all cases I'm testing this with the stringregexgui.au3 from the StringRegExp help file. Any help would be greatly appreciated.
  11. Ok, thanks for that! I'll give it a try - it might be ok as a workaround.
  12. Hi all, I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14. I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong. Anyway, the code to replicate my issue is: Test('username', 'DOMAIN') ; THIS ERRORS: ;Test('localun', 'DOMAIN') ; THIS ERRORS: ;Test(' ', ' ') ; THIS ERRORS: ;Test('', '') ; THIS ERRORS: ;Test('localun', '') ; THIS ERRORS: ;Test('', 'DOMAIN') Func Test($un, $dom) $compName = 'PCNAME' $FullName = '.' $Description = '.' ; get the WIM object $objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2") ; get default user full name and description $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") If IsObj($objAccount) Then $FullName = $objAccount.FullName $Description = $objAccount.Description EndIf ConsoleWrite($FullName & @CRLF) ConsoleWrite($Description & @CRLF) Return EndFunc On my old PC this code will output just . and . for each of those line currently commented out. Which is fine. On my new PC any of those commented out lines of code cause an error, and the script won't even compile. $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") $objAccount = $objWMIService^ ERROR I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement. Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?
  13. Aha! ok, my version is 3.3.12 - I'd missed the new release. Thanks.
  14. Very neat. I get an error about $SHEX_OPEN when I compile - I assume there's a missing include? I've simply replaced it with "Open" for now.
  15. Is there a way to make the generated QR image bigger? If I take the current size and enlarge it, it gets quite blurry around the edges.
  16. Oh wow. The ol' double square bracket trick... Thankyou so much! That seems to be perfect! You even caught the missing AB in the [89ab] set.
  17. Hi all, it's been a while since I last used regular expressions and I find myself out of time to experiment with this particular issue, so I throw myself upon your mercy and expertise. I am looking to create a function that will say whether or not a supplied string is a valid UUID or not. Local $sTestF = '4C4C4544-004A-4C10-8054-B7C04F46343' Local $sTestT = '4C4C4544-004A-4C10-8054-B7C04F463432' ConsoleWrite('False = ' & _IsValidUUID($sTestF) & @CRLF) ConsoleWrite('True = ' & _IsValidUUID($sTestT) & @CRLF) Func _IsValidUUID($sUUID) ;[\p{XDigit}]{8}-[\p{XDigit}]{4}-[34][\p{XDigit}]{3}-[89ab][\p{XDigit}]{3}-[\p{XDigit}]{12} ; Test UUID = '4C4C4544-004A-4C10-8054-B7C04F463432' Local $sRegExp = '([:xdigit:]){8}\-([:xdigit:]){4}\-([34])([:xdigit:]){3}\-([89ab])([:xdigit:]){3}\-([:xdigit:]){12}' ConsoleWrite(StringRegExp($sUUID, $sRegExp) & @CRLF) Local $Result = StringRegExp($sUUID, $sRegExp) ConsoleWrite($Result & @CRLF) If @error Then ConsoleWrite('Error: [' & @error & ']' & @CRLF) Return 'False' Else ConsoleWrite('Error2: [' & @error & ']' & @CRLF) Return 'True' EndIf EndFunc In the line under the Function call, you'll see the regex I found to do this from a google search. That was my starting point, and I'm trying to get it to work in Au3 and failing miserably. $sTestF is a known invalid String $sTestT is a known valid String Everything I've tried so far has produced the same results for both. Any help you could provide me is greatly appreciated. Thanks for your time!
  18. Suggestion/workaround - test 6 DCs, with the first being one you DON'T want to measure. Ie: DC75, DC1, DC2,DC3,DC4,DC5 That way the delay only affects a DC you don't care about. Another option is to run the script 5 times, with a different DC in the first position each time, thus they all get affected by the slow connection equally (which could be important if the latency is what you're trying to measure).
  19. Here's a thought, is there a way to get this script to connect to the remote machine with one account, then join with a different one? As in perhaps connect to and run with a local administrator account, but then join with a domain account.
  20. Ah nuts, then. Looks like all the necessary permissions are blocked on the domain level, and remain in force even when the pc isn't joined. That's annoying. Thanks for your help!
  21. And now the error# has changed. O.o From ErrorNotify(2): scriptline: 3771 Hexerror: 80070005 Number: 2147024891 WinDescription: Access is Denied I'm running the script on win8.1 at a virtual machine with win7
  22. Bugger. Far as I can tell WMI is working. Could be just something specific to our domain I guess - something locked down/blocked. Hm. I'll try again with _AD_ErrorNotify(2) and see what happens. Hopefully it'll give a more useful error code! Thanks for your assistance.
  23. Hi Water, when I run your joindomain example I get the following error: wmi object could not be created. -2147024174 Do you have any ideas why that might be occurring? I unjoined my otherwise working testmachine, so I know it has an AD account. Googling has not been helpful.
  24. 'Ly' would be Light Years, I suspect, not Miles.
  25. This is all so very good to know! I've fallen into a similar state as GEOsoft, whereby I'm adding tooltips to pretty much everything. It's good to see why this is bad, and to see better ways of doing similar functionality. Thanks everyone!
×
×
  • Create New...