I have a script that I want to run at startup but that requires elevated priviledges. Is there a way of doing this with Group Policy?
I tried adding it in as a startup script using GPO but it doesn't appear to run. If I run it from a standard cmd prompt then it gives access denied but if I right click the command prompt and select "Run as Administrator" then it works fine so I suspect it is a permission issue.
The script is setting the MTU on each NIC to be 1400 as follows
Dim strDNSDomain
Dim strComputer
Dim strID
Dim strKeyPath
Dim strValueName
Dim strDWValue
Const HKEY_LOCAL_MACHINE = &H80000002
Const DEFAULT_MTU_Size = 1400
const KEY_SET_VALUE = &H0002
'==== Gets the Setting for MTU from the command line in the form of /MTU:1500 ====
Set colNamedArguments = Wscript.Arguments.Named
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
strDWValue = DEFAULT_MTU_SIZE
Set colAdapters = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration")
For each objAdapter in colAdapters
strDNSDomain = objAdapter.DNSDomain
if Instr(1, strDNSDOmain, strTemp) >0 then
strID = objAdapter.SettingID
strKeyPath = "SYSTEM\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\" & strID
strValueName = "MTU"
oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, bHasAccessRight
If bHasAccessRight = True Then
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo strKeyPath & " value " & strValueName & " contains " & dwValue
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strDWValue
WScript.Echo strKeyPath & " value " & strValueName & " changing to " & strDWValue
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo strKeyPath & " value " & strValueName & " changed to " & dwValue
Else
WScript.Echo "Cannot set registry value - access denied"
End if
End if
Next