Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace environment variable with specific path #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bmdixon
Copy link

@bmdixon bmdixon commented May 14, 2021

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

Resolves #33

The service runs as LocalService so the $env:APPDATA path is incorrect.
@@ -66,7 +66,7 @@ $TeamsProcess = Get-Process -Name Teams -ErrorAction SilentlyContinue

# Check if Teams is running and start monitoring the log if it is
If ($null -ne $TeamsProcess) {
If($TeamsStatus -eq $null){ }
If ($null -eq $TeamsStatus) { }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best practice in PowerShell to have the $null on the left of checks - See here

@metbril
Copy link
Contributor

metbril commented Dec 5, 2021

This PR basically reverts #28?

@bmdixon
Copy link
Author

bmdixon commented Dec 5, 2021

This PR basically reverts #28?

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

@felipecrs
Copy link

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.

@metbril
Copy link
Contributor

metbril commented Jan 4, 2022

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)

@felipecrs
Copy link

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

@metbril
Copy link
Contributor

metbril commented Jan 4, 2022

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.

@chriscolden
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Service doesn't update status when using Env:AppData
4 participants