Thanks Tim,
That worked,

Also i wrote few lines of code to reboot a remote machine.

Here is it
------------------------------------------------
import win32api, win32security
hdl =
win32security.LogonUser(userName,domain,password,win32security.LOGON32_LOGON_NEW_CREDENTIALS,win32security.LOGON32_PROVIDER_WINNT50)
    win32security.ImpersonateLoggedOnUser(hdl)
    win32api.InitiateSystemShutdown(hostName, "This Machine will reboot in 5
seconds", 5, False, True)
    win32security.RevertToSelf()
    hdl.close()
 ------------------------------------------------------
issues here is:
   when i place this code in
        if __name__ == "__main__":

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:

error: (5, 'InitiateSystemShutdown', 'Access is denied.')

I'm i missing anything or any window's way of doing this kind of things.

Thank you very much for the responce.

Thanks,
Siddhartha



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

Reply via email to