Error code -9996 when opening Audacity from a batch file

I have set up a simple batch file to open Audacity and other programs but whenever I open it from the batch file this error pops up when I hit the record button. This DOESN’T happen when I open Audacity from the regular desktop shortcut.
I’m using the Windows WASAPI to record sound from the system.
Any thoghts?
These are the details:
{
“timestamp”: 1640183142,
“event_id”: “ab5fb4a3f3a66945b908898b1b033c63”,
“platform”: “native”,
“release”: “audacity@3.1.2”,
“contexts”: {
“os”: {
“type”: “os”,
“name”: “Windows”,
“version”: “10.0.19042”
}
},
“exception”: {
“values”: [
{
“type”: “Error”,
“value”: “Error opening recording device.\nError code: -9996 Invalid device.”,
“mechanism”: {
“type”: “runtime_error”,
“handled”: false
}
}
]
}
}

You may need to give permission for the batch file to access the “microphone”.

I have solved my 9996 error - please see the photo at the link below (if I am allowed to use a link)
It took a few hours BUT all working

Good luck
Ken

Error9996.jpg