Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Toggle "Run as Administrator" compatibility option from context menu?

09 Aug 2015   #11
arrestme

Windows 7 ultimate x64
 
 

Thanks man, I completely understand. You absolutely still rock! Respect Mr.Miyagi.


My System SpecsSystem Spec
.
15 Sep 2015   #12
arrestme

Windows 7 ultimate x64
 
 

Hello again my favorite Guru. I have a new question about a request pertaining to this thread, so not sure if I should make a new one. I'm only certain you would have the exact answer I'm looking for. If it should be somewhere else or something like that, I'll be happy to do it. Not sure what rules are on posting in already solved threads. But the answer I should've asked you about before would help anyone else coming across this particular thread.

I'm wondering how to make the context menu's "title", of our addition you helped me create, change depending on if it is already active or not. I found that this shortcut was amazing, but if I forgot if I activated it or not, I'd have to go into the properties menu anyway, voiding the saved time.

So right now if I click on an unmodified exe, I can click the "Always Admin" context, which would make it run as admin on all users. Let's say I do that & now it's checked. If I right click again, is there a way to have windows know if it's already been checked? & If it is checked, can it change the context menu to say something like "Always Admin OFF"? This way in the process of wanting to activate "Always Admin" I can see if I've already done it before or not with assurance.

Sorry to bother you again with this, but it has been a huge difference in menial tasks. I'm just not exactly sure how to alter this set-up to make that slight change. The script you provided is already set up to run a check on if the All User Run as Admin is checked, & then will uncheck it if I run it again on the same exe. But it would be so nice if the text I'm clicking could somehow indicate if it's already checked or not by a change of text. Hope I was explicit enough in describing. You seemed to have very good tact in dealing with broad descriptions by people who don't know these technical coding languages.

Thanks again if you're still around. If you've moved on & somebody else is now in charge of reading this, I implore you to help as well. If you can fill Pyprohly here's shoes. ^_^
My System SpecsSystem Spec
18 Sep 2015   #13
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Hi again Arrestme,

I'm still alive and healthy. And I'm glad you are still finding the content here useful.

I understand exactly what you're asking for, but unfortunately there isn't such a thing as having a dynamic title for a content menu entry. Though what you describe would be highly convienient, there are two barriers from one being able to achieve this: firstly, the sole job of a context menu item is to trigger something (in this case a script), and it makes no calculations. The script is the thing that determines whether the Run as Admin setting is actually enabled or not and carries out the according action. Because context menu items aren't able to make calculations, if one wanted a context menu entry with a dynamic title then some sort of program or script must run each time the user right-clicks and then quickly change a registry value. I'm doubtful Windows will allow this. Secondly, modifying, adding or deleting a context menu item requires administrative permissions, thus if the title of a context menu were to change, the user would have to accept UAC each time.

So it's not possible to have the title of "Run always as Admin" change according to whether the Run as Admin capatibility setting is enabled or not; you can only change the behaviour of the script.

What you could do is modify the script to ask you if you want to toggle the setting, it'll indicate whether or not the program is currently set to Run as Admin through a popup box. Pressing enter to this popup will change the program's Run as Admin state. Waiting 1.5 seconds will cause the box to disappear with no action being taken.

Is this a practical idea? Try it out, Arrestme, and tell me what you think.


ToggleRunAsAdmin_2.vbs
Code:
' ToggleRunAsAdmin_2.vbs ExeFile
' Toggle the "Run this program as an administrator" compatibility setting on 'ExeFile'.

Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("WinMgmts:\\.\root\default:StdRegProv")

Function PromptForElevation(Args)
	If Not WshShell.Run("Net Sess", 0, True) = 0 Then
		CreateObject("Shell.Application").ShellExecute "WScript", _
				"""" & WScript.ScriptFullName & """" & " " & """" & WScript.Arguments.Item(0) & """" & " " & Args, "","RunAs",1
		WScript.Quit
	End If
End Function

Function EnableRunAsAdmin(hDefKey, strSubKey, strValue, strData)
	objReg.SetStringValue hDefKey, strSubKey, strValue, strData
End Function

Function DisableRunAsAdmin(hDefKey, strSubKey, strValue, strData)
	If reLetters.Test( Replace(ExistingData, strData, "") ) Then
		If reRunAsAdmin.Test( ExistingData ) Then
			objReg.SetStringValue hDefKey, strSubKey, strValue, reRunAsAdmin.Replace(ExistingData, "")
		Else
			objReg.SetStringValue hDefKey, strSubKey, strValue, ExistingData & " " & strData
		End If
	Else
		objReg.DeleteValue hDefKey, strSubKey, strValue
	End If
End Function

If WScript.Arguments.Unnamed.Count = 0 Then WScript.Quit 1
If WScript.Arguments.Item(0) = "" Then WScript.Quit 1

Const StopIcon		  = 16
Const QuestionIcon	  = 32
Const ExclamationIcon = 48
Const InformationIcon = 64

Const YesNoCancelButtons = 3
Const YesNoButtons		 = 4

sngWaitSeconds = 1.5

Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE

hDefKey	  = HKCU 'Use HKCU (toggle setting for current user only) or HKLM (toggle setting for all users)
strSubKey = "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
strValue  = WScript.Arguments.Item(0)
strData	  = "RUNASADMIN"

strRunOnceKey = "Software\Microsoft\Windows\CurrentVersion\RunOnce"

Set reLetters = New RegExp
reLetters.Pattern = "[a-z]"
reLetters.IgnoreCase = True
reLetters.Global = True

Set reRunAsAdmin = New RegExp
reRunAsAdmin.Pattern = " *RUNASADMIN *"
reRunAsAdmin.IgnoreCase = True
reRunAsAdmin.Global = True

If WScript.Arguments.Named.Exists("enable") Then
	EnableRunAsAdmin hDefKey, strSubKey, strValue, strData
	objReg.SetStringValue HKCU, strSubKey, strValue, strData
	If Not objReg.EnumKey(HKCU, strRunOnceKey) = 0 Then
		objReg.CreateKey HKCU, strRunOnceKey
	End If
	Randomize
	strRegDelCmd = "reg delete " & """HKCU\" & strSubKey & """ /v """ & strValue & """ /f"
	objReg.SetStringValue HKCU, strRunOnceKey, fso.GetFileName(WScript.ScriptFullName) & "_" & Int(Rnd * 1000000), strRegDelCmd
	WScript.Quit 0
ElseIf WScript.Arguments.Named.Exists("disable") Then
	DisableRunAsAdmin hDefKey, strSubKey, strValue, strData
	objReg.DeleteValue HKCU, strSubKey, strValue
	WScript.Quit 0
End If

objReg.GetStringValue hDefKey, strSubKey, strValue, ExistingData

If IsNull(ExistingData) Then
	intSelection = WshShell.Popup("Enable run as administrator compatibility setting?", sngWaitSeconds, "Run as Administrator is Disabled", InformationIcon + YesNoCancelButtons)
	If intSelection = 6 Then
		If hDefKey = HKLM Then
			PromptForElevation("/enable")
		Else
			EnableRunAsAdmin hDefKey, strSubKey, strValue, strData
		End If
	End If
	WScript.Quit 0
Else
	intSelection = WshShell.Popup("Disable run as administrator compatibility setting?", sngWaitSeconds, "Run as Administrator is Enabled", ExclamationIcon + YesNoCancelButtons)
	Select Case intSelection
		Case 6
			If hDefKey = HKLM Then
				PromptForElevation("/disable")
			Else
				DisableRunAsAdmin hDefKey, strSubKey, strValue, strData
			End If
		Case Else
			WScript.Quit 0
	End Select
End If
I've also made a few reliablity improvements to the above script since the previous one.
My System SpecsSystem Spec
.

27 Sep 2015   #14
arrestme

Windows 7 ultimate x64
 
 

Such a smart person this guy. It's awe inspiring every time! Allow me to prepare a response & I apologize for taking so long. I didn't have as much time as I'd hoped to get back to you, so once again thank you for replying with this in almost record time & forgive me lateness in reply. I also wanted to go through your script & mess around with it some-what.

I'll try & hash it out quickly as it seems to be only 1 issue probably due to my quagmire of requests on this shortcut thing, taking time from what I assume is your seriously busy posting schedule here.

So I really like the box pop-ups, tho I'm not sure if I can accurately appreciate the upgrades you've made to the script. Tho I did see the comparison with the old one using "text different with this file..." in PSPad, I'm simply just not sure if I'm trained enough to recognize & understand all of the cool differences you author here for us. But I'm super grateful ya did it again none-the-less. That should be your slogan (fixed it again)!

But ok this 1 problem I'm sure you'll recognize straight away is that running the script thru context menu of a right clicked unmodified .exe, obviously shows the beautiful notice with a title on top showing "Run as Admin is Disabled (& will actually change to enabled if enabled)" including 3 options for us to use after going from there: Yes No & Cancel. Beautiful, really I love it.

But maybe it's me being a stickler but since *I have the "All Users" "Run as Admin" box getting checked from the previous script, if I run this new script on an already-modified-exe that has All Users Run-as-Admin activated, the new script will show up as "Run as Admin is disabled", making clicking yes or no or cancel all doing nothing, unable to check/uncheck the normal RAAdmin since setting the option for the All-Users tab, greys out the old "normal" one.

So, again I'm gonna be a super burden & ask if you can do something like what I have had for "hide/unhide hidden system files" context menu shortcut option. I had the same problem with where I couldn't have the context menu show the status of the options i wanted to toggle in it's name alone, so at the end of the script running, a pop-up notification like you have but a bit different would come up:

Code:
If dblHiddenData = 0 Then
	WshShell.RegWrite strSuperHiddenKey, 1, "REG_DWORD"
	WScript.Echo "Now SHOWING protected system files."

Else
	WshShell.RegWrite strSuperHiddenKey, 0, "REG_DWORD"
	WScript.Echo "Now HIDING protected system files."
I don't know if I'm pandering too much, but *if you could change the script to skip UAC's while enabling the All Users RAA with 1 option pop-up, I'd be once again amazed & indebted to your suave and powerful brain.

I was wondering if the script being able to do that all with the All-Users option of RAA was not too much of a bother, if you could make the pop-up with a simple "OK" button for all incidents & the inside-box description with an announcement of if it activated it or not. With what you made possible with your script update, & because of it I'd then know both status of 1.)if it was already activated/deactivated before clicking & 2.) if I had just activated/deactivated it. Then I could go from there. Which gives me another idea!
I'm pushing harder here, but i'm hoping it turns into something maybe you yourself might even use!
But now that I think of it ..if you've gotten this far, is it possible to have 1 pop-up box after clicking "always admin", no matter whether the script is checking or unchecking the RAA box? With just a few exception: The pop-up comes after script as already done it's work instead of before, & it's contents of having your "Run as Admin is now Disabled[or Enabled]!" at the top perfectly like you made it, but with the words below that (yet above the buttons) instead of having, "Enable[or disable] run as admin comp setting?" with options "Yes, No, & Cancel", instead can it say "Continue or REVERSE changes?" with options in 2 boxes of "OK" or "Reverse"?.


So the script does all the work before notifying you with the options. Then you can choose OK to move on if you're happy with the outcome, or "REVERSE" button that will turn back the action it just made. Is something like that possible? Would I need another script for the reverse? Is this too much of a headache? Or will we possibly make the best script ever in the history of Windows 7?

*Does running it as admin for All Users or not make any difference at all even if I'm the only user on the PC? I only am specifying toward the all-user run-as-admin box because I'm thinking it must cover all my bases. Or, for my purposes, would I not ever come across needing that specifically checked over the other "normal" run-as-admin properties box being checked? If there really is no difference, than no need to make any harrowing code tricks just to get the "ALL USER" version to check on/off. If so, & if it'd save you time, the other would be just fine.
My System SpecsSystem Spec
27 Sep 2015   #15
arrestme

Windows 7 ultimate x64
 
 

Sorry for my buttery way of spreading my questions & explanation all over the place; but here I wanted to point out PyProhly's adroitness & accuracy for knowing exactly where I'm coming from & superb in every respect through every response. I only continue to add to this thread for my own selfish reasons, & not due to any problem with his (or her?) advice. This is 1 smart person & very glad to have worked with him on this. Cuz this is probably the last request of mine. It's been real!
My System SpecsSystem Spec
01 Oct 2015   #16
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

My turn for an apologetic sentence regarding my response time. I had a few issues with making the script work with your specifications and in a feasible manner. But I did manage make much improvements to the behaviour of the RAA All Users setting.

Quote   Quote: Originally Posted by arrestme View Post
But maybe it's me being a stickler but since *I have the "All Users" "Run as Admin" box getting checked from the previous script, if I run this new script on an already-modified-exe that has All Users Run-as-Admin activated, the new script will show up as "Run as Admin is disabled", making clicking yes or no or cancel all doing nothing, unable to check/uncheck the normal RAAdmin since setting the option for the All-Users tab, greys out the old "normal" one.
It's because you've had the other script in HKLM mode, which set the Run as Admin flag for All Users. Conversely, when you acquired the new script, by default, it is set to write the HKCU hive, which alters RAA on the exe file for the Current User only. If the script is set to change, say, the RAA flag for the Current User, it will not check if the flag is already set for All Users, causing the script to insist that Run as Admin is disabled when it is in fact enabled but for All Users instead.

The vice versa could happen, so make sure you have configured the script to change the correct Run as Admin setting you want (either HKCU, for the current user; or HKLM, for all users).

Quote   Quote: Originally Posted by arrestme View Post
I don't know if I'm pandering too much, but *if you could change the script to skip UAC's while enabling the All Users RAA [...]
If enabling RAA for all users (i.e., editing a value in the HKLM hive), there will have to be some UAC dialogue somewhere (unless changing some permissions around in the HKLM hive is an option for you). Perhaps the UAC dialogue itself could be the indicator for whether a program is currently running-as-administrator-for-all-users or not. There's no easy way around UAC. We're going to have to work with it somehow.

Quote   Quote: Originally Posted by arrestme View Post
I'm pushing harder here, but i'm hoping it turns into something maybe you yourself might even use!
But now that I think of it ..if you've gotten this far, is it possible to have 1 pop-up box after clicking "always admin", no matter whether the script is checking or unchecking the RAA box? With just a few exception: The pop-up comes after script as already done it's work instead of before, & it's contents of having your "Run as Admin is now Disabled[or Enabled]!" at the top perfectly like you made it, but with the words below that (yet above the buttons) instead of having, "Enable[or disable] run as admin comp setting?" with options "Yes, No, & Cancel", instead can it say "Continue or REVERSE changes?" with options in 2 boxes of "OK" or "Reverse"?.
Just a single popup indicator at the end, I guess, would speed the whole task up. But while what you describe could work for the Current User RAA setting, for All Users, it won't be so consistent. I'm not sure how this method would work out with the UAC dialogue in the way; there's just too many prompts.

Also, unfortunately the buttons on those boxes are predefined and are not customisable. All seven button layout types are documented here. And below is a demonstration of all the possible button layouts.
Code:
Set WshShell = CreateObject("WScript.Shell")

intSecondsWait = 8
strText = "Example text. Hello World."

For I = 0 To 6
	WshShell.Popup strText, intSeconds, "Popup no." & I + 1 & " of 7", I
Next
Quote   Quote: Originally Posted by arrestme View Post
*Does running it as admin for All Users or not make any difference at all even if I'm the only user on the PC? I only am specifying toward the all-user run-as-admin box because I'm thinking it must cover all my bases. Or, for my purposes, would I not ever come across needing that specifically checked over the other "normal" run-as-admin properties box being checked? If there really is no difference, than no need to make any harrowing code tricks just to get the "ALL USER" version to check on/off. If so, & if it'd save you time, the other would be just fine.
You might have noticed, I am performing some ‘harrowing code trick’ just to get the All Users RAA option to work properly: I noticed that when configuring RAA for All Users programmatically (editing the registry directly), RAA wasn’t taking immediate effect. Have you noticed this when using the previous script in All Users mode?

So what I did, when setting RAA for All Users, it would also enable RAA for the Current User. The script would then make a RunOnce registry entry that removes the RAA option for the Current User next logon. RunOnce entries hold command lines that execute when the user logs in. Unfortunately, this method, which uses the Reg command, actually triggers a Command Prompt to flash briefly when logging in. I’ve now abandoned this RunOnce trick, in favour of a less fiddly method: taking advantage of the Startup folder to remove the RAA for the Current User.


Here's an update to the script. Popups happen after the doing has been done, but only for Current User RAA. You may modify the script to see what popups are like when they appear after the processing has been done for RAA All Users, but I warn, popups coming after in this setting don't look really pretty, so I've kept the popups here happening before. I'm just worried this inconsistency will take a hit on the script's intuitiveness.


ToggleRunAsAdmin_3.vbs
Code:
' ToggleRunAsAdmin_3.vbs ExeFile
' Toggles the "Run this program as an administrator" compatibility setting on 'ExeFile'.

Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objReg = GetObject("WinMgmts:\\.\root\default:StdRegProv")

Function EnableRunAsAdmin(hDefKey, strSubKey, strValue, strData)
	objReg.SetStringValue hDefKey, strSubKey, strValue, strData
End Function

Function DisableRunAsAdmin(hDefKey, strSubKey, strValue, strData, ExistingData)
	If reLetters.Test( Replace(ExistingData, strData, "") ) Then
		If reRunAsAdmin.Test( ExistingData ) Then
			objReg.SetStringValue hDefKey, strSubKey, strValue, reRunAsAdmin.Replace(ExistingData, "")
		Else
			objReg.SetStringValue hDefKey, strSubKey, strValue, ExistingData & " " & strData
		End If
	Else
		objReg.DeleteValue hDefKey, strSubKey, strValue
	End If
End Function

Function DisblRaaScriptTemplateText()
	DisblRaaScriptTemplateText = "Const HKCU = &H80000001" & vbCrLf &_
		"Const HKLM = &H80000002" & vbCrLf & vbCrLf &_
		"Set objReg = GetObject(""WinMgmts:\\.\root\default:StdRegProv"")" & vbCrLf & vbCrLf &_
		"Set reLetters = New RegExp" & vbCrLf &_
		"reLetters.Pattern = ""[a-z]""" & vbCrLf &_
		"reLetters.IgnoreCase = True" & vbCrLf &_
		"reLetters.Global = True" & vbCrLf & vbCrLf &_
		"Set reRunAsAdmin = New RegExp" & vbCrLf &_
		"reRunAsAdmin.Pattern = "" *RUNASADMIN *""" & vbCrLf &_
		"reRunAsAdmin.IgnoreCase = True" & vbCrLf &_
		"reRunAsAdmin.Global = True" & vbCrLf & vbCrLf &_
		"Function DisableRunAsAdmin(hDefKey, strSubKey, strValue, strData, ExistingData)" & vbCrLf &_
		"	If reLetters.Test( Replace(ExistingData, strData, """") ) Then" & vbCrLf &_
		"		If reRunAsAdmin.Test( ExistingData ) Then" & vbCrLf &_
		"			objReg.SetStringValue hDefKey, strSubKey, strValue, reRunAsAdmin.Replace(ExistingData, """")" & vbCrLf &_
		"		Else" & vbCrLf &_
		"			objReg.SetStringValue hDefKey, strSubKey, strValue, ExistingData & "" "" & strData" & vbCrLf &_
		"		End If" & vbCrLf &_
		"	Else" & vbCrLf &_
		"		objReg.DeleteValue hDefKey, strSubKey, strValue" & vbCrLf &_
		"	End If" & vbCrLf &_
		"End Function" & vbCrLf & vbCrLf
End Function

If WScript.Arguments.Unnamed.Count = 0 Then WScript.Quit 1
If WScript.Arguments.Item(0) = "" Then WScript.Quit 1

Const StopIcon     = 16
Const QuestionIcon = 32
Const ExclamationIcon = 48
Const InformationIcon = 64

Const YesNoCancelButtons = 3
Const YesNoButtons		 = 4

dblWaitSeconds = -1.0 'Seconds popup boxes should wait before defaulting to 'no'. Specify negative number for infinite time. 

Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE

hDefKey	  = HKCU 'Use HKCU (for current user only) or HKLM (for all users)
strSubKey = "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
strValue  = WScript.Arguments.Item(0)
strData	  = "RUNASADMIN"

strStartupFolder = WshShell.ExpandEnvironmentStrings("%AppData%\Microsoft\Windows\Start Menu\Programs\Startup")

strRandomScriptFileName = fso.GetBaseName(WScript.ScriptFullName) & "_" & fso.GetTempName() & "_" & ".vbs"
strRandomScriptFile     = WshShell.ExpandEnvironmentStrings("%Temp%\" & strRandomScriptFileName)

Set reLetters = New RegExp
reLetters.Pattern    = "[a-z]"
reLetters.IgnoreCase = True
reLetters.Global     = True

Set reRunAsAdmin = New RegExp
reRunAsAdmin.Pattern    = " *RUNASADMIN *"
reRunAsAdmin.IgnoreCase = True
reRunAsAdmin.Global     = True

objReg.GetStringValue hDefKey, strSubKey, strValue, ExistingData
If IsNull(ExistingData) Then
	If hDefKey = HKLM Then
		intSelection = WshShell.Popup("The Run as Administrator compatibility setting for this executable is currently disabled." & vbCrLf & vbCrLf & "Would you like to enable this setting?", sngWaitSeconds, "Run as Administrator is Currently Disabled", QuestionIcon + YesNoButtons)
		
		Function EnableRaaHklm()
			Set fsoTextFile = fso.CreateTextFile(strRandomScriptFile)
			fsoTextFile.Write "Const HKCU = &H80000001" & vbCrLf
			fsoTextFile.Write "Const HKLM = &H80000002" & vbCrLf & vbCrLf
			fsoTextFile.Write "Set objReg = GetObject(""WinMgmts:\\.\root\default:StdRegProv"")" & vbCrLf & vbCrLf
			fsoTextFile.Write "objReg.SetStringValue HKCU, """ & strSubKey & """, """ & strValue & """, """ & strData & """" & vbCrLf
			fsoTextFile.Write "objReg.SetStringValue HKLM, """ & strSubKey & """, """ & strValue & """, """ & strData & """"
			fsoTextFile.Close
			WScript.Sleep 120
			CreateObject("Shell.Application").ShellExecute "WScript", strRandomScriptFile, "", "RunAs", 1
			WScript.Sleep 120
			fso.DeleteFile strRandomScriptFile
			
			objReg.GetStringValue HKLM, strSubKey, strValue, ExistingData
			If IsNull(ExistingData) = False Then
			Set fsoTextFile = fso.CreateTextFile(strStartupFolder & "\" & strRandomScriptFileName)
				fsoTextFile.Write DisblRaaScriptTemplateText()
				fsoTextFile.Write "DisableRunAsAdmin HKCU, """ & strSubKey & """, """ & strValue & """, """ & strData & """, """ & ExistingData & """" & vbCrLf
				fsoTextFile.Write "CreateObject(""Scripting.FileSystemObject"").DeleteFile WScript.ScriptFullName"
				fsoTextFile.Close
			End If
		End Function
		If intSelection = 6 Then EnableRaaHklm()
	Else
		EnableRunAsAdmin HKCU, strSubKey, strValue, strData

		intSelection = WshShell.Popup("This executable's Run as Administrator compatibility setting for the current user is now ENABLED." & vbCrLf & vbCrLf & "Would you like to disable this setting?", sngWaitSeconds, "Run as Administrator is now ENABLED", QuestionIcon + YesNoButtons)
		If intSelection = 6 Then DisableRunAsAdmin HKCU, strSubKey, strValue, strData, ExistingData
	End If
Else
	If hDefKey = HKLM Then
		intSelection = WshShell.Popup("The Run as Administrator compatibility setting for this executable is currently enabled." & vbCrLf & vbCrLf & "Would you like to disable this setting?", sngWaitSeconds, "Run as Administrator is Currently Enabled", ExclamationIcon + YesNoButtons)
		
		Function DisableRaaHklm()
			Set fsoTextFile = fso.CreateTextFile(strRandomScriptFile)
			fsoTextFile.Write DisblRaaScriptTemplateText()
			fsoTextFile.Write "DisableRunAsAdmin HKCU, """ & strSubKey & """, """ & strValue & """, """ & strData & """, """ & ExistingData & """" & vbCrLf
			fsoTextFile.Write "DisableRunAsAdmin HKLM, """ & strSubKey & """, """ & strValue & """, """ & strData & """, """ & ExistingData & """" & vbCrLf
			fsoTextFile.Close
			WScript.Sleep 120
			CreateObject("Shell.Application").ShellExecute "WScript", strRandomScriptFile, "", "RunAs", 1
			WScript.Sleep 120
			fso.DeleteFile strRandomScriptFile
			
			objReg.GetStringValue HKLM, strSubKey, strValue, ExistingData
			If IsNull(ExistingData) = True Then
				Set reRandomScriptFile = New RegExp
				reRandomScriptFile.Pattern = fso.GetBaseName(WScript.ScriptFullName) & "_rad.....\.tmp_\.vbs"
				reRandomScriptFile.IgnoreCase = True
				reRandomScriptFile.Global = True
				For Each File In fso.GetFolder(strStartupFolder).Files
					If reRandomScriptFile.Test(File.Name) Then
							fso.DeleteFile File.Path
					End If
				Next
			End If
		End Function
		
		If intSelection = 6 Then DisableRaaHklm()
	Else
		DisableRunAsAdmin HKCU, strSubKey, strValue, strData, ExistingData
		
		intSelection = WshShell.Popup("This executable's Run as Administrator compatibility setting for the current user is now DISABLED." & vbCrLf & vbCrLf & "Would you like to enable this setting?", sngWaitSeconds, "Run as Administrator is now DISABLED", ExclamationIcon + YesNoButtons)
		If intSelection = 6 Then EnableRunAsAdmin HKCU, strSubKey, strValue, strData
	End If
End If
My System SpecsSystem Spec
14 Oct 2015   #17
arrestme

Windows 7 ultimate x64
 
 
Great Scot! You've done it again!

You've outdone yourself this time sir! It's perfreakin-perfect. Not that I don't admire your "harrowing coding", because I definitely do, for the RAA for all users, that was quite amazing. Especially giving me the tip to avoid UAC if I so chose by editing the registry permissions. BUT, your current version works so good, & well enough I'm just going to use it for the current user. I came to the conclusion that it shouldn't really matter, right? I'm the only user, I just wanted to be safe, in case some program wanted to run as something else besides my current User, which should probably never happen. I feel bad now though that I'm using it only for current user. Though you'll probably tell me I shouldn't, tho I do cuz this definitely helped me a ton & I learned a lot! The only thing I went in and changed in the script were the words "enable/disable" at the end with the question mark, because it could possibly confuse me if i were in a hurry & changed it to "reverse" so I'd be extra sure about the first sentence & since like you tought me, only certain button text is available. I hope that didn't mess anything up. Going into the script I do see your handy work & it is, again, quite amazing. You deserve way more reputation & thank points than what you got for this thread, & believe me I tried giving it to ya.

Quote:
You might have noticed, I am performing some ‘harrowing code trick’ just to get the All Users RAA option to work properly: I noticed that when configuring RAA for All Users programmatically (editing the registry directly), RAA wasn’t taking immediate effect. Have you noticed this when using the previous script in All Users mode?
I did not notice this. I actually had left it the way it was with your last post until just visiting again because I was pretty sure you'd be a perfectionist & low and be hold, it is god-damned perfect. If at one point in the far future when my hard drive dies & this is all lost, I really believe there's a script heaven where this will go & live a happy eternity, because that's the least it deserves! lol
If you're talking about the script before that one, than I had not noticed it, it always worked instantly as far as I knew.

I kid you not when I say, this is a dream come true & perfection. I'm surprised how well you understood what I was asking for & even with my babbling you saw where I was coming from & took the time to make my request a reality. On top of all that being beyond patient with my late responses. You on the other hand were perfectly on top in response. So thanks again!!

^____________________________________________^
My System SpecsSystem Spec
Reply

 Toggle "Run as Administrator" compatibility option from context menu?




Thread Tools Search this Thread
Search this Thread:

Advanced Search



Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 23:39.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App