Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read the value of a DWord

Status
Not open for further replies.

KRPGroup

MIS
Jun 22, 2005
317
CA
I am trying to look for a value of a Dword, if it is not true or not present at all then I want to run a reg add cmd. I used some msgbox's for testing as I am new at this. Adding or changing the value is working but I am having trouble tring to read the Value data.

Any suggestions will be appreciated..!!

Code:
Option Explicit

On Error Resume Next
 
Dim PvRestore,PvTab
Set WshShell = WScript.CreateObject("WScript.Shell")
 
Set WshShell=CreateObject("WScript.Shell")
PvRestore = "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\NoPreviousVersionsRestore"
 
WSHShell.RegRead(PvRestore)
 
If NoPreviousVersionsRestore = 1 Then 
	Msgbox "True", vbExclamation
	
Else
	Msgbox "False", vbExclamation

End If
 
[1] You use option explicit and not declaring all the variables before use. Why is that? If not you have on error resume next, you would have all sorts of runtime errors.
[2] Read documentation on the regread() and how it returns result. And what if the value does not exist...
[3] 1 is not necessarily true. In vb, vbTrue=-1.
[tt]
Option Explicit
On Error Resume Next
Dim PvRestore,PvTab[red],wshshell,x[/red]
Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshShell=CreateObject("WScript.Shell")
PvRestore = "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\NoPreviousVersionsRestore"

[red]x=[/red]WSHShell.RegRead(PvRestore)

'[red]If NoPreviousVersionsRestore = 1 Then [/red]
[blue]if err.number<>0 then
msgbox "The value does not exist."
err.clear
elseif x=1 then[/blue]
Msgbox "True", vbExclamation
Else
Msgbox "False", vbExclamation
End If
[/tt]
 
I am new to VBS and could use some direction on where to find the documentation regarding regread as well any other good reference. I am struggling to find where i can read about VBS.
 
Lets make this more simple. how do i read a registry DWord's value and display it.
 
Thanky you all..!!! The links have been helpful.

Here is what I have so far. It seems to be working fine for me. My ques is, can I have the code stop/ wait for the Silent install of the software before moving on.?? This silent install gives no indication to the user that it has completed and I thought I could use a msgbox or an echo to let them know it was successful after the install has finished.


Code:
On Error Resume Next
 
Dim Cw2005Ver,CwUpdate,WHSShell,ReadVer,exeUpdate,exeFullInstall
Set WshShell = WScript.CreateObject("WScript.Shell")
 
Cw2005Ver = "HKLM\Software\MyCustomSettings\Cw2005Ver"
CwUpdate = "139.26"	'---Latest CW verions
ReadVer = WSHShell.RegRead(Cw2005Ver)

exeUpdate = "\\fsterm\CW$\_updates\Install\Setup.exe /s"
exeFullInstall = "\\fsterm\CW$\setup.exe /s"



'---Reading Reg Values
WSHShell.RegRead(Cw2005Ver)


'---Echo Values for Testing
'WScript.Echo WshShell.RegRead(Cw2005Ver)

If Err Then
    '---Run Update then add Reg value..
WSHShell.Run(exeUpdate)
WSHShell.RegWrite Cw2005Ver, "139.26", "REG_SZ" 

Else
   If ReadVer = 139.26 Then 
    WScript.Echo "Current CaseWare v2005.00." & WshShell.RegRead(Cw2005Ver) &_
    	", update not required"
    	
   Else
    Msgbox "Current CaseWare v2005.00." & WshShell.RegRead(Cw2005Ver) &_
    	", update required", vbExclamation    	
    WSHShell.Run(exeUpdate)
    WSHShell.RegWrite Cw2005Ver, "139.26", "REG_SZ"      
   End If

End If


WScript.Quit
 
You may try to replace this:
WSHShell.Run(exeUpdate)
with this:
WSHShell.Run exeUpdate, , True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Have a look at this FAQ... faq329-5864

I found it useful for verifying Registry Key existance before attempting to read or write from the key.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top