Sign in to follow this  
Followers 0
pete1234

Sorting start menu

5 posts in this topic

#1 ·  Posted (edited)

so this is my first post - i'm new to autoit and am still figuring things out. i'm not sure if this question is actually related to autoit, but i figure it can't hurt to ask. i'm trying to create a script that will sort the start menu by name. this is what i have so far:

RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder","")
If @Error <> 0 THEN RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder")
$PID = ProcessExists("explorer.exe")
If $PID Then ProcessClose($PID)
ProcessWaitClose("explorer.exe")
ShellExecute("explorer.exe")

when i follow this process manually, everything works fine. killing explorer.exe removes the taskbar, and then starting the process again restores it and creates the new reg key, thereby sorting the start menu. now the script i've created does all this too and works, but the shellexec function restores the taskbar and also opens windows explorer. when i do it by hand windows explorer doesnt open. any ideas as to why this is happening?

fwiw, im using xp pro sp2, and ive tried this with windows explorer both running and not and with Run instead of ShellExecute.

thanks!

Edited by pete1234

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the AutoIt forum,

The system reserves the 1st instance of Explorer for the shell and any extra instances open "My Documents" folder if no switch is passed. On Win XP and above, Explorer will restart within a few seconds if ProcessClose() is used on it. A CLI tool like TaskKill.exe in Win XP Pro can kill Explorer without it restarting but that is something else. Your script will open "My Documents" folder by Explorer as the shell opens just prior automatically by the OS.

Checking the process after 5 seconds maybe adequate to ensure Explorer restarts OK.

; Check menu order registry key and delete
$regKey = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder","")
If Not @Error Then
    If RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder") = 1 Then
        ; Return the Explorer ProcessID and then close it
        $PID = ProcessExists("explorer.exe")
        If $PID Then
            ProcessClose($PID)
            ; Start explorer if it does not exist in 5 seconds
            If Not ProcessWait("explorer.exe", 5) Then
                Run("explorer.exe")
            EndIf
        EndIf
    EndIf
EndIf

:)

Edit: Added condition check on RegDelete

Edited by MHz

Share this post


Link to post
Share on other sites

Well, a simple way to keep Explorer "killed" is:

AdlibEnable("_KillExplorer")
;your script 
Func _KillExplorer()
If ProcessExists("explorer.exe") Then ProcessKill("explorer.exe")
EndFunc

Later you just disable adlib and run explorer.


I can do signature me.

Share this post


Link to post
Share on other sites

While 1

Sleep(250)

Processclose("explorer.exe")

WEnd

then just go into the proccess's and disable it...(run this as a seperat file) thats what I did :)

Share this post


Link to post
Share on other sites

thanks for all the quick replies, i love that there's many different ways to accomplish the same task. MHz - your method worked great, thanks!

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