Archives

Monthly Archive for: ‘April, 2012’
UAC with VBscript

You know this? Like to run an VBscript with elevated rights but the User Account Control (UAC) is preventing it. Normally you will open the Command Line as Administrator, and run your script. There is an more easy way to do this.

When you include the following code in your VBscript:

Option Explicit

' Windows UAC Settings for this script
Dim UAC
UAC=True

'this is at the start of your script
CheckStartModeUAC

' msgbox or your own program :)
Msgbox "UAC right now!"

Sub CheckStartModeUAC
	' Force to start with elevated prompt if neccessary on that OS
	If UACTurnedOn = True And UAC=True Then
		' UAC Enabled
	
		' Returns the running executable as upper case from the last \ symbol
		Dim strStartExe, oSh, completearguments, x
		
		' Receive launcher
		strStartExe = UCase( Mid( wscript.fullname, instrRev(wscript.fullname, "\") + 1 ) )
		
		' Collect arguments
		for x = 0 to wscript.arguments.count - 1
			completearguments = completearguments & " """ & wscript.arguments(x) & """"
		next
		
		If Instr(completearguments, "uac") then
			' Already launched with uac
		Else
			' Launch this script in UAC mode
			completearguments = completearguments & " uac"
			'Msgbox strStartExe & " """ & wscript.scriptfullname & """ " & completearguments
			
			set oSh = CreateObject("Shell.Application")
			
			oSh.ShellExecute strStartExe, """" & wscript.scriptfullname & """ " & completearguments, "", "runas", 1
			'oSh.ShellExecute strStartExe, wscript.scriptfullname & " " & completearguments, "runas", 1
			wscript.quit
		End if
	End If	
End Sub

Function UACTurnedOn ()
	' Check for UAC enabled computer
	 On Error Resume Next
	 
	 Dim oShell

	 Set oShell = CreateObject("WScript.Shell")
	 If oShell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA") = 0 Then
		  UACTurnedOn = false
	 Else
		  UACTurnedOn = true
	 End If
End Function

You will get the popupbox when you double-click on the script. Maybe you have to change your script a little bit, but it is still nice :)

Smartcards & AppV

To work with Smartcards from your AppV you need Local Interaction Allowed set to true. Normally it is not possible for an application in the bubble to communicate with the hardware connected to the system.

Edit your OSD(s) for the application, and past the following code between the brackets if that already exists.

<SOFTPKG>
<IMPLEMENTATION>
<VIRTUALENV>
<POLICIES>
<LOCAL_INTERACTION_ALLOWED>TRUE</LOCAL_INTERACTION_ALLOWED>
</POLICIES>
</VIRTUALENV>
</IMPLEMENTATION>
</SOFTPKG>

After this test your application, and make sure it works fine.

UAC with AppV

You like to have the UAC in your AppV application?

UAC Windows 7

That is possible. Enter the following text in the OSD file:

<ENVLIST>
<ENVIRONMENT VARIABLE="__COMPAT_LAYER">RunAsInvoker</ENVIRONMENT>
</ENVLIST>

Enjoy!

It is also possible to use SET __COMPAT_LAYER in a Command Prompt an set the RunAsInvoker variable.

12