Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript Update Multiple Reg Keys

$
0
0

Hi

I am looking to develop a vbscript that first check if the registry keys exist, and second if the value exist ignore to do any updates. But, if the values do not exist to perform an update.

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv")
Set Shell = CreateObject( "WScript.Shell" )

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop"
strValueName = "\\servername\sharename\" & UserName & "\Desktop"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites"
strValueName = "\\servername\sharename\" & UserName & "\Favorites"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData"
strValueName = "\\servername\sharename\" & UserName & "\AppData"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData"
strValueName = "\\servername\sharename\" & UserName & "\Local AppData"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Music"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Music"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Pictures"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Pictures"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Videos"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Videos"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Documents"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Documents"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal"
strValueName = "\\servername\sharename\" & UserName & "\My Documents\My Documents"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
'Shell Folders
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop", "\\servername\sharename" & UserName & "\Desktop", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites", "\\servername\sharename" & UserName & "\Favorites", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\AppData", "%USERPROFILE%\AppData\Roaming", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Downloads", "%USERPROFILE%\Downloads", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Local AppData", "%USERPROFILE%\AppData\Local", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Music", "\\servername\sharename\My Documents" & UserName & "\My Music", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Pictures", "\\servername\sharename\My Documents" & UserName & "\My Pictures", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Video", "\\servername\sharename\My Documents" & UserName & "\My Videos", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal", "\\servername\sharename\" & UserName & "\Documents", "REG_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\My Documents", "\\servername\sharename" & UserName & "\My Documents", "REG_SZ"
'User SHell Folders
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop", "\\servername\sharename" & UserName & "\Desktop", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites", "\\servername\sharename" & UserName & "\Favorites", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData", "%USERPROFILE%\AppData\Roaming", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Downloads", "%USERPROFILE%\Downloads", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData", "%USERPROFILE%\AppData\Local", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Music", "\\servername\sharename\My Documents" & UserName & "\My Music", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Pictures", "\\servername\sharename\My Documents" & UserName & "\My Pictures", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Video", "\\servername\sharename\My Documents" & UserName & "\My Videos", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal", "\\servername\sharename" & UserName & "\My Documents", "REG_EXPAND_SZ"
    Shell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\My Documents", "\\servername\sharename" & UserName & "\My Documents", "REG_EXPAND_SZ"
Else
    Wscript.Echo "The registry key exists."
End If



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>