Jump to content

Seemingly Simple Problem - more advanced questions after


Recommended Posts

I'm looking to create something that a few people here have attempted but none (that I could find in about 50 various searches) have accomplished... I want to create a program that will toggle the showing/hiding of the desktop icons in WinXP SP2. There are some registry switches, and from what I've read, a restart of the explorer.exe process. No biggie. I've got the registry part figured out, that was rather easy. I thought I could also easily figure out the explorer call, except... I keep getting an error message:

"Windows cannot find '/inproc'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search."

The code I've used (and tried) is the following:

;#include <Process.au3>

$PID = ProcessExists("explorer.exe"); Will return the PID or 0 if the process isn't found.
If $PID Then ProcessClose($PID);

ProcessWaitClose($PID);

;Run(@ComSpec & " /c " & "explorer.exe /inproc" & @CRLF);
;ShellExecute("explorer","/inproc");
;_RunDOS("explorer.exe /inproc");
RunWait(@ComSpec & " /c explorer.exe /inproc");

The explorer process is found, closed, and then run again, but it errors with the call to restart explorer, the /inproc flag isn't properly sent and I cannot figure out why. By default calling explorer.exe when it's not running will restart the explorer process as well as open some default folder (usually defined in the call to explorer.exe). The /inproc flag/parameter tells explorer to not open any folder/window, so the process simply restarts as I want.

Anyone have any ideas?

Advanced question:

If anyone has any ideas on a better way to toggle the show/hide process I'd also be willing to listen - supposedly it's part of an undocumented call to shell32.dll - any ideas on where to start with that? :) I'm quite new to AutoIt and am having trouble finding specific things in the manual (as I'm just starting out).

Thanks for any assistance!

Edited by BrendonKoz
Link to comment
Share on other sites

That doesn't toggle the desktop icons, that toggles the "Show Desktop", similar to "Win+M" or "Win+D" key commands...of which I could imitate. I'm eventually looking to toggle the showing/hiding of the icons on the desktop itself (Right click on desktop, properties, Arrange Icons By, Show Desktop Icons). The easy way to get to that step is to change some registry keys and restart explorer.

Right now, I'm simply trying to execute the explorer.exe /inproc command to restart explorer without opening up any explorer folder windows (so that just the process starts).

I have to do some more research to figure out how the more advanced call to shell32.dll works - if that's the only way I could do something like that; hopefully it wouldn't be that hard. (I cannot imitate the right-click options I just showed in this instance due to security policies we will have on these machines).

Link to comment
Share on other sites

No, by hiding program manager it hides the desktop icons.. Atleast for me it does.. Can anyone else confirm? Obviously WinMinimizeAll is just there to make sure you can see the icons gone for 5 secs, which is what mimics Show Desktop.

Link to comment
Share on other sites

Perhaps because I had closed explorer and reopened a new process, and all the windows I had open were child processes of the original explorer process nothing minimized or was hidden for me. I'll try it when I get in to work tomorrow (since I'd have to log off or restart this to see if it'd work).

In the meantime, if you're still awake...can you tell why my /inproc flag can't be sent properly - can't figure out what I'm doing wrong there.

Thanks for your help.

(Edit: I'm currently on my laptop, Win XP MCE, but the OS in question we'd be using this on is XP Pro SP2.)

Edited by BrendonKoz
Link to comment
Share on other sites

Well, I just tested this on my work PC with XP Pro SP2. It does in fact work if the icons are already set to be shown, but our PC's will be starting up with the icons hidden and will need to toggle them back to shown. It does not work in this case.

So again... Can anyone see why the /inproc flag won't be sent to explorer in any of my attempts? You don't need to kill the Explorer process to test this (just comment out that line if you want to test it).

Edited by BrendonKoz
Link to comment
Share on other sites

I hate bumping things, but I'm not sure how things work with that here (hopefully it's not a huge "no-no").

I think if I were to learn why this doesn't work, it would help me learn why some other things I've been trying are also not working (with the Run commands).

Link to comment
Share on other sites

This worked for me. I unchecked Show Desktop Icons, so they were gone from the desktop. Compiled the script below and tossed it into my quicklaunch for easy access, then rebooted. When I logged back in, the desktop icons were still hidden, and once I clicked on the icon in my quicklaunch for the script below, it restarted explorer and brought the icons back.

RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced","HideIcons","REG_DWORD",0)
ProcessClose("explorer.exe")

Sleep(5000)

If Not ProcessExists("explorer.exe") Then
    $pid = Run (@ComSpec & " /c explorer.exe","",@SW_HIDE)
    Sleep(1000)
    ProcessClose($pid)
EndIf

As for why /inproc is giving you an error. It's because explorer.exe arguments don't work at all when you are starting explorer.exe fresh.. You can only use arguments with explorer.exe when it is already running.

Link to comment
Share on other sites

As for why /inproc is giving you an error. It's because explorer.exe arguments don't work at all when you are starting explorer.exe fresh.. You can only use arguments with explorer.exe when it is already running.

.......I would have never figured that out - I had thought I tried that edge case with Task Manager's run command-line box. Ugh. That script you just wrote, btw, is basically exactly what I was looking for. I'm now going to see if I can figure out an alternative way to do it (without manually editing the registry and restarting Explorer) - mostly to learn more about AutoIt, and partially because it's now the weekend and I have some time.

Thank you very much for your help, and even checking on the topic for followups after it was well buried..

Link to comment
Share on other sites

Here's an alternative way. There's still yet another way, but I *believe* this is the shortest amount of code to accomplish the task (if the function is removed and longhand was used instead). Thanks to MSDN2 documentation, Microsoft Forums, this question in the AutoIt forums, the PostMessage function by Uten, and most importantly the research done by these AutoHotKey users in this topic.

Func PostMessage($hWnd, $msg, $wParm, $lParm)
    Return DllCall("user32.dll", "int", "PostMessage", _
            "hwnd", $hWnd, _
            "int", $msg, _
            "int", $wParm, _
            "int", $lParm)
EndFunc  ;==>PostMessage

$programManager = WinGetHandle("Program Manager");
PostMessage($programManager, 0x111, 28755, 0);      Show/Hide desktop icons (0x0111 is defined as $WM_COMMAND in GUIConstants.au3)
PostMessage($programManager, 0x111, 28931, 0);      Refresh the desktop

So, there's still a way to poll the information using DllCall with shell32's function SHGetSetSettings and then using the last call here to refresh the desktop - I think that might be the most efficient way of doing it, but I'm not experienced enough with AutoIt and can't quite understand the DllCall function to properly use it, and feel safe about it.

Without that, I think that the safest way would be to use covak's registry edit with a toggle variable for the registry's value (read current value, set value as NOT the value since it's a bool, then write the value), and then use the desktop refresh code I have here rather than restarting Explorer. (Granted, I asked how to kill and restart explorer properly, but it ended up being I wanted something slightly different in the end. It still helped to learn more about AutoIt and I thank covaks for that greatly!)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...