0

I am using following code to show osk

os.system("C:\\PROGRA~1\\COMMON~1\\MICROS~1\\ink\\tabtip.exe")

this code open the osk successfully but when I try to close it using below code

os.system("TASKKILL /F /IM tabtip.exe")

It gives error of

ERROR: The process "TabTip.exe" with PID 10188 could not be terminated.
Reason: Access is denied.

This error is occurring because my script does not have admin rights but I don't understand why would I need it as I started the programs myself and also when normally when I use mouse to close the application it does not demand admin rights. Any idea on how can I solve it ....

Thanks for reading :)

abdulsamad
  • 158
  • 1
  • 10
  • this post is about showing the tabtip not closing it and also not in python :? – abdulsamad Mar 22 '21 at 01:40
  • Yes, the post explaining that the tabtip.exe is actually calling a COM object so that it can call the toggle method which hides/shows the window controlled by the service. Obviously, you would need to use `win32com.client` to create a COM object in python, but that really was left as an exercise to the reader. – Lynn Crumbling Mar 22 '21 at 02:15
  • ohh thanks I will look into details and share back , THANKS :) – abdulsamad Mar 22 '21 at 07:46
  • You're welcome - and good luck! :) – Lynn Crumbling Mar 22 '21 at 12:38
  • The C version of code is too complicated for me to convert it to python. Can you help me a bit to understand it. I understand the part that I need to create a COM object and then call toggle method on it . But for what class I have to create the object for ? – abdulsamad Mar 23 '21 at 08:30
  • I manage to understand the creating the Object part I need ProgID to open the object, on searching the registry I found out `TextInputPanel.TextInputPanel.1` is the ProgID of TabTip.exe but using following code `o = win32com.client.Dispatch("TextInputPanel.TextInputPanel.1")` I get error of `pywintypes.com_error: (-2147467262, 'No such interface supported', None, None)` – abdulsamad Mar 23 '21 at 09:47

1 Answers1

1

I ended up using comtypes instead of win32com:

import win32gui
from ctypes import HRESULT
from ctypes.wintypes import HWND
from comtypes import IUnknown, GUID, COMMETHOD
import comtypes.client

class ITipInvocation(IUnknown):
    _iid_ = GUID("{37c994e7-432b-4834-a2f7-dce1f13b834b}")
    _methods_ = [
        COMMETHOD([], HRESULT, "Toggle",
                  ( ['in'], HWND, "hwndDesktop" )
                  )
        ]

dtwin = win32gui.GetDesktopWindow();
ctsdk = comtypes.client.CreateObject("{4ce576fa-83dc-4F88-951c-9d0782b4e376}", interface=ITipInvocation)
ctsdk.Toggle(dtwin);
comtypes.CoUninitialize()
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • Yes I was also reading **comtypes** meanwhile as _@Simon Mourier_ suggested me [here](https://stackoverflow.com/questions/66761510/how-to-create-com-object-for-tabtip-exe-in-python?noredirect=1#comment118019158_66761510) – abdulsamad Mar 24 '21 at 04:23