问题描述
之前我用的是下面的,但是锁定的状态下就失效了,请问有什么别的方法吗?PublicClassWindowsControllerPublicEnumRestartOptionsLogOff=0PowerOff=8Reboot=2ShutDown=1Suspend=-1Hibernate=-2EndEnumPublicStructureLUIDDimLowPartAsIntegerDimHighPartAsIntegerEndStructurePublicStructureLUID_AND_ATTRIBUTESDimpLuidAsLUIDDimAttributesAsIntegerEndStructurePublicStructureTOKEN_PRIVILEGESDimPrivilegeCountAsIntegerDimPrivilegesAsLUID_AND_ATTRIBUTESEndStructurePrivateConstTOKEN_ADJUST_PRIVILEGES=&H20PrivateConstTOKEN_QUERY=&H8PrivateConstSE_PRIVILEGE_ENABLED=&H2PrivateConstFORMAT_MESSAGE_FROM_SYSTEM=&H1000PrivateConstEWX_FORCE=4DeclareFunctionLoadLibraryLib"kernel32"Alias"LoadLibraryA"(ByVallpLibFileNameAsString)AsIntPtrDeclareFunctionFreeLibraryLib"kernel32"(ByValhLibModuleAsIntPtr)AsIntegerDeclareFunctionGetProcAddressLib"kernel32"(ByValhModuleAsIntPtr,ByVallpProcNameAsString)AsIntPtrDeclareFunctionSetSuspendStateLib"Powrprof"(ByValHibernateAsInteger,ByValForceCriticalAsInteger,ByValDisableWakeEventAsInteger)AsIntegerDeclareFunctionOpenProcessTokenLib"advapi32.dll"(ByValProcessHandleAsIntPtr,ByValDesiredAccessAsInteger,ByRefTokenHandleAsIntPtr)AsIntegerDeclareFunctionLookupPrivilegeValueLib"advapi32.dll"Alias"LookupPrivilegeValueA"(ByVallpSystemNameAsString,ByVallpNameAsString,ByReflpLuidAsLUID)AsIntegerDeclareFunctionAdjustTokenPrivilegesLib"advapi32.dll"(ByValTokenHandleAsIntPtr,ByValDisableAllPrivilegesAsInteger,ByRefNewStateAsTOKEN_PRIVILEGES,ByValBufferLengthAsInteger,ByRefPreviousStateAsTOKEN_PRIVILEGES,ByRefReturnLengthAsInteger)AsIntegerDeclareFunctionExitWindowsExLib"user32"(ByValuFlagsAsInteger,ByValdwReservedAsInteger)AsIntegerDeclareFunctionFormatMessageLib"kernel32"Alias"FormatMessageA"(ByValdwFlagsAsInteger,ByVallpSourceAsIntPtr,ByValdwMessageIdAsInteger,ByValdwLanguageIdAsInteger,ByVallpBufferAsStringBuilder,ByValnSizeAsInteger,ByValArgumentsAsInteger)AsIntegerPublicSubExitWindows(ByValhowAsRestartOptions,ByValforceAsBoolean)SelectCasehowCaseRestartOptions.SuspendSuspendSystem(False,force)CaseRestartOptions.HibernateSuspendSystem(True,force)CaseElseExitWindows(Convert.ToInt32(how),force)EndSelectEndSubProtectedSubExitWindows(ByValhowAsInteger,ByValforceAsBoolean)EnableToken("SeShutdownPrivilege")IfforceThenhow=howOrEWX_FORCEIf(ExitWindowsEx(how,0)=0)ThenThrowNewPrivilegeException(FormatError(Marshal.GetLastWin32Error()))EndSubProtectedSubEnableToken(ByValprivilegeAsString)IfNotCheckEntryPoint("advapi32.dll","AdjustTokenPrivileges")ThenReturnDimtokenHandleAsIntPtr=IntPtr.ZeroDimprivilegeLUID=NewLUID()DimnewPrivileges=NewTOKEN_PRIVILEGES()DimtokenPrivilegesAsTOKEN_PRIVILEGESIf(OpenProcessToken(Process.GetCurrentProcess().Handle,TOKEN_ADJUST_PRIVILEGESOrTOKEN_QUERY,tokenHandle))=0ThenThrowNewPrivilegeException(FormatError(Marshal.GetLastWin32Error()))If(LookupPrivilegeValue("",privilege,privilegeLUID))=0ThenThrowNewPrivilegeException(FormatError(Marshal.GetLastWin32Error()))tokenPrivileges.PrivilegeCount=1tokenPrivileges.Privileges.Attributes=SE_PRIVILEGE_ENABLEDtokenPrivileges.Privileges.pLuid=privilegeLUIDDimSizeAsInteger=4If(AdjustTokenPrivileges(tokenHandle,0,tokenPrivileges,4+(12*tokenPrivileges.PrivilegeCount),newPrivileges,Size))=0ThenThrowNewPrivilegeException(FormatError(Marshal.GetLastWin32Error()))EndSubProtectedSubSuspendSystem(ByValhibernateAsBoolean,ByValforceAsBoolean)IfNotCheckEntryPoint("powrprof.dll","SetSuspendState")ThenThrowNewPlatformNotSupportedException("TheSetSuspendStatemethodisnotsupportedonthissystem!")SetSuspendState(Convert.ToInt32(IIf(hibernate,1,0)),Convert.ToInt32(IIf(force,1,0)),0)EndSubProtectedFunctionCheckEntryPoint(ByVallibraryAsString,ByValmethodAsString)AsBooleanDimlibPtrAsIntPtr=LoadLibrary(library)IfNotlibPtr.Equals(IntPtr.Zero)ThenIfNotGetProcAddress(libPtr,method).Equals(IntPtr.Zero)ThenFreeLibrary(libPtr)ReturnTrueEndIfFreeLibrary(libPtr)EndIfReturnFalseEndFunctionProtectedFunctionFormatError(ByValnumberAsInteger)AsStringDimBuffer=NewStringBuilder(255)FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,IntPtr.Zero,number,0,Buffer,Buffer.Capacity,0)ReturnBuffer.ToString()EndFunctionEndClassPublicClassPrivilegeExceptionInheritsExceptionPublicSubNew()MyBase.New()EndSubPublicSubNew(ByValmessageAsString)MyBase.New(message)EndSubEndClass
解决方案
解决方案二:
各位帮帮忙啊,谢谢了
解决方案三:
锁定计算机的状态下,计算机是无法进行任何操作的。其他的也等大侠来。
解决方案四:
直接按重启键或关机键或直接拔电源
解决方案五:
锁定情况下是在不同的桌面,这个不能关闭。
解决方案六:
如果用户手工进入锁定状态就没办法。但是你可以用mouse_event或是sendInput这2个api,或是SendKey方法,发送一些无效的屏幕点击或键盘输入,以阻止系统进入休眠模式,屏幕保护。
解决方案七:
进入屏保后,往往默认都是过一段时间锁定计算机的。
解决方案八:
牛B有没有其他低端方法啊在锁定状态下,我想知道如何手动快捷键操作关机状态的,当然不希望是直接按电源按钮之类,希望有高手指点一下,谢过咯!
解决方案九:
该回复于2012-03-21 20:13:59被版主删除