Sending CTRL-C event to console application
Daniel Clark
djbclark at gmail.com
Fri Feb 9 15:55:46 EST 2007
On Feb 9, 9:12 am, "Daniel Clark" <djbcl... at gmail.com> wrote:
> I'm going to try taking a different approach by using a GUI Automation
> tool like WATSUP [1] or pywinauto[2] next.
This works:
AutoIT [1] code (compiled to an executable):
Run(@ComSpec & ' /k ' & $CmdLineRaw )
This was necessary because other means of starting cmd.exe didn't
actually spawn a new window. Syntax is just like:
C:\> autoitrun.exe "cd c:\Program Files\Tivoli\TSM & dir /s/p"
And that will pop up a new cmd.exe window with a dir /s/p listing of
cd c:\Program Files\Tivoli\TSM
Python code (changes service to be able to interact with desktop and
then runs the above):
import win32service
import os, sys
def EnsureInteractiveService(servicename):
scm = win32service.OpenSCManager(None, None,
win32service.SC_MANAGER_ALL_ACCESS)
try:
svc = win32service.OpenService(scm, servicename,
win32service.SC_MANAGER_ALL_ACCESS)
except:
print '''Error: Couldn't open service with name "''' +
servicename + '''"'''
sys.exit(1)
oldsvccfg = win32service.QueryServiceConfig(svc)
win32service.ChangeServiceConfig(svc, # scHandle
oldsvccfg[0] |
win32service.SERVICE_INTERACTIVE_PROCESS, # serviceType
oldsvccfg[1], # startType
oldsvccfg[2], # errorControl
oldsvccfg[3], # binaryFile
oldsvccfg[4], # loadOrderGroup
oldsvccfg[5], # bFetchTag
oldsvccfg[6], # serviceDeps
oldsvccfg[7], # acctName
'', # password
oldsvccfg[8]) # displayName
win32service.CloseServiceHandle(svc)
win32service.CloseServiceHandle(scm)
EnsureInteractiveService("TSM for WPLC")
os.chdir("c:\\Program Files\\WPLC-TSM\\updates")
os.system("autoitrun.exe dir /s/p")
[1] AutoIt v3 - Automate and Script Windows Tasks
http://www.autoitscript.com/autoit3/
More information about the Python-list
mailing list