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 ?
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)
Please log in to answer
Posted by:
babric
19 years ago
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 :-)
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
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".[;)]
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
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
Posted by:
WiseUser
19 years ago
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.
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
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 :-)
What do you mean by "Scripting host" ?
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
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:
I would have a personal preference for the simplest method that is the least likely to fail.
The object called "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
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|]
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
Posted by:
AngelD
19 years ago
Posted by:
babric
19 years ago
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.