I'm trying to run a BAT file from a Macro in excel:
Sub RunBatchFile()
Dim batchPath As String
Dim cmdPath As String
' Set the path to your batch file
batchPath = "C:\cmdb_si_parent.bat"
' Set the path to cmd.exe
cmdPath = "C:\Windows\System32\cmd.exe"
' Run the batch file using the Shell function and cmd.exe with /k parameter
Shell Chr(34) & cmdPath & Chr(34) & " /k " & Chr(34) & batchPath & Chr(34), vbNormalFocus
End Sub
I'm getting Access is denied. I don't know why its saying that because I can perfrectly execute the bat file from my file explorer.. Getting the same message when I replace the bat file to a different folder.
My bat file:
powershell.exe -executionpolicy remotesigned -File "\\domain\runparentcheck.ps1"