本帖最后由 pcl_test 于 2015-9-13 13:54 编辑
- @echo off 2>nul 3>nul
- ::需要安装.Net Framework 2.0及以上
- set "netpath=%systemroot%\Microsoft.NET\Framework"
- for /f "delims=" %%a in ('dir /ad /b "%netpath%\v?.*"') do (
- if exist "%netpath%\%%a\csc.exe" (
- set "cscpath=%netpath%\%%a\csc.exe"
- goto :0
- )
- )
- :0
- >"%tmp%\$" more +15 "%~f0"
- "%cscpath%" /out:"%tmp%\$SetAffinity.exe" "%tmp%\$"
- "%tmp%\$SetAffinity.exe"
- pause&exit
- ::C# codes 参考http://caoshugui.blog.163.com/blog/static/25375653200910115329888/
- using System;
- using System.Diagnostics;
- namespace SetAffinity{
- class Myclass{
- static void Main(string[] args){
- //设置需修改CPU相关性的进程名
- String[] proname = new String[]{"game","ra2"};
- for (int i=0; i<proname.Length; i++){
- Process pro = Process.GetProcessesByName(proname[i])[0];
- //设置CPU相关性为cpu0
- pro.ProcessorAffinity = (System.IntPtr)1;
- }
- }
- }
- }
复制代码
|