Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

check for registry entry then run VBS

Posted on 2008-10-02
4
Medium Priority
?
307 Views
Last Modified: 2012-06-27
I want to create an .exe file that, on install creates a registry entry and adds an icon to the desktop.  When the user clicks on the icon it runs a VBS file that checks to see if that entry is there before running another VBS file.  
0
Comment
Question by:Dier02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 1800 total points
ID: 22623169
Try this function:

'==================================================================================
 
' Function Name : regKeyExists(pHive, byVal pKey)
 
' Return value  : Boolean (True or False)
 
' Author        : Alex Simenduev, http://www.planetit.ws
' Date          : 16/07/2008
 
' Description   : Check if specified registry key in specified HIVE exists
 
'==================================================================================
 
Function regKeyExists(pHive, byVal pKey) : regKeyExists = False
 
	Dim objReg, strSubkey, arrSubkeys, strKey, arrSplit, intReturn
 
	Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
 
	
 
	' Remove ending backslash (\) if exists
 
	If Right(pKey, 1) = "\" Then
 
		pKey = Left(pKey, Len(pkey) - 1)
 
	End If
 
	
 
	arrSplit = Split(pkey, "\")
 
	strKey = arrSplit(Ubound(arrSplit))
 
	pKey = Left(pKey, Len(pkey) - Len(strKey) - 1)
 
	
 
	intReturn = objReg.EnumKey(pHive, pKey, arrSubkeys)
 
	If intReturn <> 0 Then Exit Function
 
	If Not isArray(arrSubkeys) Then Exit Function
 
	
 
	For Each strSubkey in arrSubkeys
 
		If UCase(strSubkey) = UCase(strKey) Then 
 
			regKeyExists = True
 
			Exit Function
 
		End If
 
	Next
 
End Function

Open in new window

0
 
LVL 5

Accepted Solution

by:
si_shamil earned 1800 total points
ID: 22623180
Ups, the snippet has added an extra lines, ignore it, use this:

'==================================================================================
' Function Name    : regKeyExists(pHive, byVal pKey)
' Return value    : Boolean (True or False)
' Author            : Alex Simenduev, Oasis Capital Management
' Date            : 16/07/2008
' Description        : Check if specified registry key in specified HIVE exists
'==================================================================================
Function regKeyExists(pHive, byVal pKey) : regKeyExists = False
    Dim objReg, strSubkey, arrSubkeys, strKey, arrSplit, intReturn
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
     
    ' Remove ending backslash (\) if exists
    If Right(pKey, 1) = "\" Then
        pKey = Left(pKey, Len(pkey) - 1)
    End If
     
    arrSplit = Split(pkey, "\")
    strKey = arrSplit(Ubound(arrSplit))
    pKey = Left(pKey, Len(pkey) - Len(strKey) - 1)
     
    intReturn = objReg.EnumKey(pHive, pKey, arrSubkeys)
    If intReturn <> 0 Then Exit Function
    If Not isArray(arrSubkeys) Then Exit Function
     
    For Each strSubkey in arrSubkeys
        If UCase(strSubkey) = UCase(strKey) Then  
            regKeyExists = True
            Exit Function
        End If
    Next
End Function
0
 

Author Comment

by:Dier02
ID: 22623206
I want to create an .exe file that, on install creates a registry entry and adds an icon to the desktop.
0
 
LVL 22

Assisted Solution

by:Paka
Paka earned 200 total points
ID: 22624368
To do these, you will need a VBS packager (such as PrimalScript).  PrimalScript will let you package your vbs as an EXE.  PrimalScript has a 30 evaluation program that will let you develop the EXE you need.

To work with the registry in VBS use this link:
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/operatingsystem/registry/

How to create a desktop shortcut:
http://www.computerperformance.co.uk/ezine/ezine119.htm



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question