Run As Admin Toggle

Discuss and share scripts and script files...
Post Reply
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Run As Admin Toggle

Post by bdeshi »

Toggles the "run as Administrator" compatibility option for selected executables.
RunasAdminToggle.xys
Quite useless in day-to-day browsing, but might be used (with a little tweaking, in other scripts) to temporarily elevate a (helper) program without vbs tmp files etc.
source:

Code: Select all

"ToggleRunAsAdmin : adminrun"
 /* RunAsAdmin toggle//SammaySarkar//Jun-16-2014 11:07:18 PM
 toggles the Run as Admin compatibility option for all exe files in selection. */
 $sel = get("SelectedItemsPathNames", '|'); $a = "HKCU"; $b = '';
 //$b = (%osbitness% == 64)?' /reg:64':'';
 //apply for all users: Run XY as admin, set $a = "HKLM" and if 64bit OS, uncomment the cmd above
 foreach ($itm, $sel, '|'){
 	if ( (exists("$itm") == 1) && (getpathcomponent($itm, ext) == "exe") ){//step;
 		//obtain current compatibility value
 		$currReg = replace(gettoken(runret("%COMSPEC% /c reg.exe query ""$a\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"" /v ""$itm""$b"),-1,"    "),<crlf>);
 		//toggle
 		if (strpos($currReg, "RUNASADMIN") != -1){
 			//if set, negate RUNASADMIN from data
 			$value = replace($currReg, "RUNASADMIN", "");
 			if (replace($value, " ") == ""){
	 			//if negating turns out to empty the data, delete the value and continue to next $itm
 				run "reg.exe delete ""$a\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"" /v ""$itm"" /f$b",, 2, 0;
 				continue;
 			}
 		}
 		else {
	 		//else add RUNASADMIN
 			$value = $currReg." RUNASADMIN";
 	    }
 		run "reg.exe add ""$a\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"" /v ""$itm"" /d ""$value"" /f$b",, 2, 0;
 	}
 }
 status "Done. Check each file's Properties->Compatibility.";
[/size]
Obligatory Note: by design it alters the registry (although toggling back will undo the alteration)
To see the attached files, you need to log into the forum.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply