在另一个桌面上启动进程,Python,Windows

时间:2014-05-16 06:36:49

标签: python winapi python-2.7 pywin32

我创建了第二个桌面

import win32api, win32con, win32gui, win32service, win32process
import pywintypes
import traceback, thread, time, cStringIO


k = win32service.CreateDesktop("ABCD2", 0, win32con.MAXIMUM_ALLOWED, None)

如何在桌面“ABCD2”上启动一个进程,例如calc.exe?

1 个答案:

答案 0 :(得分:2)

您可以将STARTUPINFO.lpDesktop设置为该桌面的名称:

import win32api, win32con, win32gui, win32service, win32process
#import pywintypes
#import traceback, thread, time, cStringIO


hDesktop = win32service.CreateDesktop("ABCD2",
                                      0,
                                      win32con.GENERIC_ALL,
                                      None)

win32api.Sleep(500)
StartInfo = win32process.STARTUPINFO()
StartInfo.lpDesktop = "ABCD2"

ProcInfo = win32process.CreateProcess(
    None,
    "mspaint.exe",
    None,
    None,
    True,
    win32con.NORMAL_PRIORITY_CLASS | win32con.CREATE_NEW_CONSOLE,
    None,
    None,
    StartInfo)