AutoHotkey Community

It is currently May 27th, 2012, 10:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: ShutdownWindows
PostPosted: February 12th, 2007, 11:24 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
There was a question in the Help section how to bring up the ShutdownWindows dialog. Actually, there are two methods: one documented, and one undocumented.

The documented one is via COM, but, I think it'll work only when explorer.exe is set as the shell. Anyway, here they are.

BOTH needs the latest build, 1.0.46.08.

Documented:
Code:
#NoEnv

CoInitialize()

GUID4String(       CLSID_Shell, "{13709620-C279-11CE-A49E-444553540000}")
GUID4String(IID_IShellDispatch, "{D8F015C0-C278-11CE-A49E-444553540000}")

; CreateObject( "Shell.Application" )
psh := CreateObject(CLSID_Shell, IID_IShellDispatch)

DllCall(VTable(psh, 20), "Uint", psh)
DllCall(VTable(psh,  2), "Uint", psh)

CoUninitialize()


VTable(ppv, nID)
{
   Return DecodeInteger( DecodeInteger(ppv) + nID * 4 )
}

DecodeInteger(ptr)
{
   Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
}

Ansi2Unicode(ByRef sString, ByRef wString, nLen = 0)
{
   If !nLen
      nLen := DllCall("MultiByteToWideChar"
      , "Uint", 0
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", 0
      , "int",  0)

   VarSetCapacity(wString, nLen * 2)

   DllCall("MultiByteToWideChar"
      , "Uint", 0
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", &wString
      , "int",  nLen)
}

GUID4String(Byref CLSID, sString)
{
   VarSetCapacity(CLSID, 16, 0)
   Ansi2Unicode(sString, wString, 39)
   DllCall("ole32\CLSIDFromString", "str", wString, "str", CLSID)
}

CreateObject(ByRef CLSID, ByRef IID)
{
   If ( StrLen(CLSID) = 38 )
   GUID4String(CLSID, CLSID)
   If ( StrLen(  IID) = 38 )
   GUID4String(  IID,   IID)
   DllCall("ole32\CoCreateInstance", "str", CLSID, "Uint", 0, "Uint", 1|2|4, "str", IID, "UintP", ppv)
   Return ppv
}

CoInitialize()
{
   DllCall("ole32\CoInitialize", "Uint", 0)
}

CoUninitialize()
{
   DllCall("ole32\CoUninitialize")
}



Undocumented:
Code:
hModule := DllCall("LoadLibrary", "str", "shell32.dll")
DllCall(DllCall("GetProcAddress", "Uint", hModule, "Uint", 60), "Uint", 0)
DllCall("FreeLibrary", "Uint", hModule)



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 12:52 am 
Offline

Joined: September 26th, 2006, 12:52 am
Posts: 160
Location: In a House, On my a55
uhm yer that might work or you could just use

Code:
shutdown 12


wow that was easy, you can also change the options to make it shutdown properly by changing 12 to something else

_________________
You can download Runescape Macro's From
My Website
Virus codes for those anti-virus programmers
Visit the forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 11:02 am 
Read again, Seclinix, the purpose is to show the standard Shutdown dialogue, not to shutdown inconditionnaly.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 11:09 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
Both examples do nothing here... (XP Pro SP2, german)

But maybe you can do it also this way?
Code:
msgbox, 4148, Question, Shutdown Windows?
IfMsgBox, Yes
   ShutDown, 4+8

Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 11:14 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Thalon wrote:
Both examples do nothing here... (XP Pro SP2, german)

Are you using the latest build 1.0.46.08?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 3:27 pm 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
No, 1.0.46.06

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 3:34 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Quote:
No, 1.0.46.06
So?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: ShutdownWindows
PostPosted: February 13th, 2007, 3:52 pm 
Sean wrote:
BOTH needs the latest build, 1.0.46.08.
Hey, this time he warned! :-D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 8:45 pm 
Offline

Joined: September 26th, 2006, 12:52 am
Posts: 160
Location: In a House, On my a55
yer but still why display the dialog, you eventually will shut down or log out anyway wont you.... so your degrading yourself by doing it the hard way instead of the simple way given to you

_________________
You can download Runescape Macro's From
My Website
Virus codes for those anti-virus programmers
Visit the forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 1:02 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
This works for me (XP SP2 English)
Code:
Send {LWIN}
Sleep 200
Send {UP}{ENTER}
It is useful to be assigned to a hotkey. You want to offer Cancel, in case the hotkey was pressed in error. A GUI is much more complex.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 2:01 am 
Offline

Joined: September 26th, 2006, 12:52 am
Posts: 160
Location: In a House, On my a55
nice "short script" lmao

_________________
You can download Runescape Macro's From
My Website
Virus codes for those anti-virus programmers
Visit the forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 2:27 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Laszlo wrote:
This works for me (XP SP2 English)

OK, I'm tired of this. I'm well aware of the methods you guys posted, and even happened to know of which API the Shutdown function uses. So, don't waste your time on this, or post them in a separate thread.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: ShutdownWindows
PostPosted: February 14th, 2007, 2:43 am 
Offline

Joined: January 18th, 2006, 7:39 am
Posts: 274
Location: Conway, Arkansas
Sean wrote:
The documented one is via COM, but, I think it'll work only when explorer.exe is set as the shell.


Sean, confirmed. Your first example does not work under the shell I use (one of the Blackbox for Windows variants) but your second one does. Just thought you'd like to know as an FYI.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: ShutdownWindows
PostPosted: February 14th, 2007, 2:47 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
skwire wrote:
Sean wrote:
The documented one is via COM, but, I think it'll work only when explorer.exe is set as the shell.


Sean, confirmed. Your first example does not work under the shell I use (one of the Blackbox for Windows variants) but your second one does. Just thought you'd like to know as an FYI.

Many thanks for taking your time to test it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2007, 8:55 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
:oops: I'm very sorry!
I've updated the version and both scripts do work now perfectly!
I really didn't think that these 0.02 versions make that difference! :oops:

Nice script :!:
Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group