refresh user profile

rated by 0 users
This post has 4 Replies | 2 Followers

Top 500 Contributor
Posts 7
Chris Ngu Posted: 05-12-2012 2:24 AM

I found this vbs script to refresh the current user profile so you can see the change immediately. what would be the powershell equivalent

Set oShell = CreateObject("WScript.Shell")
Set oSHApp = CreateObject("Shell.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")

'Set Wallpaper to Path Below
sWinDir = oFSO.GetSpecialFolder(0)
sWallPaper = "C:\WINDOWS\DOMXP.bmp"

' Update Wallpaper in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
wscript.sleep 3000

'Refresh Screen
oSHApp.ControlPanelItem cstr("desk.cpl")
' alt. oShell.Run "control desk.cpl"

Do Until oShell.AppActivate ("Display Properties")
Loop
oShell.SendKeys "{DOWN}{UP}{TAB 3}~"

'Minimise all Windows.
oSHApp.MinimizeAll
Top 10 Contributor
Posts 640

I'm not able to rewrite the entire script for you, but here's an example.

$shell = new-object -com 'WScript.Shell'
$shell.run('control desk.cpl')

That's how to create a COM object and run one of its methods. 

Top 500 Contributor
Posts 7

The wallpaper was just an example. I want to be able to refresh the user's running profile so that changes made via the registry, such as with the Environment Variable PATH, can be applied to the user's running profile without logging off and back on.
So that it can be used for scripted program installations which will make Environment Variable changes via registry key value additions within HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.

Idk if that makes a little more sense

Top 10 Contributor
Posts 640

I understand... I'm just saying that, in a free Q&A forum, I'm not really able to invest the time to rewrite your entire script for you. Instead, I provided you with an example of the PowerShell syntax, using a specific portion of your script as an example.

You should be able to take that syntax example and apply it to the rest of your script yourself. Everything in that VBScript you pasted can be converted to the PowerShell syntax I showed you.

Top 500 Contributor
Posts 7

Thank you

Page 1 of 1 (5 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.