#include "precomp.h" #pragma hdrstop // // x86 version (that deals with boot.ini) // is in i386 directory. This is the arc version, that // deals with nv-ram. // #ifndef _X86_ typedef enum { BootVarSystemPartition, BootVarOsLoader, BootVarOsLoadPartition, BootVarOsLoadFilename, BootVarOsLoadOptions, BootVarLoadIdentifier, BootVarMax } BOOT_VARS; PWSTR BootVarNames[BootVarMax] = { L"SYSTEMPARTITION", L"OSLOADER", L"OSLOADPARTITION", L"OSLOADFILENAME", L"OSLOADOPTIONS", L"LOADIDENTIFIER" }; DWORD BootVarComponentCount[BootVarMax]; PWSTR *BootVarComponents[BootVarMax]; DWORD LargestComponentCount; #define MAX_COMPONENTS 20 BOOL SetNvRamVar( IN PWSTR VarName, IN PWSTR VarValue ) { UNICODE_STRING VarNameU,VarValueU; NTSTATUS Status; BOOLEAN OldPriv,DontCare; // // Set up unicode strings. // RtlInitUnicodeString(&VarNameU ,VarName ); RtlInitUnicodeString(&VarValueU,VarValue); // // Make sure we have privilege to set nv-ram vars. // Note: ignore return value; if this fails then we'll catch // any problems when we actually try to set the var. // RtlAdjustPrivilege( SE_SYSTEM_ENVIRONMENT_PRIVILEGE, TRUE, FALSE, &OldPriv ); Status = NtSetSystemEnvironmentValue(&VarNameU,&VarValueU); // // Restore old privilege level. // RtlAdjustPrivilege( SE_SYSTEM_ENVIRONMENT_PRIVILEGE, OldPriv, FALSE, &DontCare ); return(NT_SUCCESS(Status)); } BOOL FChangeBootIniTimeout( IN INT Timeout ) { WCHAR TimeoutValue[24]; // // Form the timeout value. // wsprintfW(TimeoutValue,L"%u",Timeout); // // Set the vars // if(!SetNvRamVar(L"COUNTDOWN",TimeoutValue)) { return(FALSE); } return(SetNvRamVar(L"AUTOLOAD",L"YES")); } BOOL GetVarComponents( IN PWSTR VarValue, OUT PWSTR **Components, OUT PDWORD ComponentCount ) { PWSTR *components; DWORD componentCount; PWSTR p; PWSTR Var; PWSTR comp; DWORD len; components = SAlloc(MAX_COMPONENTS * sizeof(PWSTR)); if(!components) { return(FALSE); } for(Var=VarValue,componentCount=0; *Var; ) { // // Skip leading spaces. // while(iswspace(*Var)) { Var++; } if(*Var == 0) { break; } p = Var; while(*p && (*p != L';')) { p++; } len = (DWORD)((PUCHAR)p - (PUCHAR)Var); comp = SAlloc(len + sizeof(WCHAR)); if(!comp) { DWORD i; for(i=0; i LargestComponentCount) { LargestComponentCount = BootVarComponentCount[var]; } } b = DoRemoveWinntBootSet(); // // Restore previous privilege. // RtlAdjustPrivilege( SE_SYSTEM_ENVIRONMENT_PRIVILEGE, OldPriv, FALSE, &DontCare ); return(b); } #endif