
seanhart
Active Members-
Posts
31 -
Joined
-
Last visited
About seanhart
- Birthday 03/26/1975
Profile Information
-
Location
Ontario, Canada
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
seanhart's Achievements

Seeker (1/7)
3
Reputation
-
toasterking reacted to a post in a topic: RegWriteAllUsers / RegDeleteAllUsers
-
Klexur reacted to a post in a topic: Auto-sizing, moveable, borderless splash screen
-
dble reacted to a post in a topic: _DateCalc (new UDF)
-
I just noticed it appears to be broken on v3.2.10.0, some of the constants appear to be in use already (e.g. $SE_RESTORE_NAME, $TOKEN_ADJUST_PRIVILEGES). Does anyone know if these have been added as internal constants now? I'll take a look around and see what I can find. In the mean time just renaming the constants should do the trick.
-
McAfee detecting AutoIt as virus
seanhart replied to seanhart's topic in AutoIt General Help and Support
For those of us using AutoIt in our day to day jobs it's good to share information like this that could affect what we're doing. As soon as I started having these problems I checked the forums first to see if there was a known issue, and I'm glad to see others benefiting from this post. In any case, McAfee has now released an "emergency update" and specifically referenced AutoIt compiled scripts as the reason why. It's good to see it recognized as a legitimate program by one of the leading anti-virus vendors. McAfee mentions the false detection of AutoIt here: http://vil.nai.com/vil/content/v_140628.htm -
McAfee detecting AutoIt as virus
seanhart replied to seanhart's topic in AutoIt General Help and Support
I just finished working with McAfee support and doing testing, and they have confirmed the issue and said they will release the new DAT files (5181) today. -
Just a quick notice that McAfee AntiVirus with DAT files version 5180 (Dec 7) are detecting script compiled with AutoIt 3.2.2.0 as being infected with the YahLover.worm virus. I have opened a support ticket with McAfee and will provide an update when I have one.
-
Here's a slightly different approach to solve the same problem Some examples: $bitrate = _GetFileProperty("C:\WINDOWS\clock.avi", "Bit Rate") ;gives "00:00:12" $size = _GetFileProperty("C:\WINDOWS\Gone Fishing.bmp", "Dimensions") ;gives "128 x 128" $company = _GetFileProperty("C:\WINDOWS\Notepad.exe", "Company") ;gives "Microsoft Corporation"
-
I needed to create a function like this for a specific requirement so I thought I would share it. Uses FileRead and FileWrite to copy a file allowing for a progress bar showing amount of data copied. Also allows for slowing the copy down (copygap), to make it bandwidth friendly. This has been done before using external copy commands (like xcopy) and constant file size checking, but this method fit my requirement better. Enjoy! ; -- ProgressCopy -- ; Uses FileRead and FileWrite functions to do a binary copy of file data from ; one location to another with a progress bar. Note that time stamps will be ; different. ; ; Inputs ; $src : Full path to source file ; $dst : Full path to destination file (file name required) ; $copygap : Time in ms to leave between each copy of data (default 20ms) ; ; Returns 1 if success, 0 if failed Func ProgressCopy($src, $dst, $copygap = 20) Dim $OptEnv, $OptVar, $size, $count, $timer, $progress, $in, $out ; Turn off expanded environment or variables, can cause problems for binary read $OptEnv = Opt("ExpandEnvStrings", 0) $OptVar = Opt("ExpandVarStrings", 0) ; Get size of file to determine remaining $size = FileGetSize($src) ; Set up initial variables $count = 0 ;keep count of bytes copied $progress = 0 ;progress bar variable (0 - 100) $chunk = 16384 ;amount of data to copy at a time (bytes) $updatefreq = 500 ;frequency of update to progress bar (ms) $progtitle = "File Copy Progress" ;title of progress bar window $timer = TimerInit() ;initialize timer to keep track of update frequency ; Show progress bar ProgressOn($progtitle, "Copying " & $src & " ...", "0 of " & $size & " bytes copied. (0%)") ; Open input and output files (exit if error) $in = FileOpen($src, 0) If @error <> 0 Then Return 0 $out = FileOpen($dst, 2) If @error <> 0 Then FileClose($in) Return 0 EndIf ; Start reading input $bin = FileRead($in, $chunk) While @error = 0 ; Write chunk of data, keep trying for up to 10 seconds if failed Do FileWrite($out, $bin) Until (@error = 0) Or (TimerDiff($timer) > 10000) If @error <> 0 Then FileClose($in) FileClose($out) Return 0 EndIf ; Update copy counter $count = $count + $chunk ; Update progress as specified If (TimerDiff($timer) / $updatefreq) > 1 Then $progress = Int(($count / $size) * 100) ProgressSet($progress, $count & " of " & $size & " bytes copied. (" & $progress & "%)") $timer = TimerInit() EndIf ; Wait as specified Sleep($copygap) ; Get next chunk of data $bin = FileRead($in, $chunk) WEnd ; Show complete ProgressSet(100, $size & " of " & $size & " bytes copied. (100%)") ; Close files FileClose($in) FileClose($out) ; Hide progress bar Sleep(100) ProgressOff() ; Reset expanded environment or variables Opt("ExpandEnvStrings", $OptEnv) Opt("ExpandVarStrings", $OptVar) ; Return success Return 1 EndFunc
-
Thanks cryn for the feedback. I agree with you for point 1, it probably is faster to load files based on enumerating the profilelist in the registry. I've used that key in the past but didn't think about it for this use, good idea. Your second point isn't quite right though. I've written the script to try every ntuser.dat file in the profile folder, and you are correct that any profiles in use will fail. However the second part of the code then enumerates all loaded profile keys under HKU which will catch the ones that failed earlier. So it's not quite as clean as it can be but it does work for all profiles. I have excluded local system accounts by ignoring SIDs with 8 or less characters. I might re-write with some of your recommendations if I have time, thanks for them. Sean
-
I've tested on Win 2K, XP, and Vista (UAC turned off). Can't speak for 2003 (though it should work) or 64bit. Thanks to everyone else for the comments.
-
I needed to do this for work recently and thought I'd share it. Here is a UDF which allows you to write a user specific registry key to ever user profile on the system (whether logged on or off). Includes the "default user" registry, so changes apply to any new users that log on as well. Examples: ; Give everyone a new IE home page (note you don't need HKCU) RegWriteAllUsers("Software\Microsoft\Internet Explorer\Main", "Start Page", "REG_SZ", "http://www.google.com") ; Delete everyone's custom wallpaper (note it you can use HKCU if you want) RegDeleteAllUsers("HKEY_CURRENT_USER\Control Panel\Desktop", "WallPaper") Code uses RegLoadHive functions by Larry. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.2.0 Author: Sean Hart Script Function: UDFs to write or delete registry keys from all user profiles on the system. Uses RegLoadHive functions provided by Larry #ce ---------------------------------------------------------------------------- ; === RegWriteAllUsers === ; Writes "current user" registry data to every user profile on the system. ; Requires RegLoadHive and RegUnLoadHive functions. ; ; Inputs: $key - see RegWrite function for details (no HKU\HKCU\HKLM required) ; $value - see RegWrite function for details ; $type - see RegWrite function for details ; $data - see RegWrite function for details ; ; Returns: nothing Func RegWriteAllUsers($key, $value, $type, $data) Dim $i, $curkey, $ExpandEnvStrings, $profiledir, $curdir, $search ; init variables $i = 1 $error = 0 $ExpandEnvStrings = Opt("ExpandEnvStrings",1) $profiledir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory") ; change directory to profile directory $curdir = @WorkingDir FileChangeDir($profiledir) ; replace HKU / HKCU / HKLM in key if require Select Case StringLeft($key, 4) = "HKU\" $key = StringRight($key, StringLen($key) - 4) Case StringLeft($key, 5) = "HKCU\" $key = StringRight($key, StringLen($key) - 5) Case StringLeft($key, 5) = "HKLM\" $key = StringRight($key, StringLen($key) - 5) Case StringLeft($key, 11) = "HKEY_USERS\" $key = StringRight($key, StringLen($key) - 11) Case StringLeft($key, 18) = "HKEY_CURRENT_USER\" $key = StringRight($key, StringLen($key) - 18) Case StringLeft($key, 19) = "HKEY_LOCAL_MACHINE\" $key = StringRight($key, StringLen($key) - 19) EndSelect ; Go through all directories where ntuser.dat is accessible $search = FileFindFirstFile("*.*") $dir = FileFindNextFile($search) While @error = 0 ; Process directories If StringInStr(FileGetAttrib($profiledir & "\" & $dir), "D") Then ; Check for ntuser.dat If FileExists($profiledir & "\" & $dir & "\ntuser.dat") Then ; Try and load hive If RegLoadHive("TempUser", $profiledir & "\" & $dir & "\ntuser.dat") Then ; Apply new registry data RegWrite("HKEY_USERS\TempUser\" & $key, $value, $type, $data) ; Unload hive RegUnloadHive("TempUser") EndIf EndIf EndIf $dir = FileFindNextFile($search) WEnd ; Start by going through all currently logged on user keys (exclude system accounts and classes) $curkey = RegEnumKey("HKEY_USERS", $i) While @error = 0 If (StringLen($curkey) > 8) And (Not StringInStr($curkey, "_Classes")) Then RegWrite("HKEY_USERS\" & $curkey & "\" & $key, $value, $type, $data) EndIf $i = $i + 1 $curkey = RegEnumKey("HKEY_USERS", $i) WEnd ; Put settings back and change back to previous directory Opt("ExpandEnvStrings",$ExpandEnvStrings) FileChangeDir($curdir) EndFunc ; === END RegWriteAllUsers === ; === RegDeleteAllUsers === ; Deletes "current user" registry data from every user profile on the system. ; Requires RegLoadHive and RegUnLoadHive functions. ; ; Inputs: $key - see RegDelete function for details (no HKU\HKCU\HKLM required) ; $value - (optional) see RegDelete function for details ; ; Returns: nothing Func RegDeleteAllUsers($key, $value = "ÿ") Dim $i, $curkey, $ExpandEnvStrings, $profiledir, $curdir, $search ; init variables $i = 1 $error = 0 $ExpandEnvStrings = Opt("ExpandEnvStrings",1) $profiledir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory") ; change directory to profile directory $curdir = @WorkingDir FileChangeDir($profiledir) ; replace HKU / HKCU / HKLM in key if require Select Case StringLeft($key, 4) = "HKU\" $key = StringRight($key, StringLen($key) - 4) Case StringLeft($key, 5) = "HKCU\" $key = StringRight($key, StringLen($key) - 5) Case StringLeft($key, 5) = "HKLM\" $key = StringRight($key, StringLen($key) - 5) Case StringLeft($key, 11) = "HKEY_USERS\" $key = StringRight($key, StringLen($key) - 11) Case StringLeft($key, 18) = "HKEY_CURRENT_USER\" $key = StringRight($key, StringLen($key) - 18) Case StringLeft($key, 19) = "HKEY_LOCAL_MACHINE\" $key = StringRight($key, StringLen($key) - 19) EndSelect ; Go through all directories where ntuser.dat is accessible $search = FileFindFirstFile("*.*") $dir = FileFindNextFile($search) While @error = 0 ; Process directories If StringInStr(FileGetAttrib($profiledir & "\" & $dir), "D") Then ; Check for ntuser.dat If FileExists($profiledir & "\" & $dir & "\ntuser.dat") Then ; Try and load hive If RegLoadHive("TempUser", $profiledir & "\" & $dir & "\ntuser.dat") Then ; Delete registry data If $value = "ÿ" Then RegDelete("HKEY_USERS\TempUser\" & $key) Else RegDelete("HKEY_USERS\TempUser\" & $key, $value) EndIf ; Unload hive RegUnloadHive("TempUser") EndIf EndIf EndIf $dir = FileFindNextFile($search) WEnd ; Start by going through all currently logged on user keys (exclude system accounts and classes) $curkey = RegEnumKey("HKEY_USERS", $i) While @error = 0 If (StringLen($curkey) > 8) And (Not StringInStr($curkey, "_Classes")) Then ; Delete registry data If $value = "ÿ" Then RegDelete("HKEY_USERS\" & $curkey & "\" & $key) Else RegDelete("HKEY_USERS\" & $curkey & "\" & $key, $value) EndIf EndIf $i = $i + 1 $curkey = RegEnumKey("HKEY_USERS", $i) WEnd EndFunc ; === END RegDeleteAllUsers === ; === RegLoadHive === ; Loads a ntuser.dat file as a registry hive ; Requires SetPrivilege function. ; ; Inputs: $hiveName - name for the hive ; $NTUSER_datFile - full path to ntuser.dat file to load ; $RLH_key - (optional) root for hive (defaults to HKU) ; ; Returns: 1 - Successful ; 0 - Error (sets @error) Func RegLoadHive($hiveName, $NTUSER_datFile, $RLH_key = "HKU") If Not (@OSTYPE=="WIN32_NT") Then SetError(-1) Return 0 EndIf Const $HKEY_LOCAL_MACHINE = 0x80000002 Const $HKEY_USERS = 0x80000003 Const $SE_RESTORE_NAME = "SeRestorePrivilege" Const $SE_BACKUP_NAME = "SeBackupPrivilege" Local $RLH_ret Local $aPriv[2] If $RLH_key = "HKLM" Then $RLH_key = $HKEY_LOCAL_MACHINE ElseIf $RLH_key = "HKU" Then $RLH_key = $HKEY_USERS Else SetError(-2) Return 0 EndIf $aPriv[0] = $SE_RESTORE_NAME $aPriv[1] = $SE_BACKUP_NAME SetPrivilege($aPriv,1) $RLH_ret = DllCall("Advapi32.dll","int","RegLoadKey","int",$RLH_key,"str",$hiveName,"str",$NTUSER_datFile) SetError($RLH_ret[0]) Return Not $RLH_ret[0] EndFunc ; === END RegLoadHive === ; === RegUnloadHive === ; Unloads a registry hive ; Requires SetPrivilege function. ; ; Inputs: $hiveName - name for the hive ; $RLH_key - (optional) root for hive (defaults to HKU) ; ; Returns: 1 - Successful ; 0 - Error (sets @error) Func RegUnloadHive($hiveName, $RUH_key = "HKU") If Not (@OSTYPE=="WIN32_NT") Then SetError(-1) Return 0 EndIf Const $HKEY_LOCAL_MACHINE = 0x80000002 Const $HKEY_USERS = 0x80000003 Local $RUH_ret If $RUH_key = "HKLM" Then $RUH_key = $HKEY_LOCAL_MACHINE ElseIf $RUH_key = "HKU" Then $RUH_key = $HKEY_USERS Else SetError(-2) Return 0 EndIf $RUH_ret = DllCall("Advapi32.dll","int","RegUnLoadKey","int",$RUH_key,"Str",$hiveName) Return Not $RUH_ret[0] EndFunc ; === RegUnloadHive === ; === SetPrivilege === ; Special function for use with registry hive functions Func SetPrivilege( $privilege, $bEnable ) Const $TOKEN_ADJUST_PRIVILEGES = 0x0020 Const $TOKEN_QUERY = 0x0008 Const $SE_PRIVILEGE_ENABLED = 0x0002 Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv $nTokens = 1 $LUID = DLLStructCreate("dword;int") If IsArray($privilege) Then $nTokens = UBound($privilege) $TOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]") $NEWTOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]") $hCurrProcess = DLLCall("kernel32.dll","hwnd","GetCurrentProcess") $SP_auxret = DLLCall("advapi32.dll","int","OpenProcessToken","hwnd",$hCurrProcess[0], _ "int",BitOR($TOKEN_ADJUST_PRIVILEGES,$TOKEN_QUERY),"int_ptr",0) If $SP_auxret[0] Then $hToken = $SP_auxret[3] DLLStructSetData($TOKEN_PRIVILEGES,1,1) $nTokenIndex = 1 While $nTokenIndex <= $nTokens If IsArray($privilege) Then $priv = $privilege[$nTokenIndex-1] Else $priv = $privilege EndIf $ret = DLLCall("advapi32.dll","int","LookupPrivilegeValue","str","","str",$priv, _ "ptr",DLLStructGetPtr($LUID)) If $ret[0] Then If $bEnable Then DLLStructSetData($TOKEN_PRIVILEGES,2,$SE_PRIVILEGE_ENABLED,(3 * $nTokenIndex)) Else DLLStructSetData($TOKEN_PRIVILEGES,2,0,(3 * $nTokenIndex)) EndIf DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,1),(3 * ($nTokenIndex-1)) + 1) DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,2),(3 * ($nTokenIndex-1)) + 2) DLLStructSetData($LUID,1,0) DLLStructSetData($LUID,2,0) EndIf $nTokenIndex += 1 WEnd $ret = DLLCall("advapi32.dll","int","AdjustTokenPrivileges","hwnd",$hToken,"int",0, _ "ptr",DllStructGetPtr($TOKEN_PRIVILEGES),"int",DllStructGetSize($NEWTOKEN_PRIVILEGES), _ "ptr",DllStructGetPtr($NEWTOKEN_PRIVILEGES),"int_ptr",0) $f = DLLCall("kernel32.dll","int","GetLastError") EndIf $NEWTOKEN_PRIVILEGES = 0 $TOKEN_PRIVILEGES = 0 $LUID = 0 If $SP_auxret[0] = 0 Then Return 0 $SP_auxret = DLLCall("kernel32.dll","int","CloseHandle","hwnd",$hToken) If Not $ret[0] And Not $SP_auxret[0] Then Return 0 return $ret[0] EndFunc ; === END SetPrivilege ===RegAllUsers.au3
-
It's similar but a little more user friendly and robust. Using Simucal's UDF on my system gave the wrong results (for example my Company property was at index 33 instead of 30). My script pulls the property names directly from the directory object and doesn't rely on the index numbers. The property names also match with what you would see in explorer or other apps, thus it's easier to plug them in to the function instead of looking up the index number. I gave Simucal credit in my UDF for inspiring it though.
-
I just wrote the attached UDF to solve a need I had to be able to return the property of a file given the property name. If a property name is not specified or blank, a 2 dimensional array is returned listing all valid properties and their values. Some examples: $bitrate = _GetFileProperty("C:\WINDOWS\clock.avi", "Bit Rate") ;gives "00:00:12" $size = _GetFileProperty("C:\WINDOWS\Gone Fishing.bmp", "Dimensions") ;gives "128 x 128" $company = _GetFileProperty("C:\WINDOWS\Notepad.exe", "Company") ;gives "Microsoft Corporation" $all_props = _GetFileProperty("C:\WINDOWS\Notepad.exe") ; $all_props[3][1] = "Type" ; $all_props[3][2] = "Application" Enjoy! GetFileProperty.au3
-
I figure I should comment since I was one of the ones who was yelled at . Not that I blame Valik, I have to deal with help desk questions so I also get frustrated when the answers are there waiting to be searched. And I do try my best to search the forums before asking questions, but again if a feature is highly desired you'll only know from the number of posts it generates. So, why do I want the console option? Because I use AutoIt to write lots of "behind the scenes" silent utilities. I jumped for joy the first time I saw the #notrayicon option. Although these utilities are designed to be run by an automated method and thus invisible to the user, sometimes a tech needs to run one manually. And there's where console output comes in useful. I'd like to output something like "install completed successfully" or "unable to access network", etc, etc, but only when someone wants to see it (runs it manually). Otherwise it's easy enough to hide the console window output when it's not wanted (e.g. through a logon script). And in this case I don't want to use a splashtext window or message box because 99% of the time I don't want anyone to see anything. Of course I could require a command line option to make the utility silent or not silent (which I've done in the past) but some of our techs aren't too brite. So there it is, hope Valik doesn't find out where I live.
-
Great explanation, sorry for my ignorance! :">
-
Just going back to the original request for a second... and please bear with me because I'm not really a developer. Isn't the only reason ConsoleWrite () doesn't output to a DOS console is because AutoIt frees up the command line after running (ie. GUI mode)? How about a # command that tells AutoIt not to release the command line after running (like #notguimode or #dontrelease) so that ConsoleWrite () outputs to the DOS console until the script completes, thus avoiding the need for using "|more" to acheive that. Sean
-
How to detect system inactivity?
seanhart replied to seanhart's topic in AutoIt General Help and Support
It's definitely simpler and it doesn't technically watch the keyboard although it does watch for cursor movement which will work most of the time, but it's not as comprehensive as cameronsdad's one.