Snippets ( Windows Information )

From AutoIt Wiki
Jump to navigation Jump to search

Please always credit an author in your script if you use their code. It is only polite.


_ComputerGetStartup

Author: guinness








#include <Array.au3> Local $aArray = _ComputerGetStartup() _ArrayDisplay($aArray) Func _ComputerGetStartup() Local $aReturn[2][6] = [[0, 6]], $oColItems, $oObjectItem, $oWMIService $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $oColItems = $oWMIService.ExecQuery("Select * From Win32_StartupCommand", "WQL", 0x30) If IsObj($oColItems) Then For $oObjectItem In $oColItems If ($aReturn[0][0] + 1) >= $aReturn[0][2] Then $aReturn[0][2] = ($aReturn[0][0] + 1) * 2 ReDim $aReturn[$aReturn[0][2]][$aReturn[0][1]] EndIf $aReturn[0][0] += 1 $aReturn[$aReturn[0][0]][0] = $oObjectItem.Name $aReturn[$aReturn[0][0]][1] = $oObjectItem.User $aReturn[$aReturn[0][0]][2] = $oObjectItem.Location $aReturn[$aReturn[0][0]][3] = $oObjectItem.Command $aReturn[$aReturn[0][0]][4] = $oObjectItem.Description $aReturn[$aReturn[0][0]][5] = $oObjectItem.SettingID Next ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] Return $aReturn EndIf Return SetError(1, 0, $aReturn) EndFunc ;==>_ComputerGetStartup 

ReturnToContents

DriveInfo

Unknown




Modified: Chimaera





Example() Func Example() Local $aDriveArray = DriveGetDrive("ALL") If @error = 0 Then Local $sDriveInfo = "" For $i = 1 To $aDriveArray[0] $sDriveInfo &= StringUpper($aDriveArray[$i]) & "\" & @CRLF $sDriveInfo &= @TAB & "File System = " & DriveGetFileSystem($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Label = " & DriveGetLabel($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Serial = " & DriveGetSerial($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Type = " & DriveGetType($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Free Space = " & DriveSpaceFree($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Total Space = " & DriveSpaceTotal($aDriveArray[$i]) & @CRLF $sDriveInfo &= @TAB & "Status = " & DriveStatus($aDriveArray[$i]) & @CRLF $sDriveInfo &= @CRLF Next MsgBox(4096, "", $sDriveInfo) EndIf EndFunc ;==>Example 

ReturnToContents

Find If An Application Is Hung

Author: neogia








; Find If An Application Is Hung If _NotResponding("TITLE HERE", "TEXT HERE[OPTIONAL]", 1) Then ; The last parameter indicates whether you want to close the hung app or not. MsgBox(0,"", "Hung Application, closing app now.") Else MsgBox(0,"", "Application running as intended.") EndIf Func _NotResponding($title, $text, $closeIfHung = 0) $hWnd = WinGetHandle($title, $text) If $hWnd == "" Then MsgBox(0,"Error","Could not find window") Exit EndIf $retArr = DllCall("user32.dll", "int", "IsHungAppWindow", "hwnd", $hWnd) If @error == 0 Then If $retArr[0] == 1 Then If $closeIfHung Then ProcessClose(WinGetProcess($title, $text)) EndIf Return 1 EndIf Else Return 0 EndIf EndFunc 

ReturnToContents

_GetDefBrowser

Author: JScript







Check to see which browser is the default.


; Check to see which browser is the default. MsgBox(4096, "Default browser", "My default browser is: " & _GetDefBrowser()) Func _GetDefBrowser() Local $sRegRead = RegRead("HKCR\http\shell\open\command", "") Return StringRegExpReplace($sRegRead, "(.*?\x22)(.*?[\\/])*(.*?)(\x22.*?\z)", "$3") ; << Credits to SmOke_N EndFunc ;==>_GetDefBrowser 

ReturnToContents

_GetDefaultBrowser

Author: guinness







Get the default browser of the system.


; Get the default browser of the system. #include <APIConstants.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. #include <WinAPIEx.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ConsoleWrite(_GetDefaultBrowser() & @CRLF) Func _GetDefaultBrowser() Return _WinAPI_AssocQueryString(".html", $ASSOCSTR_EXECUTABLE) EndFunc ;==>_GetDefaultBrowser 

ReturnToContents

_GetDefaultPrinter

Author: guinness








; Check to see which printer is the default. ConsoleWrite(_GetDefaultPrinter() & @CRLF) ; Get the default printer. Func _GetDefaultPrinter() Local $sResult = 'None', $oWMIService = ObjGet('winmgmts:\\' & '.' & '\root\cimv2') Local $oColItems = $oWMIService.ExecQuery('Select * From Win32_Printer Where Default = True') If IsObj($oColItems) Then For $oObjectItem In $oColItems $sResult = $oObjectItem.DeviceID Next EndIf Return $sResult EndFunc ;==>_GetDefaultPrinter 

ReturnToContents

_GetDesktopArea

Author: guinness








#include <Array.au3> #include <WinAPI.au3> Local $aArray = _GetDesktopArea() _ArrayDisplay($aArray) ; Get the working visible area of the desktop, this doesn't include the area covered by the taskbar. Func _GetDesktopArea() Local Const $SPI_GETWORKAREA = 48 Local $tWorkArea = DllStructCreate($tagRECT) _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea)) Local $aReturn[4] = [DllStructGetData($tWorkArea, "Left"), DllStructGetData($tWorkArea, "Top"), _ DllStructGetData($tWorkArea, "Right") - DllStructGetData($tWorkArea, "Left"), DllStructGetData($tWorkArea, "Bottom") - DllStructGetData($tWorkArea, "Top")] Return $aReturn EndFunc ;==>_GetDesktopArea 

ReturnToContents

_GetDriveBySerial

Author: guinness








ConsoleWrite( _GetDriveBySerial("S3Ri41") & @LF) Func _GetDriveBySerial($sSerial) Local $aDriveList[25] = [24, "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:", _ "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:"] For $A = 1 To $aDriveList[0] If (DriveGetSerial($aDriveList[$A]) = $sSerial And DriveStatus($aDriveList[$A]) = "READY") Then Return $aDriveList[$A] EndIf Next Return SetError(1, 0, "(Unknown)") EndFunc ;==>_GetDriveBySerial 

ReturnToContents

_GetDriveMediaType

Author: guinness








MsgBox(4096, '', 'The media type of the E:\ drive is: ' & _GetDriveMediaType('E:')) Func _GetDriveMediaType($sDrive) Local $oWMIService = ObjGet('winmgmts:\\' & '.' & '\root\cimv2') Local $oColItems = $oWMIService.ExecQuery('Select * From Win32_CDROMDrive Where Drive = "' & StringLeft($sDrive, 2) & '"', 'WQL', 0x30), $sReturn = '' If IsObj($oColItems) Then For $oObjectItem In $oColItems $sReturn &= $oObjectItem.MediaType Next Return $sReturn EndIf Return SetError(1, 0, '') EndFunc ;==>_GetDriveMediaType 

ReturnToContents

_GetFileDrive

Author: guinness








ConsoleWrite(_GetFileDrive(@ScriptFullPath) & @CRLF) ; Get the drive letter of a filepath. Idea from _PathSplit. Func _GetFileDrive($sFilePath) Return StringLeft($sFilePath, StringInStr($sFilePath, ":", 2, 1) + 1) EndFunc ;==>_GetFileDrive 

ReturnToContents

_GetFileExtension

Author: guinness








ConsoleWrite(_GetFileExtension(@ScriptFullPath) & @CRLF) ; Get the file extension including the dot of a filepath. Idea from _PathSplit. Func _GetFileExtension($sFilePath) Return StringTrimLeft($sFilePath, StringInStr($sFilePath, ".", 2, -1) - 1) EndFunc ;==>_GetFileExtension 

ReturnToContents

_GetFileName

Author: guinness








ConsoleWrite(_GetFileName(@ScriptFullPath) & @CRLF) ; Get the filename including the extension of a filepath. Idea from _PathSplit. Func _GetFileName($sFilePath) Return StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", 2, -1)) EndFunc ;==>_GetFileName 

ReturnToContents

_GetFilePath

Author: guinness








ConsoleWrite(_GetFilePath(@ScriptFullPath) & @CRLF) ; Get the directory part of a filepath. Idea from _PathSplit. Func _GetFilePath($sFilePath) Return StringLeft($sFilePath, StringInStr($sFilePath, "\", 2, -1) - 1) EndFunc ;==>_GetFilePath 

ReturnToContents

_GetFullPath

Author: guinness








; Creates a path based on the relative path you provide. Similar to _PathFull. #include <WinAPIEx.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ConsoleWrite(_GetFullPath(".\" & @ScriptName) & @CRLF) Func _GetFullPath($sRelativePath, $sBasePath = @WorkingDir) Local $sWorkingDir = @WorkingDir FileChangeDir($sBasePath) $sRelativePath = _WinAPI_GetFullPathName($sRelativePath) FileChangeDir($sWorkingDir) Return $sRelativePath EndFunc ;==>_GetFullPath 

ReturnToContents

_GetInstalledPath

Author: storme








#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;#AutoIt3Wrapper_Run_Debug_Mode=y Func example() Local $installedPath $installedPath = _GetInstalledPath("Adobe Reader") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console $installedPath = _GetInstalledPath("KB2482017") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console $installedPath = _GetInstalledPath("EASEUS Todo Backup Free") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console $installedPath = _GetInstalledPath("InCD!UninstallKey") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $installedPath = ' & $installedPath & ' >Error code: ' & @error & @crlf) ;### Debug Console EndFunc ;==>example ; #FUNCTION# ==================================================================================================================== ; Name...........: _GetInstalledPath ; Description ...: Returns the installed path for specified program ; Syntax.........: GetInstalledPath($sProgamName) ; Parameters ....: $sProgamName - Name of program to seaach for ; - Must be exactly as it appears in the registry unless extended search is used ; $fExtendedSearchFlag - True - Search for $sProgamName in "DisplayName" Key ; $fSlidingSearch - True - Find $sProgamName anywhere in "DisplayName" Key ; False - Must be exact match ; Return values .: Success - returns the install path ; Failure - 0 ; [email="|@Error"]|@Error[/email] - 1 = Unable to find entry in registry ; [email="|@Error"]|@Error[/email] - 2 = No "InstalledLocation" key ; Author ........: John Morrison aka Storm-E ; Remarks .......: V1.5 Added scan for $sProgamName in "DisplayName" Thanks to JFX for the idea ; Related .......: ; Link ..........: ; Example .......: ; AutoIT link ...; [url="http://www.autoitscript.com/forum/topic/139761-getinstalledpath-from-uninstall-key-in-registry/"]http://www.autoitscript.com/forum/topic/139761-getinstalledpath-from-uninstall-key-in-registry/[/url] ; =============================================================================================================================== Func _GetInstalledPath($sProgamName, $fExtendedSearchFlag = True, $fSlidingSearch = True) Local $sBasePath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" Local $sCurrentKey ; Holds current key during search Local $iCurrentKeyIndex ; Index to current key Local $sInstalledPath = RegRead($sBasePath & $sProgamName, "InstallLocation") If @error Then If @error = -1 Then ;Unable To open InstallLocation so unable to find path Return SetError(2, 0, "") ; Path Not found EndIf ;Key not found If $fExtendedSearchFlag Then $iCurrentKeyIndex = 1 While 1 $sCurrentKey = RegEnumKey($sBasePath, $iCurrentKeyIndex) If @error Then ;No keys left Return SetError(1, 0, "") ; Path Not found EndIf If ($fSlidingSearch And StringInStr(RegRead($sBasePath & $sCurrentKey, "DisplayName"), $sProgamName)) Or (RegRead($sBasePath & $sCurrentKey, "DisplayName") = $sProgamName) Then ;Program name found in DisplayName $sInstalledPath = RegRead($sBasePath & $sCurrentKey, "InstallLocation") If @error Then ;Unable To open InstallLocation so unable to find path Return SetError(2, 0, "") ; Path Not found EndIf ExitLoop EndIf $iCurrentKeyIndex += 1 WEnd Else Return SetError(1, 0, "") ; Path Not found EndIf EndIf Return $sInstalledPath EndFunc ;==>_GetInstalledPath 

ReturnToContents

_GetRelativePath

Author: guinness








; Returns the relative path to a directory or file. Similar to _PathGetRelative. #include <WinAPIEx.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ConsoleWrite(_GetRelativePath(@ScriptDir, @ProgramFilesDir) & @CRLF) ; Pass the script's directory. ConsoleWrite(_GetRelativePath(@ScriptFullPath, @ProgramFilesDir) & @CRLF) ; Pass the entire file path including the filename. Func _GetRelativePath($sFrom, $sTo) Local $iIsFolder = Number(_WinAPI_PathIsDirectory($sTo) > 0), $sRelativePath = '' If $iIsFolder Then $sTo = _WinAPI_PathAddBackslash($sTo) EndIf If _WinAPI_PathIsDirectory($sFrom) = 0 Then $sFrom = _WinAPI_PathRemoveFileSpec($sFrom) EndIf $sRelativePath = _WinAPI_PathRelativePathTo(_WinAPI_PathAddBackslash($sFrom), 1, $sTo, $iIsFolder) ; Retrieve the relative path. If @error Then Return SetError(1, 0, $sTo) EndIf If $sRelativePath = "." Then $sRelativePath &= "\" ; This is used when the source and destination are the same directory. EndIf Return $sRelativePath EndFunc ;==>_GetRelativePath 

ReturnToContents

_IsActive

Author: guinness








Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Check if the Notepad window is active and display the appropriate message box. If _IsActive($hWnd) Then MsgBox(4096, "", "Notepad is active.") Else MsgBox(4096, "", "Notepad isn't active.") EndIf ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example ; Check if the window is active. Func _IsActive($hWnd) Return BitAND(WinGetState($hWnd), 8) = 8 EndFunc ;==>_IsActive 

ReturnToContents

_IsEnvExists

Author: guinness








ConsoleWrite(_IsEnvExists("SciTE_HOME") & @CRLF) ConsoleWrite(_IsEnvExists("PATH") & @CRLF) ; Checks if an environment variable exists. Func _IsEnvExists($sVariable) Return EnvGet($sVariable) <> "" EndFunc ;==>_IsEnvExists 

ReturnToContents

_IsClassicTheme

Author: guinness








#include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ConsoleWrite(_IsClassicTheme() & @LF) Func _IsClassicTheme() ; By guinness 2011. Returns True or False. _WinAPI_GetCurrentThemeName() Return @error > 0 EndFunc ;==>_IsClassicTheme 

ReturnToContents

_IsExtensionSupported

Author: guinness








#include <APIConstants.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. #include <WinAPIEx.au3> ; Download from http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. ConsoleWrite(_IsExtensionSupported('.html') & @CRLF) ; With the dot. ConsoleWrite(_IsExtensionSupported('html') & @CRLF) ; Without the dot. ConsoleWrite(_IsExtensionSupported('.AuProj') & @CRLF) ; With the dot. ; Check if a file extension is supported on the system. Func _IsExtensionSupported($sExtension) Return FileExists(_WinAPI_AssocQueryString('.' & StringRegExpReplace($sExtension, '\A\.+', ''), $ASSOCSTR_EXECUTABLE)) = 1 EndFunc ;==>_IsExtensionSupported 

ReturnToContents

_IsFocused

Author: DelStone




Modified: guinness





; Check to see if a window / control has focus or not. Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) Local $iEdit = ControlGetHandle($hWnd, "", "[CLASS:Edit; INSTANCE:1]") ; Check if the Notepad window's edit control has focus and display the appropriate message box. If _IsFocused($hWnd, $iEdit) Then MsgBox(4096, "", "The edit control has keyboard focus. Select the Notepad title to see the caret.") Else MsgBox(4096, "", "The edit control doesn't have keyboard focus.") EndIf ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example ; Check if a control is focused. Func _IsFocused($hWnd, $iControlID) Return ControlGetHandle($hWnd, "", $iControlID) = ControlGetHandle($hWnd, "", ControlGetFocus($hWnd)) EndFunc ;==>_IsFocused 

ReturnToContents

_IsFullPath

Author: guinness








ConsoleWrite(_IsFullPath(@ScriptFullPath) & @CRLF) ConsoleWrite(_IsFullPath(@ScriptName) & @CRLF) Func _IsFullPath($sFilePath) Return StringInStr($sFilePath, ":\", 2) > 0 EndFunc ;==>_IsFullPath 

ReturnToContents

_IsOnTop

Author: guinness








; Check to see if a window is on top. #include <Constants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Example() Func Example() Local $hGUI = GUICreate('') GUISetState(@SW_SHOW, $hGUI) ; Set the GUI as being on top using the handle returned by GUICreate. WinSetOnTop($hGUI, '', 1) MsgBox(4096, '', 'Is the GUI on top: ' & _IsOnTop($hGUI) & ', this should be True') GUIDelete($hGUI) EndFunc ;==>Example ; Check if a window is on top. Func _IsOnTop($sTitle, $sText = '') Return BitAND(_WinAPI_GetWindowLong(WinGetHandle($sTitle, $sText), $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST EndFunc ;==>_IsOnTop 

ReturnToContents

_IsReadOnly

Author: guinness








ConsoleWrite(_IsReadOnly(@ScriptFullPath) & @CRLF) Func _IsReadOnly($sFilePath) Return StringInStr(FileGetAttrib($sFilePath), "R") > 0 EndFunc ;==>_IsReadOnly 

ReturnToContents

_IsMaximized

Author: guinness








; Check if the window is maximised. Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Set the state of the Notepad window to "maximized". WinSetState($hWnd, '', @SW_MAXIMIZE) ; Check if the Notepad window is maximized and display the appropriate message box. If _IsMaximized($hWnd) Then MsgBox(4096, "", "Notepad is maximized.") Else MsgBox(4096, "", "Notepad isn't maximized.") EndIf ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example Func _IsMaximized($hWnd) Return BitAND(WinGetState($hWnd), 32) = 32 EndFunc ;==>_IsMaximized 

ReturnToContents

_IsMinimized

Author: guinness








; Check if the window is minimized. Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Set the state of the Notepad window to "minimized". WinSetState($hWnd, '', @SW_MINIMIZE) ; Check if the Notepad window is minimized and display the appropriate message box. If _IsMinimized($hWnd) Then MsgBox(4096, "", "Notepad is minimized.") Else MsgBox(4096, "", "Notepad isn't minimized.") EndIf ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example Func _IsMinimized($hWnd) Return BitAND(WinGetState($hWnd), 16) = 16 EndFunc ;==>_IsMinimized 

ReturnToContents

_IsProcess64Bit

Author: guinness








#include <WinAPIEx.au3> Local $aArray = ProcessList() For $i = 1 To $aArray[0][0] ConsoleWrite('[' & $i & '] ' & $aArray[$i][0] & ' => ' & _Ternary(_IsProcess64Bit($aArray[$i][1]), 'Is a 64-bit application.', 'Is a 32-bit application.') & @CRLF) Next ; Version: 1.00. AutoIt: V3.3.8.1 ; Check if a process is a 64-bit executable. Returns 1 is natively 64-bit or 0 if 32-bit. Func _IsProcess64Bit($iPID = 0) If $iPID < 1 Then $iPID = ProcessExists($iPID) EndIf Return Number(_WinAPI_IsWow64Process($iPID) = 0) EndFunc ;==>_IsProcess64Bit Func _Ternary($iValue, $vTrue, $vFalse) ; Like _Iif. Local $aArray[2] = [$vFalse, $vTrue] Return $aArray[Number(Number($iValue) > 0)] EndFunc ;==>_Ternary 

ReturnToContents

_IsServiceRunning

Author: guinness








ConsoleWrite(_IsServiceRunning('wuauserv') & @CRLF) ConsoleWrite(_IsServiceRunning('Themes') & @CRLF) ConsoleWrite(_IsServiceRunning('winmgmt') & @CRLF) ConsoleWrite(_IsServiceRunning('AutoItService') & @CRLF) ; Check if a service is running. Func _IsServiceRunning($sService) Local $oShell = ObjCreate('shell.application') If @error Then Return SetError(1, 0, False) EndIf Return $oShell.IsServiceRunning($sService) EndFunc ;==>_IsServiceRunning 

ReturnToContents

_IsTaskbarHidden

Author: guinness








ConsoleWrite(_IsTaskbarHidden() & @CRLF) ; Detect whether the taskbar is hidden or not. Func _IsTaskbarHidden() Local Const $ABS_AUTOHIDE = 0x01, $ABM_GETSTATE = 0x00000004 Local $aReturn = DllCall('shell32.dll', 'uint', 'SHAppBarMessage', 'dword', $ABM_GETSTATE, 'ptr*', 0) If @error Then Return SetError(1, 0, 0) EndIf Return BitAND($aReturn[0], $ABS_AUTOHIDE) = $ABS_AUTOHIDE EndFunc ;==>_IsTaskbarHidden 

ReturnToContents

_PathSplitEx

Author: guinness








; A different approach to _PathSplit(), in which it returns a 1D array, it also uses faster comparison for StringInStr. ; Note: This is for fullpaths only e.g. C:\Test\Text.exe Local $aPathSplit = _PathSplitEx(@ScriptFullPath) _ArrayDisplay($aPathSplit) Func _PathSplitEx($sFilePath) Local $aReturn[5] = [$sFilePath], $iPosition = StringInStr($sFilePath, "\", 2, -1) $aReturn[1] = StringLeft($sFilePath, 2) $aReturn[2] = StringTrimLeft($sFilePath, 2) $aReturn[3] = StringTrimLeft($sFilePath, StringInStr($sFilePath, ".", 2, -1) - 1) $aReturn[4] = StringTrimRight(StringTrimLeft($sFilePath, $iPosition), StringLen($aReturn[4])) Return $aReturn EndFunc ;==>_PathSplitEx 

ReturnToContents

_PidGetPath

Author: SmOke_N








$PID = Run("notepad.exe") WinWaitActive("") MsgBox(0x0,"PID/Path", _PidGetPath($PID)) Func _PidGetPath($pid = "", $strComputer = 'localhost') If $pid = "" Then $pid = WinGetProcess(WinGetTitle("")) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $objItem.ExecutablePath Then Return $objItem.ExecutablePath Next EndIf EndFunc ;==>_PidGetPath 

ReturnToContents

QuickInfo

Author: Dasttann777








#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** MsgBox(0, "Welcome", "Scanning System", 2) MsgBox(0, "Quick Info", "Computer Name = " & @ComputerName & @CRLF & _ "Desktop Common Dir = " & @DesktopCommonDir & @CRLF & _ "Desktop Width = " & @DesktopWidth & @CRLF & _ "Desktop Height = " & @DesktopHeight & @CRLF & _ "Ip Address = " & @IPAddress1 & @CRLF & _ "OS Version = " & @OSVersion) 

ReturnToContents

_StripEnvVariable

Author: guinness








ConsoleWrite(EnvGet(_StripEnvVariable("%PATH%")) & @CRLF) ConsoleWrite(EnvGet(_StripEnvVariable("PATH%")) & @CRLF) ConsoleWrite(_StripEnvVariable("PATH") & @CRLF) ConsoleWrite(_StripEnvVariable("%PATH") & @CRLF) ; Strip the percentage signs from an environment variable. Func _StripEnvVariable($sVariable) Return StringRegExpReplace($sVariable, '%?(\V*)%+', '\1') ; '%*(.*?)%*' EndFunc ;==>_StripEnvVariable 

ReturnToContents

USB connections - All USB Devices

Author: Valuater








$strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice") For $objDevice in $colDevices $strDeviceName = $objDevice.Dependent ;ConsoleWrite("!>" & $strDeviceName & @CRLF) $strQuotes = Chr(34) $strDeviceName = StringReplace($strDeviceName, $strQuotes, "") $arrDeviceNames = StringSplit($strDeviceName, "=") $strDeviceName = $arrDeviceNames[2] $colUSBDevices = $objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'") For $objUSBDevice in $colUSBDevices ConsoleWrite("-->" & $objUSBDevice.Description & @CRLF) Next Next 

ReturnToContents

_WinAPI_IsEnvExists

Author: guinness








#include <WinAPI.au3> ConsoleWrite(_WinAPI_IsEnvExists("%SciTE_HOME%") & @CRLF) ConsoleWrite(_WinAPI_IsEnvExists("%PATH%") & @CRLF) ; Checks if an environment variable exists. Uses the API ExpandEnvironmentStrings, so therefore you must use an environment variable with ; percentage signs included. Func _WinAPI_IsEnvExists($sVariable) Return _WinAPI_ExpandEnvironmentStrings($sVariable) <> $sVariable EndFunc ;==>_IsEnvExists 


ConsoleWrite(_WinAPI_IsEnvExists("%SciTE_HOME%") & @CRLF) ConsoleWrite(_WinAPI_IsEnvExists("%PATH%") & @CRLF) ; Checks if an environment variable exists. Uses the API ExpandEnvironmentStrings, so therefore you must use an environment variable with ; percentage signs included. Func _WinAPI_IsEnvExists($sVariable) Local $aResult = DllCall('kernel32.dll', 'dword', 'ExpandEnvironmentStringsW', 'wstr', $sVariable, 'wstr', '', 'dword', 4096) If @error Then Return SetError(@error, @extended, 0) EndIf Return $aResult[2] <> $sVariable EndFunc ;==>_WinAPI_IsEnvExists 

ReturnToContents

_WinGetPath

Author: GaryFrost








; Get the execuatble path of a window $path = _WinGetPath() MsgBox(0,WinGetTitle(""),$path) Func _WinGetPath($Title="", $strComputer='localhost') $win = WinGetTitle($Title) $pid = WinGetProcess($win) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $objItem.ExecutablePath Then Return $objItem.ExecutablePath Next EndIf EndFunc ;==>_WinGetPath() 

ReturnToContents

_IsUACEnabled

Author: guinness








ConsoleWrite( _IsUACEnabled() & @CRLF) ; Returns 0/1 if disabled/enabled and sets @error to non-zero if the OS doesn't support UAC i.e. XP and below. Func _IsUACEnabled() If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentVersion") >= 6.0 Then Return Number(RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System", "ConsentPromptBehaviorAdmin") = 1) EndIf Return SetError(1, 0, 0) EndFunc ;==>_IsUACEnabled 

ReturnToContents