Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Problem reading value in HKEY_USER

Reply
 
Old 05-17-2009   #1 (permalink)
Khaosinc


 
 

Problem reading value in HKEY_USER

Could someone please offer some advise regarding a script that I am
trying to write. And I am a Noob to Vbscript!
I have been tasked with deploying a new image for the corparate
desktop, deploying the new image was the easy part, I wrote a script
that would copy the new image from an admin share and replace the old
image in the system root.
The problem that I have found is that if the end user already has the
old image set as their desktop wallpaper, Windows has already copied
and converted the image and relocated it in c:\document and setting\
%username%\local settings\microsoft\Wallpaper1.bmp, and the user
still see the old image on their desktop. (I can not just replace
wallpaper1.bmp, just in case the user has a custom wallpaper i.e.
family picture)

I started with the below code to identify if the current user was
using the corparate image as their desktop wallpaper.

===================================================================================

Option Explicit
'On Error Resume Next

Dim oReg
Dim strComputer, strKeyPath, strValueName, strValue

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Control Panel\Desktop"
strValueName = "ConvertedWallPaper"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath, _
strValueName,strValue

Wscript.Echo "Image being used: " & strValue

===================================================================================

I used the code in a logon script, If strValue = Corparate image Then
copy the new image from the admin share and replace wallpaper1.bmp
(replaced with a converted new image with the relevant name), but this
didn't work, I can only assume that the HKCU hive isn't loaded into
the registry when the script runs.

So as a workaround I came up with the below script, but it is
returning nothing. Any ideas??

===================================================================================

Dim oReg
Dim strComputer, strKeyPath, strValueName, strValue

Const HKEY_USERS = &H80000003

strComputer = "."
strKeyPath = "Control Panel\Desktop"
strValueName = "ConvertedWallPaper"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")

WScript.Echo SID
WScript.Echo(HKEY_USERS& "\" & SID & "\" & strKeyPath & "\" &
strValueName & "\")

oReg.GetStringValue HKEY_USERS,SID,strKeyPath,strValueName,strValue

Wscript.Echo "Image being used: " & strValue

'===================================================================

Private Function SID

Const HKEY_USERS = &H80000003

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
\root\default:StdRegProv")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set wshShell = CreateObject("WScript.Shell")
Set objSysEnv = wshShell.Environment("User")

objSysEnv("FULLNAME") = objUser.FullName
objReg.EnumKey HKEY_USERS, "", arrKeys

For Each subkey In arrKeys
objReg.GetExpandedStringValue HKEY_USERS,subkey &
"\Environment","FULLNAME",strValue
If strValue = objUser.FullName Then
SID = subkey
End If
Next

End Function

===================================================================================

Please HELP!!

My System SpecsSystem Spec
Old 05-20-2009   #2 (permalink)
Khaosinc


 
 

Re: Problem reading value in HKEY_USER

On May 17, 10:05*pm, Khaosinc <israel.new...@xxxxxx> wrote:
Quote:

> Could someone please offer some advise regarding a script that I am
> trying to write. And I am a Noob to Vbscript!
> I have been tasked with deploying a new image for the corparate
> desktop, deploying *the new image was the easy part, I wrote a script
> that would copy the new image from an admin share and replace the old
> image in the system root.
> The problem that I have found is that if the end user already has the
> old image set as their desktop wallpaper, Windows has already copied
> and converted the image and relocated it in c:\document and setting\
> %username%\local settings\microsoft\Wallpaper1.bmp, *and the user
> still see the old image on their desktop. (I can not just replace
> wallpaper1.bmp, just in case the user has a custom wallpaper i.e.
> family picture)
>
> I started with the below code to identify if the current user was
> using the corparate image as their desktop wallpaper.
>
> ===========================================================================*========
>
> Option Explicit
> 'On Error Resume Next
>
> Dim oReg
> Dim strComputer, strKeyPath, strValueName, strValue
>
> Const HKEY_CURRENT_USER = &H80000001
>
> strComputer = "."
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> * * strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "Control Panel\Desktop"
> strValueName = "ConvertedWallPaper"
> oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath, _
> * * strValueName,strValue
>
> Wscript.Echo *"Image being used: " & strValue
>
> ===========================================================================*========
>
> I used the code in a logon script, If strValue = Corparate image Then
> copy the new image from the admin share and replace wallpaper1.bmp
> (replaced with a converted new image with the relevant name), but this
> didn't work, I can only assume that the HKCU hive isn't loaded into
> the registry when the script runs.
>
> So as a workaround I came up with the below script, but it is
> returning nothing. Any ideas??
>
> ===========================================================================*========
>
> Dim oReg
> Dim strComputer, strKeyPath, strValueName, strValue
>
> Const HKEY_USERS = &H80000003
>
> strComputer = "."
> strKeyPath = "Control Panel\Desktop"
> strValueName = "ConvertedWallPaper"
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
> strComputer & "\root\default:StdRegProv")
>
> WScript.Echo SID
> WScript.Echo(HKEY_USERS& "\" & SID & "\" & strKeyPath & "\" &
> strValueName & "\")
>
> oReg.GetStringValue HKEY_USERS,SID,strKeyPath,strValueName,strValue
>
> Wscript.Echo *"Image being used: " & strValue
>
> '===================================================================
>
> Private Function SID
>
> Const HKEY_USERS = &H80000003
>
> Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
> \root\default:StdRegProv")
> Set objSysInfo = CreateObject("ADSystemInfo")
> Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
> Set wshShell = CreateObject("WScript.Shell")
> Set objSysEnv = wshShell.Environment("User")
>
> objSysEnv("FULLNAME") = objUser.FullName
> objReg.EnumKey HKEY_USERS, "", arrKeys
>
> For Each subkey In arrKeys
> * *objReg.GetExpandedStringValue HKEY_USERS,subkey &
> "\Environment","FULLNAME",strValue
> * *If strValue = objUser.FullName Then
> * * * *SID = subkey
> * *End If
> Next
>
> End Function
>
> ===========================================================================*========
>
> Please HELP!!

Problem Solved

Const HKEY_USERS = &H80000003

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = SID & "\Control Panel\Desktop"
oReg.GetStringValue HKEY_USERS, strKeyPath, "ConvertedPaper", intValue

Wscript.Echo intValue

'==========================================================================================

Private Function SID

Dim objReg, objSysInfo, objUser
Dim wshShell, objSysEnv, arrKeys
Dim strValues, subKey

Const HKEY_USERS = &H80000003

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.
\root\default:StdRegProv")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set wshShell = CreateObject("WScript.Shell")
Set objSysEnv = wshShell.Environment("User")

objSysEnv("FULLNAME") = objUser.FullName
objReg.EnumKey HKEY_USERS, "", arrKeys

For Each subkey In arrKeys
objReg.GetExpandedStringValue HKEY_USERS,subkey &
"\Environment","FULLNAME",strValues
If strValues = objUser.FullName Then
SID = subkey
End If
Next

End Function
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
hardware problem only reading 24g out of 120 does anyone know what to do General Discussion
Problem reading the registry Virtual PC
hkey_user to hkey_current_user Vista installation & setup
Problem reading .DAT files Vista installation & setup
Preview/Reading Pane Problem Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46