亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.net中的CreateJobObject / SetInformationJobObject

.net中的CreateJobObject / SetInformationJobObject

LEATH 2019-10-29 10:35:08
我正在努力拼湊一個拼湊的CreateJobObject和SetInformationJobObject的工作示例。通過各種Google搜索(包括俄語和中文帖子?。覍⒁韵麓a拼湊在一起。我認為JOBOBJECT_BASIC_LIMIT_INFORMATION的定義根據平臺(32/64位)而變化。CreateJobObject / AssignProcessToJobObject 似乎可以工作。SetInformationJobObject失敗-錯誤24或87。Process myProcess // POPULATED SOMEWHERE ELSE// Create Job & assign this process and another process to the jobIntPtr jobHandle = CreateJobObject( null , null );AssignProcessToJobObject( jobHandle , myProcess.Handle );AssignProcessToJobObject( jobHandle , Process.GetCurrentProcess().Handle );// Ensure that killing one process kills the others                JOBOBJECT_BASIC_LIMIT_INFORMATION limits = new JOBOBJECT_BASIC_LIMIT_INFORMATION();limits.LimitFlags = (short)LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;IntPtr pointerToJobLimitInfo = Marshal.AllocHGlobal( Marshal.SizeOf( limits ) );Marshal.StructureToPtr( limits , pointerToJobLimitInfo , false );   SetInformationJobObject( job , JOBOBJECTINFOCLASS.JobObjectBasicLimitInformation , pionterToJobLimitInfo ,  ( uint )Marshal.SizeOf( limits ) )...        [DllImport( "kernel32.dll" , EntryPoint = "CreateJobObjectW" , CharSet = CharSet.Unicode )]        public static extern IntPtr CreateJobObject( SecurityAttributes JobAttributes , string lpName );        public class SecurityAttributes        {            public int nLength; //Useless field = 0            public IntPtr pSecurityDescriptor; //хз))            public bool bInheritHandle; //Возможность наследования            public SecurityAttributes()            {                this.bInheritHandle = true;                this.nLength = 0;                this.pSecurityDescriptor = IntPtr.Zero;            }        }        [DllImport( "kernel32.dll" )]        static extern bool SetInformationJobObject( IntPtr hJob , JOBOBJECTINFOCLASS JobObjectInfoClass , IntPtr lpJobObjectInfo , uint cbJobObjectInfoLength );
查看完整描述

3 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

總而言之,亞歷山大·葉祖托夫(Alexander Yezutov)構成的簽名在x86和x64上均可工作。當應改用UIntPtr時,Matt Howells簽名使用許多UInt32。我為CloseHandle使用了以下P / Invoke簽名,它似乎可以正常工作:


[DllImport("kernel32.dll", SetLastError = true)]

static extern bool CloseHandle(IntPtr hObject);

必須將以下內容添加到由Mas發布的app.manifest中:


<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">

<application>

  <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->


    <!--The ID below indicates application support for Windows Vista -->

    <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>


    <!--The ID below indicates application support for Windows 7 -->

    <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>


</application>

最后,從Visual Studio啟動時,這將不起作用(至少在Win 7下)。父進程必須從Windows資源管理器啟動。


查看完整回答
反對 回復 2019-10-29
  • 3 回答
  • 0 關注
  • 984 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號