
Deon
Active Members-
Posts
20 -
Joined
-
Last visited
Everything posted by Deon
-
Duplicate column in array and stringleft the value
Deon replied to Deon's topic in AutoIt General Help and Support
Thanks gents, works perfectly. -
I have an array that looks like: ______________________ |123456|ABCDEF|999999| ______________________ And I want to have Autoit create a new column at the start and grab the first 3 characters of the next column, so the array would now look like this: __________________________ 123|123456|ABCDEF|999999| __________________________ I've had a bit of a play with some of the _Array functions but can't really find anything to duplicate the column, so I'm not sure where to start. Any help appreciated!
-
Delete row from array where a column matches a value
Deon replied to Deon's topic in AutoIt General Help and Support
Thanks guys! Sorry, I had two trains of thought in my head at once. My initial idea was to duplicate the file, then remove the matching ones from one and the other to create two separate files with the correct value. Re-reading my title/post, this was not very clear... I apologise! This works perfectly! Only takes about 5 seconds to run through 10,000 lines of data and split them into the correct files.. thanks Malkey! -
I have a CSV file which contains eg 1000 rows. The file is split into two types, as aexample I've replaced the data with fruit items in the attachment. I want to split the array into two separate arrays (and then write them to files)... so one array will contain all the 'Apple' items, and one array will contain all the 'Orange' items. I tried using one of the few scripts I found which delete blank rows but then change the expression to match 'Apple' and 'Orange' but it didn't work, nothing was altered in the array. Appreciate any help you can offer
-
Hi, I have a script which fetches 7 excel files from our company's webserver and saves them as a file. I then create a new spreadsheet with 7 tabs and copy-paste each of the 7 files into it's own tab. I'm trying to automate this and not having much luck. I've tried using _Excel_RangeCopyPaste and failed abysmally, and then in desperation tried using Send() to send ctrl and tab keys but I really want a cleaner way. I would paste the code I have, but I overwrote the one using the Excel UDF, and you really don't want to see the one with a hundred Send()'s and Sleep()'s in it. I'd really appreciate any help anyone can offer! I've been using AutoIt for a while, so even if you can push me in the right direction, I can continue from there Cheers, Deon.
-
Perfect! Thank you
-
I have 100 text files which contain some information which is (just) human-readable. I want to extract two things from them, one is a string which fits a RegEx: [a-zA-Z]{2}\d{4}[a-zA-Z]{2}\d{3}(although technically it will say DescriptionAA1111AA111, and I just want to catch the AA1111AA111 part of it, but I can use a StringRight() function to clean that up) And the scond is a string showing the status of a device on our network, something like: 06:52:16 AWST01.24.00OnPlaying streamIdlePresent and mountedInternet: XX A1str.to: 0, buf.emp: 0, str.dsc: 0, vs.eof: 0which always starts with a time stamp (something like \d{2}:\d{2}:\d{2}?) Basically, I just want to define two variables: The last 11 characters of DescriptionAA1111AA111 (only appears once in the string)The entire line the first time a time like 06:52:16 is found I tried playing using FileReadLine() but because they aren't always on the same line from file to file. I also tried passing the entire file to StringRegExp(), but I can't seem to find a way to get StringRegExp() to trawl through the file looking for a match, rather than trying to match the entire contents against the expression. Any help appreciated!
-
Thanks for the reply, but unfortunately the script isn't returning anything now Even when I remove the variables and hard-code the data into the code like this, it still returns nothing: #include <_XMLDomWrapper.au3> #include <File.au3> Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load("C:\temp\test.xml") $oParameters = $oXML.SelectNodes("//Device[@name='Printer']//Event/Parameter") For $oParameter In $oParameters $oName = $oParameter.SelectSingleNode("./Name") If String($oName.text) = "HoursPoweredCount" Then $oValue = $oParameter.SelectSingleNode("./Value") ConsoleWrite(String($oValue.text) & @CRLF) Exit EndIf Next
-
Thanks for that, looks great.. it's returning the value now. One thing though, say I have the same parameter (HoursPoweredCount) for two different devices (in the example above Device name is 'printer'), how can I find HoursPoweredCount for another device called 'screen'?
-
I have read the other threads about how to use _XMLGetAttrib, and have got the below script, but it always returns -1 leading me to think it's not calling the correct parameter properly #include <_XMLDomWrapper.au3> #include <File.au3> $XMLfile = InputBox("XML File","What is the path to the XML file?") Global $oXML = ObjCreate("Microsoft.XMLHTTP") $oXML.Open("GET", "$XMLfile", 0) $oXML.Send Global $sFile = _TempFile(@TempDir, '~', '.xml') FileWrite($sFile, $oXML.responseText) If _XMLFileOpen($sFile) Then Local $sLvl = _XMLGetAttrib('./Devices/Printer/UPOSstat/Event/Parameter', 'HoursPoweredCount') ConsoleWrite($sLvl & @LF) EndIf FileDelete($sFile)A snippet of the XML file I'm trying to read: <Devices> <Device Name="Printer"> <UPOSStat xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.nrf-arts.org/IXRetail/namespace/"> <Event> <Parameter> <Name>HoursPoweredCount</Name> <Value>834</Value> </Parameter> <Parameter>...</Parameter> <Parameter>...</Parameter> <Parameter>...</Parameter> Basically, I want to pass the URL of the XML file to the script, and it returns the value of HoursPoweredCount, but I don't think I'm naming the path properly in _XMLGetAttrib. Cheers, Deon.
-
Thanks guys
-
Hi, I am looking for a way to identify text ajacent to a string in another string/window/etc. Eg: John - 53 Mary - 12 Bill - 32 Jill - 11 Say, I need to know how many Jill has done.. I want to be able to present 'Jill' to the script, and it returns '11'. Possible?
-
I'm using the below code from an >old forum post, but I logon to my computer as a standard user, and I'll need to connect to the other computer as an Administrator (with a different username). I can use RunAs for now, but I'd like a way to hard-code my credentials into the script (yes, I'm aware others can decompile it - no one else will be using the script), so I don't have to use RunAs everytime. Here's the code at the moment: #AutoIt3Wrapper_Change2CUI=Y #include <Date.au3> $strComputer = InputBox("Remote Uptime","What's the DNS?") If $cmdline[0] Then If StringInstr($cmdlineraw,"?") Then MsgBox(0,"Remote Uptime",@CRLF & "Description:" & @CRLF & @TAB & "Displays system up time for local or remote machines." & @CRLF) MsgBox(0,"Remote Uptime",@CRLF & "Parameter List:" & @CRLF & @TAB & "/?" & @TAB & @TAB & @TAB & "Displays this help/usage." & @CRLF) MsgBox(0,"Remote Uptime",@CRLF & "Examples:" & @CRLF & @TAB & @ScriptName & @CRLF) MsgBox(0,"Remote Uptime",@TAB & @ScriptName & " hostname1 hostname2 hostname3" & @CRLF) Exit EndIf For $x = 1 To $cmdline[0] MsgBox(0,"Remote Uptime",StringUpper($cmdline[$x]) & " " & _Uptime($cmdline[$x])&@CRLF) Next Else MsgBox(0,"Remote Uptime",_Uptime($strComputer) & @CRLF) EndIf Func _Uptime($strComputer) $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") If Not IsObj($objWMIService) Then Return "Failed to connect... sorry about that." $colOperatingSystems = $objWMIService.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem") For $objOS in $colOperatingSystems $dtmBootup = $objOS.LastBootUpTime $dtmLastBootupTime = _WMIDateStringToDate($dtmBootup) Next Return _FormatUptime($dtmLastBootupTime) EndFunc Func _WMIDateStringToDate($dtmBootup) Return StringLeft($dtmBootup,4) & "/" & StringMid($dtmBootup, 5, 2) & "/" & StringMid($dtmBootup, 7, 2) & " " & StringMid($dtmBootup, 9, 2) & ":" & StringMid($dtmBootup, 11, 2) & ":" & StringMid($dtmBootup, 13, 2) EndFunc Func _FormatUptime($dtmLastBootupTime) Dim $arrdatediffs[4][3]=[[0,24," day"],[0,60," hour"],[0,60," minute"],[0,1," second"]] $datediff = StringSplit("D|h|n|s","|") $tNow = _NowCalc() For $diff = 1 to $datediff[0] $arrdatediffs[$diff-1][0] = _DateDiff($datediff[$diff], $dtmLastBootUpTime, $tNow) Next $ubound = UBound($arrdatediffs)-1 For $x = $ubound To 0 Step -1 If $x > 0 Then If $arrdatediffs[$x-1][0] > 0 Then $arrdatediffs[$x][0] = ($arrdatediffs[$x][0]-($arrdatediffs[$x-1][0]*$arrdatediffs[$x-1][1])) EndIf Next $strUptime = "" For $x = 0 To $ubound If $arrdatediffs[$x][0] > 0 Then $strUptime &= $arrdatediffs[$x][0] & $arrdatediffs[$x][2] If $arrdatediffs[$x][0] > 1 Then $strUptime &= "s" If $x < $ubound Then $strUptime &= ", " EndIf Next Return $strUptime EndFunc
-
Trying to submit a form in IE, and I keep getting an error.. was working fine, and then all of a sudden stopped #include<IE.au3> $sUsername = "usernamegoeshere" $sPassword = "passwordgoeshere" $sUrl = "http://loginpageshere" $oIE = _IECreate($sUrl, 0, 1, 0, 0) Sleep(2000) $oHWND = _IEPropertyGet($oIE, "hwnd") WinSetState($oHWND, "", @SW_MAXIMIZE) $oForm = _IEFormGetCollection($oIE, 0) $oUsername = _IEFormElementGetObjByName($oForm, 'username') $oPassword = _IEFormElementGetObjByName($oForm, "password") _IEFormElementSetValue($oUsername, $sUsername) _IEFormElementSetValue($oPassword, $sPassword) _IEFormSubmit($oForm) Error is: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Deon\Documents\NameOfScript.au3" "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (904) : ==> Variable must be of type "Object".: Case $i_index > -1 And $i_index < $oTemp.forms.length Case $i_index > -1 And $i_index < $oTemp^ ERROR >Exit code: 1 Time: 2.730 Any assistance appreciated!
-
Every time I compile an icon using the Script to EXE conversion tool, it displays the wrong icon. I used a red toolbox icon long ago for a script, and now every single script I compile has this red toolbox as the icon. Even if I select 'Default' and delete the red icon file from every location on my computer - it still appears as the icon for every script I compile. Any ideas?
-
Variable keeps returning a weird value
Deon replied to Deon's topic in AutoIt General Help and Support
Console output: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Deon\Documents\runas.au3" Username: 4 Password: 6 >Exit code: 0 Time: 2.424 -
I'm working on a script which will run a program as another user, using RunAs The user is prompted for their alternate login details, and the variables $username and $password are passed to RunAs. Everything was working fine, until I noticed the program to be run stopped opening. An hour of debugging later, I've found the $username and $password variables are returning a static value for some reason. No matter what the user enters, $username returns '4' No matter what the user enters, $password returns '6' I've included a small piece of the code below, and this snippet seems to be replicating the problem. I've outputted both variables to the console in this snippet. Any assistance is greatly appreciated!! #include <GUIConstants.au3> ; Prompt the user for their login details $MAIN = GUICreate("USERNAME & PASSWORD", 220, 120) GUICtrlCreateLabel("USERNAME:", 10, 15, 65, 25) $USERNAME = GUICtrlCreateInput("", 80, 10, 120, 25) GUICtrlCreateLabel("PASSWORD:", 10, 55, 65, 25) $PASSWORD = GUICtrlCreateInput("", 80, 50, 120, 25) $OK = GUICtrlCreateButton("OK", 40, 85, 60, 25) $CANCEL = GUICtrlCreateButton("CANCEL", 120, 85, 60, 25) GUISetState() While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Or $MSG = $CANCEL Exit Case $MSG = $OK GUIDelete($MAIN) ConsoleWrite("Username: " & $username & @CRLF & "Password: " & $password & @CRLF) Exit EndSelect Sleep(10) WEnd
-
Apologies for making this a bit of a complicated one... I'm looking for a remote uptime script. I've found a few, and something like one of the below would probably do... however I need to be able to run the script as another user. For security, we don't use our domain admin accounts on a day-to-day basis, only when we need to run scripts that require domain admin permissions. Eg, I'm logged in all day as $regularuser and use $domainadmin when I log into a server... $regularuser doesn't have admin rights on the servers, so this code must be executed as $domainadmin. The script will be placed in a network share, so I can't use RunAs in Windows, because when the session is created for the RunAs user ($domainadmin), the network share will not be mapped and the script won't be found. Any ideas? #AutoIt3Wrapper_Change2CUI=Y #include <Date.au3> $strComputer = "." If $cmdline[0] Then If StringInstr($cmdlineraw,"?") Then ConsoleWrite(@CRLF & "Description:" & @CRLF & @TAB & "Displays system up time for local or remote machines." & @CRLF) ConsoleWrite(@CRLF & "Parameter List:" & @CRLF & @TAB & "/?" & @TAB & @TAB & @TAB & "Displays this help/usage." & @CRLF) ConsoleWrite(@CRLF & "Examples:" & @CRLF & @TAB & @ScriptName & @CRLF) ConsoleWrite(@TAB & @ScriptName & " hostname1 hostname2 hostname3" & @CRLF) Exit EndIf For $x = 1 To $cmdline[0] ConsoleWrite(StringUpper($cmdline[$x]) & " " & _Uptime($cmdline[$x])&@CRLF) Next Else ConsoleWrite(_Uptime($strComputer) & @CRLF) EndIf Func _Uptime($strComputer) $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") If Not IsObj($objWMIService) Then Return "Failed to Connect" $colOperatingSystems = $objWMIService.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem") For $objOS in $colOperatingSystems $dtmBootup = $objOS.LastBootUpTime $dtmLastBootupTime = _WMIDateStringToDate($dtmBootup) Next Return _FormatUptime($dtmLastBootupTime) EndFunc Func _WMIDateStringToDate($dtmBootup) Return StringLeft($dtmBootup,4) & "/" & StringMid($dtmBootup, 5, 2) & "/" & StringMid($dtmBootup, 7, 2) & " " & StringMid($dtmBootup, 9, 2) & ":" & StringMid($dtmBootup, 11, 2) & ":" & StringMid($dtmBootup, 13, 2) EndFunc Func _FormatUptime($dtmLastBootupTime) Dim $arrdatediffs[4][3]=[[0,24," day"],[0,60," hour"],[0,60," minute"],[0,1," second"]] $datediff = StringSplit("D|h|n|s","|") $tNow = _NowCalc() For $diff = 1 to $datediff[0] $arrdatediffs[$diff-1][0] = _DateDiff($datediff[$diff], $dtmLastBootUpTime, $tNow) Next $ubound = UBound($arrdatediffs)-1 For $x = $ubound To 0 Step -1 If $x > 0 Then If $arrdatediffs[$x-1][0] > 0 Then $arrdatediffs[$x][0] = ($arrdatediffs[$x][0]-($arrdatediffs[$x-1][0]*$arrdatediffs[$x-1][1])) EndIf Next $strUptime = "" For $x = 0 To $ubound If $arrdatediffs[$x][0] > 0 Then $strUptime &= $arrdatediffs[$x][0] & $arrdatediffs[$x][2] If $arrdatediffs[$x][0] > 1 Then $strUptime &= "s" If $x < $ubound Then $strUptime &= ", " EndIf Next Return $strUptime EndFunc or $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" Local $strComputer = InputBox("Which computer?","Enter Computer name") $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_System", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $uptime = $objItem.SystemUpTime If $uptime > 60 Then $uptime = $uptime / 60; convert the seconds to minutes If $uptime > 60 Then $uptime = $uptime / 60; convert the minutes to hours If $uptime > 24 Then; convert hours to days $uptime = Number(StringFormat("%.2f",$uptime / 24)) If $uptime > 1.0 Then; uptime more than 1 day $Output = $Output & "SystemUpTime: " & $uptime & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop EndIf EndIf EndIf EndIf $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PerfFormattedData_PerfOS_System" ) Endif
-
OutlookEX UDF - Help & Support (III)
Deon replied to water's topic in AutoIt General Help and Support
What's the easiest way to show the count of my unread subfolders? I'm using the below at the moment, but want to use OutlookEX if possible to make the script better. At the moment the above script returns '0' even if there is 1 unread email in the subfolder 'Test' of folder 'Inbox'. How do I catch all unread emails in the count? $objOutlook = ObjCreate("Outlook.Application") $objNameSpace = $objOutlook.GetNamespace("MAPI") $objNamespace.Logon("Default Outlook Profile", "", FALSE, TRUE) $objFolder = $objNamespace.GetDefaultFolder(6) Msgbox(0,"Unread Email Count",$objFolder.UnreadItemCount)- 817 replies