cancel
Showing results for 
Search instead for 
Did you mean: 

VBScript: Record result in registry???

henderson1977
Grafter
Posts: 191
Registered: 31-07-2007

VBScript: Record result in registry???

Hi all, I have the following script which displays on screen the size of the My Documents folder:

Const MY_DOCUMENTS = &H5&

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace(MY_DOCUMENTS)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path

Set objFolder = objFSO.GetFolder(strPath)
Wscript.Echo objFolder.Size


It gives me the result I want but now I want to import this value into the registry so I can use LANDesk Reports to report on this value.

I am far from being a VBScript expert, so I need help. How do I convert/amend the Wscript.Echo objFolder.Size line to import the result into the registry instead of displaying the result on screen please? (it doesn't matter where in the registry it goes).

Thanks
Scott
5 REPLIES
MysteryFCM
Grafter
Posts: 528
Registered: 30-08-2007

VBScript: Record result in registry???

I wrote a VBS file for someone a few months ago that was wanting to write to the registry if it will help?

Dim objWSH, blnKey

Set objWSH = WScript.CreateObject("WScript.Shell")
On Error Resume Next
blnKey = objWSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\")
If Err.Number <> 0 Then '// Key exists
'// Code to create the key
On Error Resume Next
objWSH.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", 1, "REG_SZ"
'// Code to add the value
On Error Resume Next
objWSH.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\001\", "outlook.exe /importprf \\srvfile01\netlogon\outlook.prf", "REG_SZ"
End If
Set objWSH = Nothing
henderson1977
Grafter
Posts: 191
Registered: 31-07-2007

VBScript: Record result in registry???

Thanks mysteryfcm, this is the sort of VBScript I am after but have tried to tailor it to my needs, but keep running into compilation errors, or the like...

Can you give me some pointers or, if I'm not being too cheeky, have a go at patching the script together yourself plz?

Smiley
MysteryFCM
Grafter
Posts: 528
Registered: 30-08-2007

VBScript: Record result in registry???

Here you go Smiley (sorry for taking so long, my connection is pretty rubbish atm).

Option Explicit


Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

Const CSIDL_PERSONAL = &H5& '// My Documents

Dim objWSH, blnKey, objFSO, objShell, objFolder, lSize, sRegPath, x

sRegPath = "HKCU\MyDocuments_Size"

'// Open, use, destroy ...
Set objShell = CreateObject("Shell.Application")
objFolder = objShell.Namespace(CSIDL_PERSONAL).self.path
Set objShell = Nothing

'// Get the size and store it in a local var
Set objFSO = CreateObject("Scripting.FileSystemObject")
lSize = objFSO.GetFolder(objFolder).Size: Set objFolder = Nothing: Set objFSO = Nothing

Set objWSH = WScript.CreateObject("WScript.Shell")
'// Code to create the key (sRegPath must end in a backslash for this)
objWSH.RegWrite sRegPath, 1, "REG_SZ"
'// Code to add the value
objWSH.RegWrite sRegPath, lSize, "REG_SZ"

Set objWSH = Nothing
henderson1977
Grafter
Posts: 191
Registered: 31-07-2007

VBScript: Record result in registry???

You're a legend!

Many thanks, Steve.

Cheesy
MysteryFCM
Grafter
Posts: 528
Registered: 30-08-2007

VBScript: Record result in registry???

My pleasure Smiley