<div>Thanks Tim,</div>
<div>That worked,</div>
<div> </div>
<div>Also i wrote few lines of code to reboot a remote machine.</div>
<div> </div>
<div>Here is it</div>
<div>------------------------------------------------</div>
<div>import win32api, win32security</div>
<div>hdl = win32security.LogonUser(userName,domain,password,win32security.LOGON32_LOGON_NEW_CREDENTIALS,win32security.LOGON32_PROVIDER_WINNT50)<br> win32security.ImpersonateLoggedOnUser(hdl)<br> win32api.InitiateSystemShutdown(hostName, "This Machine will reboot in 5 seconds", 5, False, True)<br>
win32security.RevertToSelf()<br> hdl.close()</div>
<div> ------------------------------------------------------</div>
<div>issues here is:</div>
<div> when i place this code in </div>
<div> if __name__ == "__main__":</div>
<div> </div>
<div>it runs successfully(reboots the remote machine). But if i place this code in a function of a module ( like logon part in a function and initiateshutdown in other fuction) or whole code in a function it fails giving this error:</div>
<div> </div>
<div>error: (5, 'InitiateSystemShutdown', 'Access is denied.')</div>
<div> </div>
<div>I'm i missing anything or any window's way of doing this kind of things.</div>
<div> </div>
<div>Thank you very much for the responce.</div>
<div> </div>
<div>Thanks,</div>
<div>Siddhartha</div>
<div><br> </div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"> 1. Connection to remote machine registry fails.<br> (siddhartha veedaluru)<br> 2. Re: Connection to remote machine registry fails. (Tim Roberts)<br>
3. Re: problem in calling excel object quit method (Tim Roberts)<br> 4. window events via SetWindowsHookExA (Antoine Martin)<br> 5. Re: window events via SetWindowsHookExA (Tim Roberts)<br> 6. python-win32 : cross database automation (Threader Slash)<br>
<br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Thu, 17 Sep 2009 18:04:15 +0530<br>From: siddhartha veedaluru <<a href="mailto:siddhartha.veedaluru@gmail.com">siddhartha.veedaluru@gmail.com</a>><br>
To: <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>Subject: [python-win32] Connection to remote machine registry fails.<br>Message-ID:<br> <<a href="mailto:424b71ec0909170534i36c31653ic277b39699e38300@mail.gmail.com">424b71ec0909170534i36c31653ic277b39699e38300@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br><br>Hi ,<br><br>I'm trying to connect to a remote windows machine's registry using<br>ConnectRegistry and try to get the process architecture information.<br>
<br><br>Here is the code snippet for it<br>#processRegKey = "System\CurrentControlSet\Control\Session<br>Manager\Environment"<br>#processRegValue = "PROCESSOR_ARCHITECTURE"<br>#try:<br># regHandle =<br>
ConnectRegistry(r"\\atom",HKEY_LOCAL_MACHINE<file://atom%22,hkey_local_machine/><br>)<br># regHandleObj = OpenKey(regHandle, processRegKey)<br># processType = QueryValueEx(regHandleObj, processRegValue)[0].split("<br>
")[0]<br># print processType<br>#except Exception, erno:<br># print "Exception:"<br># print erno<br><br>but it fails with access denied errors.<br>I assume that there is credentials issue.<br>but i have the credential, but where should i have to provide this.<br>
<br><br>Please help in accesing remote machine adderss.<br>Also the machine might be in another domain.<br><br>i know that we have wmi module. just try to achive it with win32 Api.<br><br>Thanks,<br>sid.<br>-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>URL: <<a href="http://mail.python.org/pipermail/python-win32/attachments/20090917/daf021f3/attachment-0001.htm" target="_blank">http://mail.python.org/pipermail/python-win32/attachments/20090917/daf021f3/attachment-0001.htm</a>><br>
<br>------------------------------<br><br>Message: 2<br>Date: Thu, 17 Sep 2009 09:49:26 -0700<br>From: Tim Roberts <<a href="mailto:timr@probo.com">timr@probo.com</a>><br>To: Python-Win32 List <<a href="mailto:python-win32@python.org">python-win32@python.org</a>><br>
Subject: Re: [python-win32] Connection to remote machine registry<br> fails.<br>Message-ID: <<a href="mailto:4AB26896.70207@probo.com">4AB26896.70207@probo.com</a>><br>Content-Type: text/plain; charset=ISO-8859-1<br>
<br>siddhartha veedaluru wrote:<br>><br>> I'm trying to connect to a remote windows machine's registry using<br>> ConnectRegistry and try to get the process architecture information.<br>><br>> Here is the code snippet for it<br>
> #processRegKey = "System\CurrentControlSet\Control\Session<br>> Manager\Environment"<br>> #processRegValue = "PROCESSOR_ARCHITECTURE"<br>> #try:<br>> # regHandle = ConnectRegistry(r"\\atom",HKEY_LOCAL_MACHINE<br>
> <file://atom%22,hkey_local_machine/>)<br>> # regHandleObj = OpenKey(regHandle, processRegKey)<br>> # processType = QueryValueEx(regHandleObj,<br>> processRegValue)[0].split(" ")[0]<br>
> # print processType<br>> #except Exception, erno:<br>> # print "Exception:"<br>> # print erno<br>><br>> but it fails with access denied errors.<br>> I assume that there is credentials issue.<br>
> but i have the credential, but where should i have to provide this.<br><br>If the user you are currently logged in as is valid on the other<br>machine, this should just work.<br><br>Otherwise, you will have to call win32security.LogonUser and<br>
win32security.ImpersonateLoggedOnUser before calling ConnectRegistry.<br><br> handle = win32Security.LogonUser( 'username', 'domain', 'password',<br> win32con.LOGON32_LOGON_INTERACTIVE,<br>
win32con.LOGON32_PROVIDER_DEFAULT )<br> win32security.ImpersonateLoggonOnUser( handle )<br><br> # ... connect to to registry here ...<br><br> win32security.RevertToSelf()<br> handle.Close()<br><br>--<br>Tim Roberts, <a href="mailto:timr@probo.com">timr@probo.com</a><br>
Providenza & Boekelheide, Inc.<br><br><br><br>------------------------------<br><br>Message: 3<br>Date: Thu, 17 Sep 2009 09:51:19 -0700<br>From: Tim Roberts <<a href="mailto:timr@probo.com">timr@probo.com</a>><br>
To: Python-Win32 List <<a href="mailto:python-win32@python.org">python-win32@python.org</a>><br>Subject: Re: [python-win32] problem in calling excel object quit<br> method<br>Message-ID: <<a href="mailto:4AB26907.7050408@probo.com">4AB26907.7050408@probo.com</a>><br>
Content-Type: text/plain; charset=ISO-8859-1<br><br>Puneet Singh wrote:<br>><br>> Hi,<br>><br>> I am calling quit() from a thread but its not working<br>><br><br>You need to call Quit from the thread that created the Excel object.<br>
Are you doing that?<br><br>--<br>Tim Roberts, <a href="mailto:timr@probo.com">timr@probo.com</a><br>Providenza & Boekelheide, Inc.<br><br><br><br>------------------------------<br><br>Message: 4<br>Date: Fri, 18 Sep 2009 02:14:33 +0700<br>
From: Antoine Martin <<a href="mailto:antoine@nagafix.co.uk">antoine@nagafix.co.uk</a>><br>To: <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>Subject: [python-win32] window events via SetWindowsHookExA<br>
Message-ID: <<a href="mailto:4AB28A99.5000407@nagafix.co.uk">4AB28A99.5000407@nagafix.co.uk</a>><br>Content-Type: text/plain; charset=UTF-8<br><br>-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA512<br><br>Hi,<br><br>
I am trying to use SetWindowsHookExA via ctypes to be notified when<br>Windows are mapped/unmapped, to get the same functionality as<br>SUBSTRUCTURE_MASK events on the root X-window (or is there a better way<br>that I have missed?)<br>
<br>Here is the code:<br><br>WIN_HOOK = CFUNCTYPE(c_long, c_int, c_uint, c_long)<br>def register_hook()<br> WH_CALLWNDPROCRET = 4<br> dll_handle = ctypes.windll.user32._handle<br> self.call_next_hook = ctypes.windll.user32.CallNextHookEx<br>
self.hook_handle =<br>types.windll.user32.SetWindowsHookExA(WH_CALLWNDPROCRET,<br>WIN_HOOK(window_hook), dll_handle, 0)<br><br>def window_hook(self, nCode, wParam, lParam):<br> print "hello"<br> return self.call_next_hook(self.hook_handle, nCode, wParam, lParam)<br>
<br>Something with the callback signature must be wrong because the hook<br>does get registered (hook_handle>0), but as soon as a window event<br>fires, my application is terminated. It does not even get to say hello...<br>
<br>Here's what I used to figure out the C method signature:<br><a href="http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx</a><br>
<br>Apologies if this is not the right list (please let me know which one<br>is), it definitely looks like people here are most likely to be able to<br>help me.<br><br>Thanks<br>Antoine<br>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.9 (GNU/Linux)<br>Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org</a><br><br>iEYEAREKAAYFAkqyipIACgkQGK2zHPGK1rsYnACfSmX8S99kF0JZbvjRAeFSMAGU<br>
hIMAniBF8mbW3/9xbhSU3zD0c+xluf/p<br>=rWxJ<br>-----END PGP SIGNATURE-----<br><br><br>------------------------------<br><br>Message: 5<br>Date: Thu, 17 Sep 2009 14:03:48 -0700<br>From: Tim Roberts <<a href="mailto:timr@probo.com">timr@probo.com</a>><br>
To: Python-Win32 List <<a href="mailto:python-win32@python.org">python-win32@python.org</a>><br>Subject: Re: [python-win32] window events via SetWindowsHookExA<br>Message-ID: <<a href="mailto:4AB2A434.4000701@probo.com">4AB2A434.4000701@probo.com</a>><br>
Content-Type: text/plain; charset=ISO-8859-1<br><br>Antoine Martin wrote:<br>><br>> I am trying to use SetWindowsHookExA via ctypes to be notified when<br>> Windows are mapped/unmapped, to get the same functionality as<br>
> SUBSTRUCTURE_MASK events on the root X-window (or is there a better way<br>> that I have missed?)<br><br>WH_CALLWNDPROC is a bit extreme. The equivalent to mapping and<br>unmapping in the Windows world is activation, done with the WM_ACTIVATE<br>
and WM_DEACTIVATE messages. You should be able to monitor those with<br>WH_CBT, which is a bit lighter weight than the WH_CALLWNDPROC hooks.<br><br>There is a problem with your code, however:<br><br><br>> Here is the code:<br>
><br>> WIN_HOOK = CFUNCTYPE(c_long, c_int, c_uint, c_long)<br>> def register_hook()<br>> WH_CALLWNDPROCRET = 4<br>> dll_handle = ctypes.windll.user32._handle<br>> self.call_next_hook = ctypes.windll.user32.CallNextHookEx<br>
> self.hook_handle =<br>> types.windll.user32.SetWindowsHookExA(WH_CALLWNDPROCRET,<br>> WIN_HOOK(window_hook), dll_handle, 0)<br><br>You are telling it that the function to be called is inside of<br>user32.dll. When you install an invasive hook like this, the operating<br>
system actually injects that DLL into every process that owns a window.<br>Your hook function is then called in the context of those other<br>processes. That's why they tell you that most hook procedures must<br>reside in a DLL.<br>
<br>In your case, the function address you gave is local to your EXE. It<br>won't exist in other processes (or it will point to random memory).<br>When the first event occurs, your callback will be called in a thread in<br>
some other process. That thread gets an exception, because that address<br>points into random space, and your app is terminated.<br><br>There used to be a great project at the University of North Carolina<br>called pyAA that could do this, but it hasn't been updated past Python<br>
2.4. At this point, I do not know of a way to implement Windows hooks<br>in straight Python.<br><br>--<br>Tim Roberts, <a href="mailto:timr@probo.com">timr@probo.com</a><br>Providenza & Boekelheide, Inc.<br><br><br><br>
------------------------------<br><br>Message: 6<br>Date: Fri, 18 Sep 2009 14:17:09 +1000<br>From: Threader Slash <<a href="mailto:threaderslash@gmail.com">threaderslash@gmail.com</a>><br>To: <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
Subject: [python-win32] python-win32 : cross database automation<br>Message-ID:<br> <<a href="mailto:f1fcc2170909172117g470c47d2vcf461c7192c71e1c@mail.gmail.com">f1fcc2170909172117g470c47d2vcf461c7192c71e1c@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br><br>Hello Everybody...<br><br>I working on a client-server database solution. The system is normalized and<br>is using MySQL. To automate some of processes I using Python. Part of the<br>
old database will be still running on Lotus Notes.<br><br>After working on it, it seems that the best choice to directly manipulate<br>Lotus is to use Python with win32COM -<br><a href="http://www.boddie.org.uk/python/COM.html" target="_blank">http://www.boddie.org.uk/python/COM.html</a> . I installed ActivePython 2.6<br>
compiler, which comes with integrated win32com.<br><br>However, when I try to run.. it gives me the error:<br><br>--x--x--<br><br>ActivePython 2.6.2.2 (ActiveState Software Inc.) based on<br>Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)]<br>
on<br>win32<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import win32com.client<br>>>> sess=win32com.client.Dispatch("Lotus.NotesSession")<br>
Traceback (most recent call last):<br>File "<stdin>", line 1, in <module><br>File "C:\dev\python\Py26\lib\site-packages\win32com\client\__init__.py",<br>line 95, in Dispatch<br>dispatch, userName =<br>
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)<br>File "C:\dev\python\Py26\lib\site-packages\win32com\client\dynamic.py", line<br>98, in _GetGoodDispatchAndUserN<br>ame<br>return (_GetGoodDispatch(IDispatch, clsctx), userName)<br>
File "C:\dev\python\Py26\lib\site-packages\win32com\client\dynamic.py", line<br>78, in _GetGoodDispatch<br>IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,<br>pythoncom.IID_IDispatch)<br>pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)<br>
<br>--x--x--<br><br>Any suggestions? Some help is mostly appreciated.<br><br>I will keep working to get it fixed, after I post the working solution here.<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>
URL: <<a href="http://mail.python.org/pipermail/python-win32/attachments/20090918/6c4af594/attachment.htm" target="_blank">http://mail.python.org/pipermail/python-win32/attachments/20090918/6c4af594/attachment.htm</a>><br>
<br>------------------------------<br><br>_______________________________________________<br>python-win32 mailing list<br><a href="mailto:python-win32@python.org">python-win32@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
<br><br>End of python-win32 Digest, Vol 78, Issue 16<br>********************************************<br></blockquote></div><br>