Solved

check for registry entry then run VBS

Posted on 2008-10-02
4
255 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
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 450 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 450 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now