TeamsStatus
TeamsStatus copied to clipboard
Replace environment variable with specific path
The service runs as LocalService so the $env:APPDATA path is incorrect.
Resolves #33
This PR basically reverts #28?
This PR basically reverts #28?
yes, the change made in #28 means the log file directory is wrong.
This needs to be merged, otherwise the service does not work. I didn't find any other way around, as nssm does not allow to set the user to start the service without asking for its password.
Instead of hardcoding the path, would it be an option to test if the $env:APPDATA
variable returns anything and if not use the hardcoded path instead? That would with both use cases (running as LocalSystem or user)
It should be. I suppose the most difficult part is to actually test what's inside $env:APPDATA when running as a service.
Google lead me here:
https://social.msdn.microsoft.com/Forums/windows/en-US/1889f615-0a88-4c6e-9c19-f93b00846a9d/get-special-folder-on-windows-service-running-as-local-system
One could test against this result. But i don't mind a hardcoded path.
This is what i've come up with.
If ($env:APPDATA -match "C:\\Users") {
$path = "$env:APPDATA\Microsoft\Teams\logs.txt"
}
Else {
$path = "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt"
}
Then use
Get-Content -Path $path