TeamsStatus icon indicating copy to clipboard operation
TeamsStatus copied to clipboard

Replace environment variable with specific path

Open bmdixon opened this issue 3 years ago • 7 comments

The service runs as LocalService so the $env:APPDATA path is incorrect.

Resolves #33

bmdixon avatar May 14 '21 15:05 bmdixon

This PR basically reverts #28?

metbril avatar Dec 05 '21 15:12 metbril

This PR basically reverts #28?

yes, the change made in #28 means the log file directory is wrong.

bmdixon avatar Dec 05 '21 19:12 bmdixon

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.

felipecrs avatar Dec 21 '21 18:12 felipecrs

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)

metbril avatar Jan 04 '22 13:01 metbril

It should be. I suppose the most difficult part is to actually test what's inside $env:APPDATA when running as a service.

felipecrs avatar Jan 04 '22 13:01 felipecrs

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.

metbril avatar Jan 04 '22 21:01 metbril

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

chriscolden avatar Jan 24 '22 17:01 chriscolden