Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help with vbs script

Reply
 
Old 06-15-2009   #1 (permalink)
אמיר עטרי


 
 

Help with vbs script

Hello all

I am trying to write a vbs script.
The purpose of the script is to check if a GUID number is exist on the
registry.
if not, to install the an application and if Yes, to end.

Example:

If
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
exsit then END
if not, install the application (in this case office VSTO).

Thank you very much for your help

Amir



My System SpecsSystem Spec
Old 06-15-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Help with vbs script


"???? ????" <@discussions.microsoft.com> wrote in message
news:2EEC4EC6-8D6B-4F5C-BBB4-B86CB1A2D0F4@xxxxxx
Quote:

> Hello all
>
> I am trying to write a vbs script.
> The purpose of the script is to check if a GUID number is exist on the
> registry.
> if not, to install the an application and if Yes, to end.
>
> Example:
>
> If
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
> exsit then END
> if not, install the application (in this case office VSTO).
>
> Thank you very much for your help
>
> Amir
>
Since the installation of Office VSTO is most likely invoked via an
executable file, it would be simpler to run the whole process in batch file,
e.g. like so:
@echo off
if exist c:\installed.reg del c:\installed.reg
regedit /e c:\installed.reg
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
if exist c:\installed.reg (
del c:\installed.reg
goto :eof
)
e:\setup.exe [this is the Office VSTO installation program]


My System SpecsSystem Spec
Old 06-15-2009   #3 (permalink)
אמיר עטרי


 
 

Re: Help with vbs script


Hi there,
Thank you for your answer.

When you wrote: "if exist c:\installed.reg del c:\installed.reg"

Should i create first the installed.reg file and put it in c:\installed?

Should it contain the path to the guid?

Thanks gain.

Amir

"Pegasus [MVP]" wrote:
Quote:

>
> "???? ????" <@discussions.microsoft.com> wrote in message
> news:2EEC4EC6-8D6B-4F5C-BBB4-B86CB1A2D0F4@xxxxxx
Quote:

> > Hello all
> >
> > I am trying to write a vbs script.
> > The purpose of the script is to check if a GUID number is exist on the
> > registry.
> > if not, to install the an application and if Yes, to end.
> >
> > Example:
> >
> > If
> > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
> > exsit then END
> > if not, install the application (in this case office VSTO).
> >
> > Thank you very much for your help
> >
> > Amir
> >
>
> Since the installation of Office VSTO is most likely invoked via an
> executable file, it would be simpler to run the whole process in batch file,
> e.g. like so:
> @echo off
> if exist c:\installed.reg del c:\installed.reg
> regedit /e c:\installed.reg
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
> if exist c:\installed.reg (
> del c:\installed.reg
> goto :eof
> )
> e:\setup.exe [this is the Office VSTO installation program]
>
>
>
My System SpecsSystem Spec
Old 06-15-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Help with vbs script

No, you don't prepare anything. Just run the batch file as it is.

"???? ????" <@discussions.microsoft.com> wrote in message
news:867DCF22-9F10-458F-BADC-B422CE30D9D7@xxxxxx
Quote:

>
> Hi there,
> Thank you for your answer.
>
> When you wrote: "if exist c:\installed.reg del c:\installed.reg"
>
> Should i create first the installed.reg file and put it in c:\installed?
>
> Should it contain the path to the guid?
>
> Thanks gain.
>
> Amir
>
> "Pegasus [MVP]" wrote:
>
Quote:

>>
>> "???? ????" <@discussions.microsoft.com> wrote in message
>> news:2EEC4EC6-8D6B-4F5C-BBB4-B86CB1A2D0F4@xxxxxx
Quote:

>> > Hello all
>> >
>> > I am trying to write a vbs script.
>> > The purpose of the script is to check if a GUID number is exist on the
>> > registry.
>> > if not, to install the an application and if Yes, to end.
>> >
>> > Example:
>> >
>> > If
>> > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
>> > exsit then END
>> > if not, install the application (in this case office VSTO).
>> >
>> > Thank you very much for your help
>> >
>> > Amir
>> >
>>
>> Since the installation of Office VSTO is most likely invoked via an
>> executable file, it would be simpler to run the whole process in batch
>> file,
>> e.g. like so:
>> @echo off
>> if exist c:\installed.reg del c:\installed.reg
>> regedit /e c:\installed.reg
>> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{388E4B09-3E71-4649-8921-F44A3A2954A7}
>> if exist c:\installed.reg (
>> del c:\installed.reg
>> goto :eof
>> )
>> e:\setup.exe [this is the Office VSTO installation program]
>>
>>
>>

My System SpecsSystem Spec
Old 07-01-2009   #5 (permalink)
Mark D. MacLachlan


 
 

Re: Help with vbs script

אמיר עטרי wrote:
Quote:

> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
> \{388E4B09-3E71-4649-8921-F44A3A2954A7}
Take a look at this Hey Scripting Guy:
http://www.microsoft.com/technet/scr...nda/oct04/hey1
029.mspx

One thing to mention though is that in my testing it does nto seem to
work on Windows 7. Not sure about Vista. I beleive this is a bug.

Hope that helps,

Mark D. MacLachlan

--

My System SpecsSystem Spec
Old 07-01-2009   #6 (permalink)
PaulM


 
 

Re: Help with vbs script

Are you talking about this script??

Const HKEY_LOCAL_MACHINE = &H80000002

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

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "SystemRoot"
objRegistry.GetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
End If

It works fine in Windows 7.

--
Windows XP and Vista Tweaks
------------------------------------------------------------
www.paulsxp.com
------------------------------------------------------------
Windows XP and Vista Help Forum
------------------------------------------------------------
www.paulsxp.com/forum
------------------------------------------------------------
Live Computer Help and Chat
------------------------------------------------------------
www.paulsxp.com/livesupport.html
------------------------------------------------------------


"Mark D. MacLachlan" <markdmac@xxxxxx> wrote in message
news:e1iRgom#JHA.1376@xxxxxx
Quote:

> אמיר עטרי wrote:
>
Quote:

>> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
>> \{388E4B09-3E71-4649-8921-F44A3A2954A7}
>
> Take a look at this Hey Scripting Guy:
> http://www.microsoft.com/technet/scr...nda/oct04/hey1
> 029.mspx
>
> One thing to mention though is that in my testing it does nto seem to
> work on Windows 7. Not sure about Vista. I beleive this is a bug.
>
> Hope that helps,
>
> Mark D. MacLachlan
>
> --
>
My System SpecsSystem Spec
Old 07-02-2009   #7 (permalink)
Mark D. MacLachlan


 
 

Re: Help with vbs script

Yes, I am indeed talking about that script. I agree it does work fine
for most registry reads, however it does not work (on my Windows 7 x64
system) when trying to read an Uninstall key down at the curly braces
level.

I am able to successfully read up to
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall however trying to
read a value past that point failes. I would be greatful for someone
else to verify my findings by trying to read a path such as
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{
90120000-002A-0000-1000-0000000FF1CE}

That is the path to the "Microsoft Office Office 64-bit Components
2007".


Code I am trying is:
Code:
Const HKEY_LOCAL_MACHINE = &H80000002

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

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strValueName = "{90120000-002A-0000-1000-0000000FF1CE}"
objRegistry.GetStringValue
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then
Wscript.Echo "The registry key does not exist."
Else
Wscript.Echo "The registry key exists."
End If
The OP is trying to read such a value, so I think this script will
serve them well on an older OS but not Windows 7 unless someone can
confirm the problem is just on my side.

Regards,

Mark D. MacLachlan
My System SpecsSystem Spec
Old 07-02-2009   #8 (permalink)
PaulM


 
 

Re: Help with vbs script

I tried your script on windows 7, and you are right.
I added the key and the script run it said ,"The registry key does exists"
ever if the key is there.

--
Windows XP and Vista Tweaks
------------------------------------------------------------
www.paulsxp.com
------------------------------------------------------------
Windows XP and Vista Help Forum
------------------------------------------------------------
www.paulsxp.com/forum
------------------------------------------------------------
Live Computer Help and Chat
------------------------------------------------------------
www.paulsxp.com/livesupport.html
------------------------------------------------------------


"Mark D. MacLachlan" <markdmac@xxxxxx> wrote in message
news:eT5vAU1#JHA.1252@xxxxxx
Quote:

> Yes, I am indeed talking about that script. I agree it does work fine
> for most registry reads, however it does not work (on my Windows 7 x64
> system) when trying to read an Uninstall key down at the curly braces
> level.
>
> I am able to successfully read up to
> SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall however trying to
> read a value past that point failes. I would be greatful for someone
> else to verify my findings by trying to read a path such as
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{
> 90120000-002A-0000-1000-0000000FF1CE}
>
> That is the path to the "Microsoft Office Office 64-bit Components
> 2007".
>
>
> Code I am trying is:
>
Code:
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> strComputer = "."
> Set objRegistry = GetObject("winmgmts:\\" & _
>   strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
> strValueName = "{90120000-002A-0000-1000-0000000FF1CE}"
> objRegistry.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
>
> If IsNull(strValue) Then
>   Wscript.Echo "The registry key does not exist."
> Else
>   Wscript.Echo "The registry key exists."
> End If
>
>
> The OP is trying to read such a value, so I think this script will
> serve them well on an older OS but not Windows 7 unless someone can
> confirm the problem is just on my side.
>
> Regards,
>
> Mark D. MacLachlan
My System SpecsSystem Spec
Old 07-02-2009   #9 (permalink)
mayayana


 
 

Re: Help with vbs script

A couple of other possibilities.... I haven't tried
these specifically on Win7, though:

If the check is local you can use WScript.Shell, which
is simpler than WMI:

Function Exists(RegPath)
Dim r
On Error Resume Next
r = SH.RegRead(RegPath) '--SH here is WScript.Shell object.
If Hex(Err.number) = "80070002" Then
Exists = False
Else
Exists = True
End If
End Function

If you have to use WMI it's awkward, but one way
is to call EnumKey on the parent key. If that succeeds
and the sought after key name is in the returned
array, then the key exists. Something like this:

Dim HKLM, Path, iRet, Reg, AKeys, sKey, i2, sErr
HKLM = &H80000002
Path = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
sKey = "{388E4B09-3E71-4649-8921-F44A3A2954A7}"

Set Reg = GetObject("winMgMts:root\default:StdRegProv")
iRet = Reg.EnumKey(HKLM, Path, AKeys)

On Error Resume Next
Select Case iRet
Case 0
If UBound(AKeys) = -1 Then
sErr = "no subkeys" 'no subkeys
Else
' There are subkeys to be checked.
End If
Case 2
sErr = "path invalid" '-- invalid key Path
Case -2147217405
sErr = "access denied" '-- access denied H80041003
Case Else
sErr = "Error number: " & iRet '-- some other error.
End Select

If Len(sErr) = 0 Then
For i2 = 0 to UBound(AKeys)
If UCase(AKeys(i2)) = UCase(sKey) Then
MsgBox "key exists"
Set Reg = Nothing
WScript.quit
End If
Next
End If

Set Reg = Nothing
MsgBox "Key does not exist. " & sErr



My System SpecsSystem Spec
Old 07-03-2009   #10 (permalink)
Mark D. MacLachlan


 
 

Re: Help with vbs script

PaulM wrote:
Quote:

> I tried your script on windows 7, and you are right.
> I added the key and the script run it said ,"The registry key does
> exists" ever if the key is there.
Thanks for confirming Paul. It is really strange how it will work
prior to that point but not further down the tree.

--

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Logon Script Causing Laptops To Hang - Problems in script? VB Script
problem passing args to script 'There is no script engine for file extenstion' VB Script
Include another script, keep variables in included script? PowerShell
Script file has 'OS Handle' error when run from script PowerShell
Can you drag-n-drop a file on top of a PS script to run the script? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46