I'm trying to modify PS script, but still cant figureout what can be wrong.
cp "image.jpg" \\<IP>\C$
$RemoteReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('Users', "<IP>")
$WallPaper= $RemoteReg.OpenSubKey("S-1-5-21-780093305-1579027723-3042286928-500\Control Panel\Desktop",$True)
$WallPaper.SetValue("Wallpaper","C:\image.jpg")
But I need to use variable SIDs. So I've made this script:
$hostname = Read-Host 'enter hostname of station'
$username = Read-Host 'enter username (login)'
$objUser = New-Object System.Security.Principal.NTAccount($username)
$userSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$SIDandPath = Join-Path $userSID "Control Panel\Desktop"
cp d:\pic1.jpg \\$hostname\c$
$BaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey( 'Users' , $hostname )
$SubKey = $BaseKey.OpenSubKey($SIDandPath,$true)
$SubKey.SetValue("Wallpaper","d:\pic1.jpg")
And I'm still receiving thi error:
You cannot call a method on a null-valued expression. At C:\Users\"username"\Scripty\change_remote_wallpaper.ps1:32 char:17 + $SubKey.SetValue <<<< ("Wallpaper","d:\pic1.jpg") + CategoryInfo : InvalidOperation: (SetValue:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
Any ideas what can be wrong? If I set the value of $SubKey to "1", then I receive this:
"Method invocation failed because [System.Int32] doesn't contain a method named 'SetValue'."
So I think, that the problem is with "OpenSubKey"
Thanks for any help!!