I have a problem with the following line:
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 1)
I get the following traceback:
Traceback (most recent call last):
File "Terminator.py", line 25, in ?
main()
File "Terminator.py", line 21, in main
application = BoaApp(0)
File "C:\Python22\lib\site-packages\wxPython\wx.py", line 1748, in
__init__
_wxStart(self.OnInit)
File "Terminator.py", line 14, in OnInit
self.main = wxFrame.create(None)
File "wxFrame.py", line 22, in create
return mainFrame(parent)
File "wxFrame.py", line 72, in __init__
self.OnTimerEvent()
File "wxFrame.py", line 92, in OnTimerEvent
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 2)
pywintypes.api_error: (5, 'InitiateSystemShutdown', 'Acceso denegado.')
11:27:56: Debug: e:\projects\wx\src\msw\app.cpp(439):
'UnregisterClass(canvas)' failed with error 0x00000584 (la clase todavía
tiene ventanas abiertas.).
Why do I have access denied (Acceso denegado)?
I'm using Win2k and the account I'm using can shutdown the machine.
I'm using Python 2.2.2, wxPython 2.4.0.2 and win32all-148.
Thanks,
Leazen
[snip]
Your program must grant itself shutdown privileges. (if anyone knows
how, exactly, this is security, or even useful I am interested in
hearing)
try this (mostly plagiarized from Mark Hammond's python programming on
win32 which I strongly recommend for anyone doing win32/python):
import win32security
import win32api
from ntsecuritycon import *
def AdjustPrivilege(priv, enable=1):
# Get the process token
flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
# Get the ID for the system shutdown privilege
id = win32security.LookupPrivilegeValue(None, priv)
# Now obtain the privilege for this process
# Create a list of the privileges to be added
if enable:
newPrivileges = [(id, SE_PRIVILEGE_ENABLED)]
else:
newPrivileges = [(id, 0)]
win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges)
AdjustPrivilege(SE_SHUTDOWN_NAME)
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 1)
AdjustPrivilege(SE_SHUTDOWN_NAME, 0)
Hope that helps
-Mark
···
On Fri, 2003-02-07 at 09:32, Leazen wrote:
I have a problem with the following line:
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 1)
I get the following traceback:
Thank you very much and excuse me for this mail (which is not wxPython
related) I made a mistake.
Leazen
Roach, Mark R. wrote:
···
On Fri, 2003-02-07 at 09:32, Leazen wrote:
I have a problem with the following line:
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 1)
I get the following traceback:
[snip]
Your program must grant itself shutdown privileges. (if anyone knows
how, exactly, this is security, or even useful I am interested in
hearing)
try this (mostly plagiarized from Mark Hammond's python programming on
win32 which I strongly recommend for anyone doing win32/python):
import win32security
import win32api
from ntsecuritycon import *
def AdjustPrivilege(priv, enable=1):
# Get the process token
flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY
htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags)
# Get the ID for the system shutdown privilege
id = win32security.LookupPrivilegeValue(None, priv)
# Now obtain the privilege for this process
# Create a list of the privileges to be added
if enable:
newPrivileges = [(id, SE_PRIVILEGE_ENABLED)]
else:
newPrivileges = [(id, 0)]
win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges)
AdjustPrivilege(SE_SHUTDOWN_NAME)
win32api.InitiateSystemShutdown(None, "asdf", 5, true, 1)
AdjustPrivilege(SE_SHUTDOWN_NAME, 0)
Hope that helps
-Mark