Python writes automation to start a process at different priority levels

Source: Internet
Author: User
Tags win32

Processes on Windows, you can set priorities, such as


So, what if we need to prioritize processes in our automated testing process?

The following is the implementation of this function using the Win32 related interfaces, as follows:

# Gets the user handle htoken = win32security. OpenProcessToken (Win32API. GetCurrentProcess (), Win32con. Token_duplicate | Win32con. Token_adjust_default |win32con. Token_query | Win32con. token_assign_primary) hNewToken = Htoken authority = 0x0002000 if securitylevel! = "": AUT hority = 0x0002000 if securitylevel.lower () = = "Low": authority = 0x0001000 hNewToken = Win32 Security. Duplicatetokenex (Htoken, win32security. Securityimpersonation, 0, win32security. Tokenprimary, None) # build SID sid = Win32security for the corresponding level. SID () Sid. Initialize ((0, 0, 0, 0, 0, +), 1) SID. Setsubauthority (0, authority) # Sets the SID to the user handle win32security. Settokeninformation (hNewToken, win32security.        Tokenintegritylevel, (SID, Win32security.se_group_integrity)) CommandLine = Procpath + "" + param # Launcher Si = win32process. Startupinfo () win32process. CreateProcessAsUser (hnewToken, None, CommandLine, none, none, False, 0, none, none, Si) 
In this way, we can start the corresponding process using different priority ~ ~


Reprint Please specify: Http://blog.csdn.net/sogouauto

Explore test art, Exchange test technology, Welcome to the "Sogou test"


Python writes automation to start a process at different priority levels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.