RebootsaWindows2000PC.ManyexamplesshelltothekernelandjustkillthePC.Thisdoesitproperlyandtakesintoaccountauserprivilages.
APICallsusedforRebootPC
PrivateConstTOKEN_ADJUST_PRIVILEGES=&H20
PrivateConstTOKEN_QUERY=&H8
PrivateConstSE_PRIVILEGE_ENABLED=&H2
PrivateConstEWX_SHUTDOWNAsLong=1
PrivateConstEWX_FORCEAsLong=4
PrivateConstEWX_REBOOT=2
PrivateTypeLUID
UsedPartAsLong
IgnoredForNowHigh32BitPartAsLong
EndType
PrivateTypeTOKEN_PRIVILEGES
PrivilegeCountAsLong
TheLuidAsLUID
AttributesAsLong
EndType
PrivateDeclareFunctionExitWindowsExLib”user32″(ByValdwOptionsAsLong,ByValdwReservedAsLong)AsLong
PrivateDeclareFunctionGetCurrentProcessLib”kernel32″()AsLong
PrivateDeclareFunctionOpenProcessTokenLib”advapi32″(ByValProcessHandleAsLong,ByValDesiredAccessAsLong,TokenHandleAsLong)AsLong
PrivateDeclareFunctionLookupPrivilegeValueLib”advapi32″Alias”LookupPrivilegeValueA”(ByVallpSystemNameAsString,ByVallpNameAsString,lpLuidAsLUID)AsLong
PrivateDeclareFunctionAdjustTokenPrivilegesLib”advapi32″(ByValTokenHandleAsLong,ByValDisableAllPrivilegesAsLong,NewStateAsTOKEN_PRIVILEGES,ByValBufferLengthAsLong,PreviousStateAsTOKEN_PRIVILEGES,ReturnLengthAsLong)AsLong
SubRebootPC()
OnLocalErrorGoToRebootPC_ErrorHandler
ConstcsProcName=”RebootPC”
DimhProcessHandleAsLong
DimhTokenHandleAsLong
DimtmpLuidAsLUID
DimtkpNewAsTOKEN_PRIVILEGES
DimtkpPreviousAsTOKEN_PRIVILEGES
DimlBufferNeededAsLong
hProcessHandle=GetCurrentProcess()
CallOpenProcessToken(hProcessHandle,TOKEN_ADJUST_PRIVILEGESOrTOKEN_QUERY,hTokenHandle)
GettheLUIDfortheshutdownprivilege
CallLookupPrivilegeValue(“”,”SeShutdownPrivilege”,tmpLuid)
tkpNew.PrivilegeCount=1Oneprivilegetoset
tkpNew.TheLuid=tmpLuid
tkpNew.Attributes=SE_PRIVILEGE_ENABLED
Enabletheshutdownprivilegeintheaccesstokenofthisprocess.
lBufferNeeded=0
CallAdjustTokenPrivileges(hTokenHandle,False,tkpNew,Len(tkpPrevious),tkpPrevious,lBufferNeeded)
ForceaReboot(nooptiontosavefilestocancelout)
CallExitWindowsEx(EWX_FORCEOrEWX_REBOOT,&HFFFF)
ExitSub
RebootPC_ErrorHandler:
CallRaiseError(csModName,csProcName,Err.Number,Err.Description)
EndSub->