Jump to content

Showing the desktop via IShellDispatch4


LxP
 Share

Recommended Posts

Hi guys,

A webpage gives some C# to toggle the desktop (equivalent to hitting Win+D):

// Create an instance of the shell class
Shell32.ShellClass objShel = new Shell32.ShellClass();

// Show the desktop
((Shell32.IShellDispatch4) objShel).ToggleDesktop();

// Do some operations here

// Restore the desktop
((Shell32.IShellDispatch4) objShel).ToggleDesktop();

I've spent an hour or so trying to convert this to its AutoIt equivalent. It obviously has something to do with ObjCreate() but everything I've tried so far has given me an @Error code of -2147221005 (odd)...

Local $Obj = ObjCreate("IShellDispatch4")
Local $Obj = ObjCreate("IShellDispatch4.This")
Local $Obj = ObjCreate("Shell.IShellDispatch4")
Local $Obj = ObjCreate("Shell32.IDispatch4")
Local $Obj = ObjCreate("Shell32.IID_IShellDispatch4")

Some other pieces of code floating around refer to this object by its CLSID but I'm not sure whether that can be done using AutoIt. I tried all sorts of things there too:

Local $Obj = ObjCreate("13709620-C279-11CE-A49E-444553540000")
Local $Obj = ObjCreate("{13709620-C279-11CE-A49E-444553540000}")
Local $Obj = ObjCreate("CLSID::13709620-C279-11CE-A49E-444553540000")
Local $Obj = ObjCreate("CLSID::{13709620-C279-11CE-A49E-444553540000}")

How might the above C# code be written for AutoIt?

Link to comment
Share on other sites

Try this:

$oShell = ObjCreate("Shell.Application")
$oShell.ToggleDesktop()

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

So simple -- I was way off. Thanks Dale!

For next time, how did you come up with Shell.Application from IShellDispatch4? I couldn't see anything obvious on MSDN saying that IShellDispatch objects extend Shell objects...

P.S. Thanks anyway Valuater!

Edited by LxP
Link to comment
Share on other sites

You want me to reveal my tricks huh? I was hoping you wouldn't ask ;)

I took a quick look in MSDN for an example of instantiating the IShellDispatch4 object... when I couldn't find one I thought, hmmm, I wonder if this will work... and it did...

Dale

So simple -- I was way off. Thanks Dale!

For next time, how did you come up with Shell.Application from IShellDispatch4? I couldn't see anything obvious on MSDN saying that IShellDispatch objects extend Shell objects...

P.S. Thanks anyway Valuater!

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

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...