Run PowerShell as administrator in Excel VBA

2019-09-05 09:15发布

In this link Enable Windows Defender using Powershell I am trying to enable and disable Windows Bitdefender through excel VBA What I reach is that I have to run powershell as administrator .. But how can I do that through VBA itself? This is my try till now

Sub Enable_Disable_Windows_Defender_Using_PowerShell()
Dim wshShell        As Object
Dim wshShellExec    As Object
Dim strCommand      As String

Rem Enable = false - Disable = true

strCommand = "Powershell -nologo -Command ""Start-Process powershell -Verb runAs"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)


strCommand = "Powershell -nologo -WindowStyle Hidden -ExecutionPolicy Bypass -Command ""Set-MpPreference -DisableRealtimeMonitoring $false"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
End Sub

0条回答
登录 后发表回答