问题描述
各位大佬,求代码求链接各种求
解决方案
解决方案二:
连续发了3个一样的帖子啊LZ
解决方案三:
你这做法太暴力了吧,可以考虑检测哪些应用、服务的内存占用过大,然后重启应用或服务。
解决方案四:
引用1楼wangjun8868的回复:
连续发了3个一样的帖子啊LZ
是啊兄弟比较急帮帮忙
解决方案五:
引用2楼ajianchina的回复:
你这做法太暴力了吧,可以考虑检测哪些应用、服务的内存占用过大,然后重启应用或服务。
兄弟帮帮忙找找这个程序该怎么写
解决方案六:
就是找你对应服务器可以获取当前内存的代码,然后根据获取到的内存值,判断是否要通过process执行关机重启的那个exe
解决方案七:
doubleavailable=0;ManagementClasscimobject2=newManagementClass("Win32_PerfFormattedData_PerfOS_Memory");ManagementObjectCollectionmoc2=cimobject2.GetInstances();foreach(ManagementObjectmo2inmoc2){available+=((Math.Round(Int64.Parse(mo2.Properties["AvailableMBytes"].Value.ToString())/1024.0,1)));}moc2.Dispose();cimobject2.Dispose();if(available>1024*4*1024)//4GB{//关机}
关机类[StructLayout(LayoutKind.Sequential,Pack=1)]internalstructTokPriv1Luid{publicintCount;publiclongLuid;publicintAttr;}[DllImport("kernel32.dll",ExactSpelling=true)]internalstaticexternIntPtrGetCurrentProcess();[DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolOpenProcessToken(IntPtrh,intacc,refIntPtrphtok);[DllImport("advapi32.dll",SetLastError=true)]internalstaticexternboolLookupPrivilegeValue(stringhost,stringname,reflongpluid);[DllImport("advapi32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolAdjustTokenPrivileges(IntPtrhtok,booldisall,refTokPriv1Luidnewst,intlen,IntPtrprev,IntPtrrelen);[DllImport("user32.dll",ExactSpelling=true,SetLastError=true)]internalstaticexternboolExitWindowsEx(intDoFlag,intrea);internalconstintSE_PRIVILEGE_ENABLED=0x00000002;internalconstintTOKEN_QUERY=0x00000008;internalconstintTOKEN_ADJUST_PRIVILEGES=0x00000020;internalconststringSE_SHUTDOWN_NAME="SeShutdownPrivilege";internalconstintEWX_LOGOFF=0x00000000;internalconstintEWX_SHUTDOWN=0x00000001;internalconstintEWX_REBOOT=0x00000002;internalconstintEWX_FORCE=0x00000004;internalconstintEWX_POWEROFF=0x00000008;internalconstintEWX_FORCEIFHUNG=0x00000010;privatestaticvoidDoExitWin(intDoFlag){boolok;TokPriv1Luidtp;IntPtrhproc=GetCurrentProcess();IntPtrhtok=IntPtr.Zero;ok=OpenProcessToken(hproc,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,refhtok);tp.Count=1;tp.Luid=0;tp.Attr=SE_PRIVILEGE_ENABLED;ok=LookupPrivilegeValue(null,SE_SHUTDOWN_NAME,reftp.Luid);ok=AdjustTokenPrivileges(htok,false,reftp,0,IntPtr.Zero,IntPtr.Zero);ok=ExitWindowsEx(DoFlag,0);}publicstaticvoidReboot(){DoExitWin(EWX_FORCE|EWX_REBOOT);}//关机publicstaticvoidPowerOff(){DoExitWin(EWX_FORCE|EWX_POWEROFF);}publicstaticvoidLogOff(){DoExitWin(EWX_FORCE|EWX_LOGOFF);}}