本文整理汇总了C#中TOKEN_PRIVILEGES.Size方法的典型用法代码示例。如果您正苦于以下问题:C# TOKEN_PRIVILEGES.Size方法的具体用法?C# TOKEN_PRIVILEGES.Size怎么用?C# TOKEN_PRIVILEGES.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TOKEN_PRIVILEGES
的用法示例。
在下文中一共展示了TOKEN_PRIVILEGES.Size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SystemLocationHandler
//.........这里部分代码省略.........
if (xp) {
for (int i = 1; i < split.Length - 2; i++) {
user_root.Append(Path.DirectorySeparatorChar + split[i]);
}
} else {
for (int i = 1; i < split.Length - 3; i++) {
user_root.Append(Path.DirectorySeparatorChar + split[i]);
}
}
// Global ubisoft save location
DirectoryInfo ubisoft_save = null;
RegistryHandler ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Ubisoft\Launcher", false);
if (!ubi_reg.key_found) {
ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Wow6432Node\Ubisoft\Launcher", false);
}
if (ubi_reg.getValue("InstallDir") != null && Directory.Exists(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames"))) {
uac_enabled = true;
ubisoft_save = new DirectoryInfo(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames"));
} else if (Environment.GetEnvironmentVariable("ProgramW6432") != null && Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher"))) {
ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher", "savegames"));
} else if (Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher"))) {
ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher", "savegames"));
}
if (ubisoft_save != null && ubisoft_save.Exists) {
global.setEvFolder(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save, true);
}
//Per-user variables
loadUsersData("current_user", null);
if (Core.StaticAllUsersMode) {
// All this crap lets me get data from other user's registries
IntPtr token = new IntPtr(0);
int retval = 0;
TOKEN_PRIVILEGES TP = new TOKEN_PRIVILEGES();
TOKEN_PRIVILEGES TP2 = new TOKEN_PRIVILEGES();
LUID RestoreLuid = new LUID();
LUID BackupLuid = new LUID();
int return_length = 0;
TOKEN_PRIVILEGES oldPriveleges = new TOKEN_PRIVILEGES();
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
//IntPtr hndle = GetModuleHandle(null);
//retval = OpenProcessToken(hndle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token);
retval = OpenProcessToken(process.Handle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token);
retval = LookupPrivilegeValue(null, SE_RESTORE_NAME, ref RestoreLuid);
TP.PrivilegeCount = 1;
TP.Privileges.attributes = SE_PRIVILEGE_ENABLED;
TP.Privileges.luid = RestoreLuid;
retval = AdjustTokenPrivileges(token, 0, ref TP, TP.Size(), ref oldPriveleges, ref return_length);
if (retval == 0)
throw new TranslateableException("ProcessRestorePermissionError", retval.ToString());
retval = LookupPrivilegeValue(null, SE_BACKUP_NAME, ref BackupLuid);
TP2.PrivilegeCount = 1;
TP2.Privileges.attributes = SE_PRIVILEGE_ENABLED;
TP2.Privileges.luid = BackupLuid;
retval = AdjustTokenPrivileges(token, 0, ref TP2, TP2.Size(), ref oldPriveleges, ref return_length);
if (retval == 0)
throw new TranslateableException("ProcessBackupPermissionError", retval.ToString());
Console.WriteLine(retval);
foreach (DirectoryInfo user_folder in new DirectoryInfo(user_root.ToString()).GetDirectories()) {
if (user_folder.Name.ToLower() == "default user")
continue;
if (user_folder.Name.ToLower() == "default")
continue;
if (user_folder.Name.ToLower() == "all users")
continue;
string hive_file = Path.Combine(user_folder.FullName, "NTUSER.DAT");
if (!File.Exists(hive_file))
continue;
int h = RegLoadKey(HKEY_USERS, user_folder.Name, hive_file);
//int h = RegLoadAppKey(hive_file,out hKey, RegSAM.AllAccess,REG_PROCESS_APPKEY,0);
if (h == 32)
continue;
if (h != 0)
throw new TranslateableException("UserRegistryLoadError", user_folder.Name, h.ToString());
//sub_key = new RegistryHandler(hKey);
//sub_key = new RegistryHandler(RegRoot.users,user_folder.Name,false);
loadUsersData("users", user_folder.Name);
string result = RegUnLoadKey(HKEY_USERS, user_folder.Name).ToString();
}
}
initialized = true;
}