數十說:basically, no, what you're asking isn't possible.然而,存在其中回答與高可能性問題雖然還有非零假響應的概率一種解決方法。這裏有這樣的解決方案的草案,請參見下面的腳本:
- 如果升高已經那麼答案是100%:UAC提示不需要。
- 否則,算上升高
wscript.exe
之前的UAC提示和後:
- 如果計數器再搭配UAC提示是可能拒絕;
- 如果計數器不同,則UAC提示是可能是批准。
以上如果高架wscript.exe
以異步方式啓動或在此期間完成...例如,從RDP
會話或任務計劃程序等
option explicit
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName
Dim objShell, svcCounter, preCounter, postCounter
Set objShell = CreateObject("Shell.Application")
svcCounter = 0
preCounter = 0
postCounter = 0
Call TestProcess ("SVC", svcCounter, "svchost.exe")
strResult = strResult & vbNewLine & Cstr(svcCounter)
If svcCounter = 0 Then
'' elevated already
strResult = strResult & vbNewLine & "UAC prompt not required"
objShell.ShellExecute "wscript.exe" _
, """" & "D:\VB_scripts\SO\37911301.vbs" & """ uac" , "", "runas", 1
Else
preCounter = 0
Call TestProcess ("pre", preCounter, "wscript.exe")
' By default, Windows Vista/7/8's UAC prompt is shown on a _secure desktop_
' suspending calling process temporarily:
objShell.ShellExecute "wscript.exe" _
, """" & "D:\VB_scripts\SO\37911301.vbs" & """ uac" , "", "runas", 1
Call TestProcess ("post", postCounter, "wscript.exe")
strResult = strResult & vbNewLine & Cstr(preCounter) & vbTab & Cstr(postCounter)
If preCounter = postCounter Then
strResult = strResult & vbNewLine & "UAC prompt PROBABLY refused"
Else
strResult = strResult & vbNewLine & "UAC prompt PROBABLY approved"
End If
End If
Wscript.Echo strResult
Wscript.Quit
Sub TestProcess(byVal sStage, byRef nCounter, byVal strCap)
strResult = strResult & vbNewLine & sStage
Dim strQuery, objWMIService, colItems, objItem, sCaption, sCmdLine
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strQuery = "SELECT * FROM Win32_Process WHERE Caption = '" & strCap & "'"
Set objWMIService = GetObject("winmgmts:\\" & "." & "\ROOT\CIMV2")
Set colItems = objWMIService.ExecQuery(strQuery _
, "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
sCaption = objItem.Caption
sCmdLine = objItem.CommandLine
if VarType(sCmdLine) = 1 Then nCounter = nCounter + 1 'Null => elevated
strResult = strResult & vbNewLine & sCaption
strResult = strResult & vbTab & objItem.ProcessId
strResult = strResult & vbTab & sCmdLine
'strResult = strResult & vbTab & VarType(sCmdLine) & vbTab & TypeName(sCmdLine)
Next
End Sub
注意方法可能會失敗,那所有與strResult
相關的垃圾僅用於調試目的。而且......我知道是用於測試TestProcess
呼叫如果升高已經是對蚊子太重炮......
也許並不完全是重複的,但是這似乎高度相關:http://stackoverflow.com/q/ 27222097/4996248 –
我必須忍受PEBKAC,因爲我看不到他的實際答案。他只是貼了一個手冊部分,但沒有回答OP的問題......實際上。 – CDoc
也許它沒有幫助,但接受的答案似乎可能會給你一些想法。如果不是,希望別人能給你一個更好的答案。 –