Leaderboard
Popular Content
Showing content with the highest reputation on 10/06/2013 in all areas
-
Continuing development:2 points
-
Detect USB devices connected.
Alexxander reacted to mrflibblehat for a topic
Something like this. $vFile = FileOpen("usb.txt", 2) Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_USBHub') If IsObj($vObjItems) Then For $vObjItem In $vObjItems FileWriteLine($vFile, $vObjItem.Description & @CRLF) FileWriteLine($vFile, $vObjItem.DeviceID & @CRLF & @CRLF) Next EndIf FileClose($vFile) ShellExecute("usb.txt") or if your specifically looking for USB Drives. maybe the below. $vFile = FileOpen("usb.txt", 2) Local $vObjWMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2") $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_DiskDrive') If IsObj($vObjItems) Then For $vObjItem In $vObjItems If StringInStr($vObjItem.Caption, "USB") Then FileWriteLine($vFile, $vObjItem.Caption & @CRLF) FileWriteLine($vFile, $vObjItem.DeviceID & @CRLF & @CRLF) EndIf Next EndIf FileClose($vFile) ShellExecute("usb.txt")1 point -
Since XP Windows users have ability to view, compress, extract zipped files natively. Microsoft's developers decided to create shell extension that does this job. Shell extension is library that shell (explorer.exe) uses to communicate with in order to achieve results. In case of ZIP files this particular library is zipfldr.dll. How does it work? By default when you double-click ZIP file, explorer opens it allowing you to browse around it pretty much the same way as you would through the ordinary folder. To have that ability Microsoft developed COM based technology (methodology) known as Shell Extensibility. Every shell extension has to follow strict and documented set of rules which shell then uses to populate graphical interface user uses. I won't be going into details about registering shell extension, only about how they are meant to be implemented. The main interface every shell extension should implement is IShellFolder. That's the basic interface that would give all the information about the extension and it would be used to create instances of every other wanted or needed interface. Obvious question could be how to create object of IShellFolder interface for the extension. In case shell extension is implemented in form of DLL library then that particular dll must export function called DllGetClassObject. This function is used to create object of IClassFactory interface which is then used to get mentioned IShellFolder. In AutoIt it's very simple to do this first step. Ordinary DllCall in combination with ObjCreateInterface and voila, first helper function is done. I will call it __UnZIP_DllGetClassObject: Func __UnZIP_DllGetClassObject($sDll, $sCLSID, $sIID, $tagInterface = "") Local $tCLSID = __UnZIP_GUIDFromString($sCLSID) Local $tIID = __UnZIP_GUIDFromString($sIID) Local $aCall = DllCall($sDll, "long", "DllGetClassObject", "struct*", $tCLSID, "struct*", $tIID, "ptr*", 0) If @error Or $aCall[0] Then Return SetError(1, 0, 0) Local $oObj = ObjCreateInterface($aCall[3], $sIID, $tagInterface) If @error Then Return SetError(2, 0, 0) Return $oObj EndFunc Func __UnZIP_GUIDFromString($sGUID) Local $tGUID = DllStructCreate("byte[16]") DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(1, 0, 0) Return $tGUID EndFunc To call the function I have to DllOpen zipfldr.dll, define CLSID_CZipFolder and of course, IClassFactory: Global Const $hZIPFLDR_DLL = DllOpen("zipfldr.dll") Global Const $CLSID_CZipFolder = "{e88dcce0-b7b3-11d1-a9f0-00aa0060fa31}" ;=============================================================================== #interface "IClassFactory" Global Const $sIID_IClassFactory = "{00000001-0000-0000-C000-000000000046}" Global Const $tagIClassFactory = "CreateInstance hresult(ptr;clsid;ptr*);" & _ "LockServer hresult(bool);" ;=============================================================================== Local $oClassFactory = __UnZIP_DllGetClassObject($hZIPFLDR_DLL, $CLSID_CZipFolder, $sIID_IClassFactory, $tagIClassFactory) Now that I have object of IClassFactory interface, I can simply ask for IShellFolder object pointer: Local $pShellFolder $oClassFactory.CreateInstance(0, $sIID_IShellFolder, $pShellFolder) ... And after defining IShellFolder interface create the ShellFolder object: ;=============================================================================== #interface "IShellFolder" Global Const $sIID_IShellFolder = "{000214E6-0000-0000-C000-000000000046}" Global $tagIShellFolder = "ParseDisplayName hresult(hwnd;ptr;wstr;ulong*;ptr*;ulong*);" & _ "EnumObjects hresult(hwnd;dword;ptr*);" & _ "BindToObject hresult(struct*;ptr;clsid;ptr*);" & _ "BindToStorage hresult(struct*;ptr;clsid;ptr*);" & _ "CompareIDs hresult(lparam;struct*;struct*);" & _ "CreateViewObject hresult(hwnd;clsid;ptr*);" & _ "GetAttributesOf hresult(uint:struct*;ulong*);" & _ "GetUIObjectOf hresult(hwnd;uint;struct*;clsid;uint*;ptr*);" & _ "GetDisplayNameOf hresult(struct*;dword;struct*);" & _ "SetNameOf hresult(hwnd;struct*;wstr;dword;struct*);" ;=============================================================================== $oShellFolder = ObjCreateInterface($pShellFolder, $sIID_IShellFolder, $tagIShellFolder) The next step is to load the ZIP file. IShellFolder doesn't have method for this but it can be asked for either IPersistFile or IPersistFolder interface objects.Which interface can be used to load the ZIP depends on system. In my tests I have found that IPersistFile works on Windows 7 and IPersistFolder on Windows 8 and XP. I will go with IPersistFile first and use IPersistFolder as an alternative in case of failure. It's really irrerelevant as long as ZIP gets loaded. These both interfaces inherit from IPersist so to define them correctly I need to define that one first: ;=============================================================================== #interface "IPersist" Global Const $sIID_IPersist = "{0000010c-0000-0000-C000-000000000046}" Global $tagIPersist = "GetClassID hresult(ptr*);" ;=============================================================================== ;=============================================================================== #interface "IPersistFile" Global Const $sIID_IPersistFile = "{0000010b-0000-0000-C000-000000000046}" Global $tagIPersistFile = $tagIPersist & _ "IsDirty hresult();" & _ "Load hresult(wstr;dword);" & _ "Save hresult(wstr;bool);" & _ "SaveCompleted hresult(wstr);" & _ "GetCurFile hresult(ptr*);" ;=============================================================================== ;=============================================================================== #interface "IPersistFolder" Global Const $sIID_IPersistFolder = "{000214EA-0000-0000-C000-000000000046}" Global $tagIPersistFolder = $tagIPersist & _ "Initialize hresult(ptr);" ;=============================================================================== ;... code below goes to some function $oPersistF = ObjCreateInterface($pShellFolder, $sIID_IPersistFile, $tagIPersistFile) If @error Then ; Try IPersistFolder $oPersistF = ObjCreateInterface($pShellFolder, $sIID_IPersistFolder, $tagIPersistFolder) If @error Then Return SetError(3, 0, 0) Else If $oPersistF.Initialize(__UnZIP_SHParseDisplayName($sZIP)) < $S_OK Then Return SetError(4, 0, 0) EndIf Else Local Const $STGM_READ = 0x00000000 If $oPersistF.Load($sZIP, $STGM_READ) < $S_OK Then Return SetError(4, 0, 0) EndIf ;... Func __UnZIP_SHParseDisplayName($sPath) Local $aCall = DllCall("shell32.dll", "long", "SHParseDisplayName", "wstr", $sPath, "ptr", 0, "ptr*", 0, "ulong", 0, "ulong*", 0) If @error Or $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[3] EndFunc Now that ZIP is loaded zipfldr will do its job of unzipping a file. If you look back to IShellFolder definition you'll see that the object of that interface exposes function/method called ParseDisplayName. When invoked the interface will internally locate wanted file and give back pointer to PIDL (a form of item identifier uniquely identifying it). This data is then passed to BindToStorage.BindToStorage is function that accepts IID of the interface you want to bind item to. In my case I will go for IStream so that I can easily get decompressed binary data out of it. Before I show how to do that a word about ParseDisplayName. It appears that "paths" inside the ZIP use either forward slash or backslash depending on system. For example if you ZIP have folder "ABC" with file "x.txt" in it, on XP it would be "ABC/x.txt" and on newer systems it'd be "ABCx.txt". So in case of failure with one I'll go with another. Local Const $SFGAO_STREAM = 0x00400000 ;... Local $pPidl = 0 Local $iAttributes = $SFGAO_STREAM ; Find the file inside the ZIP If $oShellFolder.ParseDisplayName(0, 0, $sFile, 0, $pPidl, $iAttributes) < $S_OK Then $sFile = StringReplace($sFile, "\", "/") ; XP uses forward slash apparently If $oShellFolder.ParseDisplayName(0, 0, $sFile, 0, $pPidl, $iAttributes) < $S_OK Then Return SetError(5, 0, 0) EndIf ...Back to IStream (inherits from ISequentialStream): ;=============================================================================== #interface "ISequentialStream" Global Const $sIID_ISequentialStream = "{0c733a30-2a1c-11ce-ade5-00aa0044773d}" Global Const $tagISequentialStream = "Read hresult(struct*;dword;dword*);" & _ "Write hresult(struct*;dword;dword*);" ;=============================================================================== ;=============================================================================== #interface "IStream" Global Const $sIID_IStream = "{0000000c-0000-0000-C000-000000000046}" Global Const $tagIStream = $tagISequentialStream & _ "Seek hresult(int64;dword;uint64*);" & _ "SetSize hresult(uint64);" & _ "CopyTo hresult(ptr;uint64;uint64*;uint64*);" & _ "Commit hresult(dword);" & _ "Revert hresult();" & _ "LockRegion hresult(uint64;uint64;dword);" & _ "UnlockRegion hresult(uint64;uint64;dword);" & _ "Stat hresult(struct*;dword);" & _ "Clone hresult(ptr*);" ;=============================================================================== ;... Local $pStream If $oShellFolder.BindToStorage($pPidl, 0, $sIID_IStream, $pStream) <> $S_OK Then Return SetError(6, __UnZIP_CoTaskMemFree($pPidl), 0) Local $oStream = ObjCreateInterface($pStream, $sIID_IStream, $tagIStream) And that would be it as far as unzipping goes. Getting binary data out of stream is off-topic here. The udf uses function UnZIP_SaveFileToBinary for that. If you are interested then take a look at that inside the attached file. To use functions from the UDF to for example, extract file named "test.txt" inside folder named "Test" inside the folder named "Abc" inside the ZIP file "Testing.zip", you would call it like this: $sZIP = "Testing.zip" ; full path to your zip $sFile = "Abc\Test\test.txt" ; file inside the zip $bBinary = UnZIP_SaveFileToBinaryOnce($sZIP, $sFile) ; to extract to variable ; Maybe to print to console? ConsoleWrite(BinaryToString($bBinary) & @CRLF) Or if you'd want to extract it to some location on your disk: $sZIP = "Testing.zip" ; full path to your zip $sFile = "Abc\Test\test.txt" ; file inside the zip $sDestination = @DesktopDir & "\test.txt" UnZIP_SaveFileToFileOnce($sZIP, $sFile, $sDestination) For repetitive tasks on the same ZIP file you wouldn't want to use ...Once() functions, but rather than that functions without that suffix to avoid internal parsing of the whole ZIP for every file inside: $sZIP = "Testing.zip" ; full path to your zip $sFile0 = "Abc\Test\test0.txt" ; file 0 inside the zip $sFile1 = "Abc\Test\test1.txt" ; file 1 inside the zip $sFile5 = "Abc\Test\Whatever\test5.txt" ; file 5 inside the zip Local $oShellFolder, $oPersistF $bBinary = UnZIP_SaveFileToBinary($sZIP, $sFile0, $oShellFolder, $oPersistF) ; to extract to variable ; Print content of file 0 to console ConsoleWrite(BinaryToString($bBinary) & @CRLF) $bBinary = UnZIP_SaveFileToBinary($sZIP, $sFile1, $oShellFolder, $oPersistF) ; to extract to variable ; Print content of file 1 to console ConsoleWrite(BinaryToString($bBinary) & @CRLF) $bBinary = UnZIP_SaveFileToBinary($sZIP, $sFile5, $oShellFolder, $oPersistF) ; to extract to variable ; Print content of file 5 to console ConsoleWrite(BinaryToString($bBinary) & @CRLF) ; Free objects $oShellFolder= 0 $oPersistF = 0 ...You get the idea. Technique used here is pretty much unique. I have't seen any code that uses this to-the-point method written in any language. To use it backward check this article. Oh and I took CLSID_CZipFolder name from here because they deserve it. UDF: UnZIP.au3 You can find example of usage >here.1 point
-
Getting Text HTML
Trojan55 reacted to mrflibblehat for a topic
$chg will return an array. I also notice that $fix does not have any such source code in. Maybe this is served up client side in the browser by javascript. not so sure how that works. Best I can suggest is $src = BinaryToString(InetRead("https://www.google.dz/")) $chg = StringRegExp($src,'"srch"\:"(.*?)"', 3) MsgBox(0,"",$chg[0])1 point -
World Clock(s) - (by cities)
jaberwacky reacted to Rogue5099 for a topic
The main goal for me is to show the time in different locations to be able to know when to call my kids while out of their time zone. The screenshots above are 2 separate images showing either 2 or 4 clocks. This is something I wrote awhile ago and had to reuse. It's very simple in design so if anyone wants to spruce it up a bit be my guest and please share as well. Time Zone Clocks.au3 Time Zone Clocks.au3 -Added a check to make sure InputBox's are numbers -Decreased size of GUI to get rid of last line label -Changed GUICtrlSetData to ControlSetText (increased speed of Data Function) -Changed only to update Label's if different to avoid flickering -Changed AdlibRegister from 900ms to 60ms*Number of Clocks (Maybe a little more CPU usage) Time Zone Clocks.au3 -Added city code list to program -Replace InputBox's with GUI to enter city codes -Can search cities by typing in city name -Now you can input all city codes in 1 input with a comma separating them i.e. 100,200,300 -Now just double click the city in the list to add to input -Disabled editing of Input Box on starting GUI -Added Error check for no cities selected -Added AdlibUnRegister to prevent errors while closing1 point -
how to easily get the subnet mask?
mrflibblehat reacted to Gianni for a topic
I found on the forum this?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>> remarkable?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>> ?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>>UDF by Ascend4nt using that UDF, is possible to easily get the subnet mask of any IP set on the local computer. for example with a simple script like this: #include "_NetworkStatistics.au3" ; get this from the following link: ; http://www.autoitscript.com/forum/topic/151920-network-interface-info-statistics-and-traffic/?p=1088781 MsgBox(0, "", "IP: " & @IPAddress1 & @TAB & " Subnet Mask: " & _GetMask(@IPAddress1), 5) Func _GetMask($ip) ; get infos on network (see _NetworkStatistics.au3 UDF for info) Local $_net = _Network_IPv4AddressTable() If Not @error Then For $i = 0 To UBound($_net) - 1 ; scans all returned IP If $_net[$i][1] = $ip Then ; if found my IP Return $_net[$i][2] ; Return the mask EndIf Next EndIf Return "error" EndFunc ;==>_GetMask hope it can be useful to other users (the _NetworkStatistics.au3 UDF is in the file "NetworkStatistics.zip" on> this Ascend4nt's post bye1 point -
You should know one thing about that script, it's recursing between 2 functions constantly, if you run it long enough the script will crash with a recursion level reached error. By recursing I mean that one function is calling another function which in turn calls the function that calls it. Delay5Sec() is called by CheckRouter(), after the 5 second delay Delay5Sec() calls CheckRouter() and so on and so on.1 point