December 14, 2024

AutoIT: Give users the ability to defrag without Admin access

I found a cool tool this weekend, called AutoIT V3.

You can find it here: http://www.autoitscript.com/autoit3/

I put together a script that will (running as the local admin) allow a user that has zero admin priviledges the ability to defrag their hard drive.

Here’s the script:
;**** AutoIT Script to allow users to defrag their hard drive ****
; Set the RunAs parameters to use local adminstrator account
RunAsSet(“Administrator”,@ComputerName, “PASSWORDHERE”)

; Run defrag as admin
RunWait(“mmc.exe dfrg.msc”,@SystemDir)

; Reset user’s permissions
RunAsSet()

;**** End of Script ****

Save this as defragit.au3, and then using the AutoIT scripting tools and compile the au3 you created.

You can download the script here.

And you can download AutoIT here.


If you want to add a cool Vista style .ico, look at Jrdn88’s gallery: http://jrdn88.deviantart.com/gallery/

9 thoughts on “AutoIT: Give users the ability to defrag without Admin access

  1. This is terrific! I’m not a hard-out scripter or anything but this looks like something I could use and solve a major issue. Thanks again

  2. when i try to run the compiled .exe, i get the defrag window, but it just sits there and doesn’t initiate the defrag process. is there an easy way to add a “click the defrag” button step to this script?

  3. For Windows 2000 systems look at Autodefrag.exe to automatically defrag a Windows 2000 system. Actually, this works for 2000/XP/2003.

    For Windows XP/2003, you can run defrag.exe and the drive letter you wish to defrag. (defrag.exe C:)

    Hope that helps.

  4. jqso do you need the adminstrator password or does it work regardless?

    in other words do can the lowly user run it with no problems?

  5. Hi, I cannot run it..
    it pop up an error msg.

    how to set this?
    RunAsSet(“Administrator”,@ComputerName, “PASSWORDHERE”)

    I put like that,
    RunAsSet(“Administrator”,@ComputerName, “12345”)

    is that ok?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.