Sign in to follow this  
Followers 0
ZacUSNYR

New coder, new to autoit - Feedback.

2 posts in this topic

I wrote this script.

Basically it copies a URL to All Users Desktop, Favorites for all user accounts on the machine, and to the favorites for Default user. Is there any thing "bad" about the way I did this? Any suggestions I could use to further my learning?

This does work and gives me the outcome I want. But I can't figure out how to check for the array and create it as need be in the loop, or to add to it, for the directory listing. Deleting the initial index after the loop was the only solution I could come up with.

Thanks!

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         ZacUSNYR

 Script Function:
    Copies Shortcuts into Favorites for all users, including the default user account, and onto the Desktop via All Users

#ce ----------------------------------------------------------------------------

#include <Array.au3>
#include <File.au3>
#NoTrayIcon
#AutoIt3Wrapper_icon="Setup.ico"

$userrootdir = @HomeDrive & "\Documents and Settings\"
$copy_desktop_dir = @DesktopCommonDir
$copy_defaultuser_dir = @HomeDrive & "\Documents and Settings\Default User\Favorites"
$shortcut_filename = "\\networkshare\shortcuts\shortcut.url"


Dim $userdirarray, $homedirarray, $excludedusersarray, $copy_destarray
$userdirarray = _ArrayCreate("0")
$homedirarray = _ArrayCreate("0")
$excludedusersarray = _ArrayCreate("Default User", "All Users", "NetworkService", "LocalService")
$copy_destarray = _ArrayCreate($copy_desktop_dir,$copy_defaultuser_dir)

$search = FileFindFirstFile($userrootdir & "*.*")

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    $dircheck = DirGetSize($userrootdir & $file, 1) 
        If IsArray($dircheck) Then
            _ArrayAdd ($homedirarray, $file)
        EndIf   
WEnd
FileClose($search)

_ArrayDelete($homedirarray, 0)

For $i = 0 To (UBound($excludedusersarray) - 1)
    _ArraySort($homedirarray)
    _CleanupUsers($excludedusersarray[$i])  
Next

For $i = 0 To (UBound($homedirarray) - 1)
    _ArrayAdd($copy_destarray, $userrootdir & $homedirarray[$i])
Next

For $i = 0 To (UBound($copy_destarray) -1)
    _ShortCutCopy($copy_destarray[$i])
Next


Func _CleanupUsers($check)
    $iKeyIndex = _ArrayBinarySearch ( $homedirarray, $check)
    If Not @error Then
       _ArrayDelete($homedirarray,$iKeyIndex)
    EndIf
EndFunc

Func _ShortcutCopy($destination)
    FileCopy ($shortcut_filename, $destination, 1)
EndFunc

Share this post


Link to post
Share on other sites



#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         ZacUSNYR

 Script Function:
    Copies Shortcuts into Favorites for all users, including the default user account, and onto the Desktop via All Users

#ce ----------------------------------------------------------------------------

#include <Array.au3>
#include <File.au3>
#NoTrayIcon
#AutoIt3Wrapper_icon="Setup.ico"

; $userrootdir = @HomeDrive & "\Documents and Settings\"
; The "Documents and Settings" not necessarily is at @HomeDrive & "\Documents and Settings\",
; this is always fact for non English Windows Versions... ;)
;
; This one below will always point to the correct location:
StringTrimRight(@DocumentsCommonDir,StringLen(@DocumentsCommonDir)-StringInStr(@DocumentsCommonDir,"\",0,-1))


; why assign a macro unmodified to a varable?
$copy_desktop_dir = @DesktopCommonDir

; this might be at different locations as well:
; $copy_defaultuser_dir = @HomeDrive & "\Documents and Settings\Default User\Favorites"
$copy_defaultuser_dir=RegRead("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites")

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0