|
|
#1 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Shut down computer
I'd like to add functionality to an updater thingy written in NSIS to shut down the computer when updates have been downloaded and installed. Can someone write me System plugin code to do this (I'd attempt it but I have no experience in that area)?
-Stu |
|
|
|
|
|
#2 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
This is the code I made after looking at MSDN, but it doesn't work.
System::Call "cimwin32::Win32Shutdown(i 5,) i.r0" -Stu |
|
|
|
|
|
#3 |
|
Major Dude
|
there are several win32-api functions to do this, documented on this page:
http://msdn.microsoft.com/library/de..._functions.asp the code you need looks like this: code: this will reboot windows immediatly (first parameter) with reason "software - upgrade" (second parameter). you also may use 0x00000008 (power off), 0x00000001 (shutdown) or 0 (logoff) instead of 0x00000002. exitwindowsex function reference, with even more codes ![]() all system shutdown reason codes this functions have some more parameters: InitiateSystemShutdown InitiateSystemShutdownEx hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#4 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
Use ExitWindowsEx. On Windows NT you'll have to adjust the process tokens. EnumUsersReg shows you how to do that.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#5 | |
|
Major Dude
|
maybe you better use the InitiateSystemShutdown function.
MSDN: Quote:
hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
|
#6 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Comm@nder21, that doesn't seem to work here.
System::Call "user32::ExitWindowsEx(i 0x00000001, i 0x00030003) i .r0" -Stu |
|
|
|
|
|
#7 |
|
Major Dude
|
hmm, maybe the values are wrong.
i took them 1:1 from the msdn ... you may try a zero for both values. the system should initiate a logoff. then at least the function itself works the right way
hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#8 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
lol tried 0 and 0 for both but instead of logging me off it just closed a few programs and then stopped. Atleast we know something works (sort of!)
-Stu |
|
|
|
|
|
#9 |
|
Major Dude
|
you may also try this one (win nt/xp/2k/2k3 only):
code: hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#10 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
That doesn't work either lol
Takes a while to execute it though. -Stu |
|
|
|
|
|
#11 |
|
Major Dude
|
this is very annoying ...
msdn sucks. or system.dll does. or i do. dunno ...
hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#12 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
NSIS denies exiting Windows while it's working (it returns FALSE to WM_QUERYENDSESSION).
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#13 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Oh, so that means this isn't possible through NSIS?
-Stu |
|
|
|
|
|
#14 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
Not without a plug-in to avoid the denial or a source code change.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#15 |
|
Major Dude
|
there's a force parameter for this one ...
hand by comm@nder21 ---------- WiKi pages:CreateInternetShortcut|Enhanced FindWindow|Parse CSV-Data|Open/Close CD-Drive|Installer without Icon|Vista application compatibility |
|
|
|
|
|
#16 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I ended up writing a small C++ app to do it. Shuts down computer after X seconds.
code: -Stu |
|
|
|
|
|
#17 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Actually, now I've learnt a lot of C++ in about 2 hours I'll turn this into a plugin with the option of chosing which shutdown type to do (ie log off, shutdown etc)
Not now though - at the weekend. -Stu |
|
|
|
|
|
#18 |
|
Major Dude
Join Date: May 2003
Posts: 681
|
try shutdown.exe from winxp (works also on 2k)
%windir%\system32\shutdown.exe -s -t 90 -c "Shutdown in 90secs" so nsis is closed but shutdown is initiated. Greets, Brummelchen |
|
|
|
|
|
#19 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Yeh thanks I was already aware of that but it doesn't seem to be on my Windows 98 machine so it's no use to me really. I also found this tool: http://www.budja.com/shutdown/
but again he designed it only for Windows XP. Windows 98 and 95 has REBOOT95.EXE too, but that's got a GUI which I don't want. -Stu |
|
|
|
|
|
#20 | |
|
Major Dude
Join Date: May 2003
Posts: 681
|
this one ?
http://www.tdnsoftware.com/download.html http://www.freeware-download.com/dow...tails/964.html Quote:
Greets, Brummelchen |
|
|
|
|
|
|
#21 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Right here is my first NSIS plugin:
http://nsis.sourceforge.net/mediawik...9/ShutDown.zip It's only 2.5kB ![]() Source and readme included. -Stu |
|
|
|
|
|
#22 |
|
M.I.A.
[NSIS Dev, Mod] Join Date: Oct 2001
Location: Israel
Posts: 11,343
|
If you're already using a plug-in, subclass the dialog and return TRUE for WM_QUERYSESSION instead of using EWX_FORCE.
NSIS FAQ | NSIS Home Page | Donate $ "I hear and I forget. I see and I remember. I do and I understand." -- Confucius |
|
|
|
|
|
#23 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I'll have a go
![]() -Stu |
|
|
|
|
|
#24 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Ok now I'm getting an error message with the heading:
dwwin.exe - DLL Initialisation Failed The message is something along the lines of "DLL failed to initialise because Windows is being shut down". Not the exact message because I can only see it for a split second. Any ideas? Should I attach the new source code? -Stu |
|
|
|
|
|
#25 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Ah right, dwwin.exe is Doctor Watson therefore I've got an error here somewhere.
Attached C source code. -Stu |
|
|
|
|
|
#26 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I was unable to get it to work, so I decided to go about it a different way.
The plugin now calls DestroyWindow to close NSIS safely. If this fails, the ExitWindowsEx is not called. I've added optional switches to enable EWX_FORCE and one to turn this safety feature off (user can then call Quit to close NSIS instead - e.g. in Section). Am I right in using DestroyWindow, or should I be sending WM_CLOSE instead. http://nsis.sourceforge.net/mediawik...utDown-0.2.zip -Stu |
|
|
|
|
|
#27 |
|
Guest
Posts: n/a
|
Is ShutDown-0.2.zip available for download anywhere?
The link in the post above doesn't work |
|
|
|
#28 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
http://nsis.sourceforge.net/File:ShutDown.zip
Edit: The file appears to have been deleted! I shall re-upload. Edit #2: Done. -Stu |
|
|
|
|
|
#29 |
|
Guest
Posts: n/a
|
Thanks
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|