Jump to content
level42

Setting the Pulseway Computer name to the Locally logged in username

Recommended Posts

So, I have this:
 

Set-ItemProperty -Path "HKLM:\Software\MMSOFT Design\PC Monitor\" -Name ComputerName -Value "$env:UserName"

Which works great from the local machine via PowerShell,

However, when I try to run this as a script/task, the name just shows up as "HOSTNAME$"

Any ideas why?

Edited by level42

Share this post


Link to post
Share on other sites

Hi @level42,

Pulseway runs these commands as the local system user (as it's a Windows Service). When you run the powershell command locally it runs in the user session which shows correctly your username. Kind in mind that Pulseway runs even if there is no logged in user.

-Paul

Share this post


Link to post
Share on other sites

Is there then another way where I can extract the locally logged in user and assign that to the PulseWay name? The few examples I found were all for domain accounts.

Share this post


Link to post
Share on other sites

Try looking at the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LastUsedUsername

-Paul

Share this post


Link to post
Share on other sites

Hi Paul,

I'm still not sure I understand where these commands are being executed. To me, they seem to be executing on the target local machine, because it is able to successfully "SET" the username, however, it can't seem to read the currently logged in user.

I also tested this, but the result is, it simply sets the Pulseway name to the Hostname ...

$key = 'HKCU:\Volatile Environment'
$UserName = (Get-ItemProperty -Path $key -Name USERNAME).USERNAME

Set-ItemProperty -Path "HKLM:\Software\MMSOFT Design\PC Monitor\" -Name ComputerName -Value "$UserName"

Again, this works from the local workstation, but not as a script.

Is there a way to debug the scripts in Pulseway, and get output directly in Pulseway, as opposed to just plugging in the script and running it to see results?

Edited by level42

Share this post


Link to post
Share on other sites

@level42, Pulseway runs scripts as the SYSTEM account. HKEY Current User will be different for the SYSTEM account compared with the HKEY Current User for a logged in user. Try running powershell as the SYSTEM account using psexec and you'll be able to run scripts exactly as the Pulseway service runs them.

-Paul

Share this post


Link to post
Share on other sites

Ok, that makes more sense. In that case I needed to take advantage of WMI.

My final code is this, which works great!

$temp = Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty username
$UserName = $temp -replace ".*\\", ""

Set-ItemProperty -Path "HKLM:\Software\MMSOFT Design\PC Monitor\" -Name ComputerName -Value "$UserName"

Thanks for the help!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...