/build/static/layout/Breadcrumb_cap_w.png

Read and compare registry keys

Hello,

During the install process, I need to look for this key :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

I have to read it before, and after an action, and compare its value.

I wanted to use some VbScript, but the problem is that this key exists only when windows need it (Windows uses it to remove files after reboot), and if I use the "RegRead" method, VbScript return an ERROR (and the install fails) if the key doesn't exists.

Do you know other vbScript methods which could work ?

0 Comments   [ + ] Show comments

Answers (12)

Posted by: babric 19 years ago
Senior Purple Belt
0
I found that :

Const HKEY_LOCAL_MACHINE = &H80000002

Dim strComputer, sKey, sKeyPath
strComputer = "."

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

strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

sKey=arrSubKeys(0)
if (skey = PendingFileRenameOperations) then
sKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager"&sKey
I DO WHAT I HAVE TO DO
End if

Found the idea here : http://www.appdeploy.com/messageboards/fb.asp?m=10157

But don't know if it works :-)
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
What's wrong with something like this?

On Error Resume Next

Const sKEY = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations"

Set oWsh = CreateObject("WScript.Shell")

Err.Clear
sRegVal = oWsh.RegRead(sKEY)
If Err.Number <> 0 Then

msgbox sRegVal
'and whatever else you like

End If

Set oWsh = Nothing

You can use "On Error Resume Next" and "On Error Goto 0" to supress errors where you expect them. You can still check for the with "Err.Number" and "Err.Description".[;)]
Posted by: AngelD 19 years ago
Red Belt
0
or ;)

Option Explicit
On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002
Dim objReg, strComputer, strKeyPath, strValueName, arrValues, strValue

strComputer = "."
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager"
strValueName = "PendingFileRenameOperations"

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

objReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,arrValues

If Ubound(arrValues) < 0 Then Wscript.Quit 2 '// exit if not found

For Each strValue In arrValues
Wscript.Echo strValue
Next

Set objReg = Nothing

I DO WHAT I HAVE TO DO
End if
Posted by: babric 19 years ago
Senior Purple Belt
0
Thank you AngelD !

That's exactly what I need, and... what I needed for some other VbScript. [:D]

I'm new in packaging, and in VbScript, so I didn't know how to check the errors. I'll look for the msdn about it.

thank you very much, that's really a very interesting statement for me :-)
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
I hadn't noticed that the key was a "REG_MULTI_SZ"... This should be more appropriate:

On Error Resume Next

Const sKEY = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations"

Set oWsh = CreateObject("WScript.Shell")

aRegVal = oWsh.RegRead(sKEY)

For Each s in aRegVal

Msgbox s

Next

Set oWsh = Nothing

Personally, I avoid using WMI when the scripting host alone will do the job. Otherwise, you're introducing an extra (unnecessary) potential point of failure.
Posted by: babric 19 years ago
Senior Purple Belt
0
Ok,

I am building MSI packages whereas the actual packages are IS 6.3 based.
When I install my MSI package, it must uninstall the old one and then installs itself. However, before installing, sometimes, the computer should reboot (because of "in use" files in the IS 6.3 packages). In order to detect it, I have to look for the Pending[...] Value Before, and After the uninstall.

I don't want to reboot during the install if it's not necessary, that's why I have to look for a lot of parameters of which this one. For me, it's a necessary point :-)

Personally, I avoid using WMI when the scripting host alone will do the job.

What do you mean by "Scripting host" ?
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
0
Well this simple extract should be enough...

Set oWsh = CreateObject("WScript.Shell")
On Error Resume Next
oWsh.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations" )
If Err.Number <> 0 Then 'Reboot in this case

Don't get me wrong - the WMI method will work too, but your question was: ...do you know other vbScript methods which could work?

I would have a personal preference for the simplest method that is the least likely to fail.

What do you mean by "Scripting host"?

The object called "WScript.Shell".
Posted by: babric 19 years ago
Senior Purple Belt
0
hum, OK..... "whistle" [&:]

I'm confused, I thanked AngelD, but Used WiseUser Script... I believed that he had proposed 2 differents scripts...

So YES I used your script WiseUser, and I thank you, but I thank you too AngelD... [;)] Your method is maybe just a little bit harder for me, but no doubt that it is a good one [:D]


[&:] need some holidays [8|]
Posted by: AngelD 19 years ago
Red Belt
0
I would go with WiseUser's solution as this will not "require" an extra script-object as WMI.
Posted by: AngelD 19 years ago
Red Belt
0
As I recall Windows Installer should solve this by itself that is; only replace file with higher version and remove lower before the new will get in place through PendingFileRenameOperations.
So don't think you need to restart after the uninstall has finished.
Posted by: babric 19 years ago
Senior Purple Belt
0
So don't think you need to restart after the uninstall has finished.

I don't understand.

The uninstall is not an MSI uninstall. During the MSI InstallExecuteSequence, I launch the old package (NOT Msi based) setup. After the uninstall, if there were files in use, they are written in the Pending[...] Key. And that's the problem for me, because if I install my new package (MSI) at the same place that the old one (NON MSI), files in use will be deleted after the next reboot ! Even if the MSI package replaced the old ones... :-/

Hope you understand, and hope that I didn't wrote a vbScript for nothing :-)
Posted by: AngelD 19 years ago
Red Belt
0
Ah sorry for that, forget what i wrote ;)
Edit: I mixed it up how files are replaced by security patch installations.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ