Solved

How to use wscript.quit to terminate a VBscript

Posted on 2009-05-13
3
2,189 Views
Last Modified: 2012-05-06
I have a VBscript that adds a registry key when a user logs on. What I want is for the scipt to not run if the key already exists. I'm fairly new to VB I'm pretty sure wscript.quit will do it I just don't get the syntax. The preferred key would be 5cb93b24ff710741b7d83b9cb6317992. Any help would be appreciated. FYI...I did not write this but have to modify it.
const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\default:StdRegProv")
RegistryFolder = "Software\Microsoft\Windows NT\" & _ 
  "CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\"
 
LDAPdisplayname = "xyz"
LDAPserver = "directory.xyz.abc.com"
LDAPport = "389"
LDAPsearchbase = "ou=employees,ou=people,dc=abc,dc=com"
 
 
'Add Ldap Type Key
sKeyPath = RegistryFolder & "e8cb48869c395445ade13e3c1c80d154\"
oReg.CreateKey HKEY_CURRENT_USER, sKeyPath 
oReg.SetBinaryValue HKEY_CURRENT_USER, _
     sKeyPath, "00033009", Array(0,0,0,0)
oReg.SetBinaryValue HKEY_CURRENT_USER, _
     sKeyPath, "00033e03", Array(&H23,0,0,0)
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e3001", "Microsoft LDAP Directory"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e3006", "Microsoft LDAP Directory"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e300a", "EMABLT.DLL"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e3d09", "EMABLT"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e3d13", "{6485D268-C2AC-11D1-AD3E-10A0C911C9C0}"
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, _
    "01023d0c", Array(&H5c,&Hb9,&H3b,&H24, _
    &Hff,&H71,&H07,&H41,&Hb7,&Hd8,_
    &H3b,&H9c,&Hb6,&H31,&H79,&H92)
 
'Add Ldap connection settings key
sKeyPath = RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\"
oReg.CreateKey HKEY_CURRENT_USER, sKeyPath
oReg.SetBinaryValue HKEY_CURRENT_USER, _
     sKeyPath, "00033009", Array(&H20,0,0,0)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "000b6613", Array(0,0)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "000b6615", Array(0,0)
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3001", LDAPdisplayname
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d09", "EMABLT"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d0a", "BJABLR.DLL"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d0b", "ServiceEntry"
oReg.SetStringValue HKEY_CURRENT_USER, _
     sKeyPath , "001e3d13", "{6485D268-C2AC-11D1-AD3E-10A0C911C9C0}"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6600", LDAPserver
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6601", LDAPport
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6602", ""
oReg.SetStringValue HKEY_CURRENT_USER, _
     sKeyPath , "001e6603", LDAPsearchbase
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
     "001e6604", "(&(mail=*)(|(mail=%s*)" & _ 
     "(|(cn=%s*)(|(sn=%s*)(givenName=%s*)))))"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6605", "SMTP"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6606", "mail"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6607", "60"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6608", "100"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6609", "120"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660a", "15"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660b", ""
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660c", "OFF"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660d", "OFF"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660e", "NONE"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660f", "OFF"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6610", "postalAddress"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6611", "cn"
oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6612", "1"
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "001e67f1", Array(&H0a)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023615", _
     Array(&H50,&Ha7,&H0a,&H61,&H55,&Hde,_
     &Hd3,&H11,&H9d,&H60,&H00,_
     &Hc0,&H4f,&H4c,&H8e,&Hfa)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d01", _
     Array(&He8,&Hcb,&H48,&H86,&H9c,&H39,_
     &H54,&H45,&Had,&He1,&H3e,&H3c,_
     &H1c,&H80,&Hd1,&H54)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01026631", _
     Array(&H98,&H17,&H82,&H92,&H5b,&H43,_
     &H03,&H4b,&H99,&H5d,&H5c,_
     &Hc6,&H74,&H88,&H7b,&H34)
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "101e3d0f", _
     Array(&H02,&H00,&H00,&H00,&H0c,&H00,_
     &H00,&H00,&H17,&H00,&H00,&H00,_
     &H45,&H4d,&H41,&H42,&H4c,&H54,_
     &H2e,&H44,&H4c,&H4c,&H00,&H42,_
     &H4a,&H41,&H42,&H4c,&H52,&H2e,_
     &H44,&Hc,&H4c,&H00)
 
'Append to Backup Key for ldap types
sKeyPath = RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\"
oReg.getBinaryValue HKEY_CURRENT_USER,sKeyPath, "01023d01",Backup
Dim oldLength
oldLength = UBound(Backup)
ReDim Preserve Backup(oldLength+16)
Backup(oldLength+1) = &He8
Backup(oldLength+2) = &Hcb
Backup(oldLength+3) = &H48
Backup(oldLength+4) = &H86
Backup(oldLength+5) = &H9c
Backup(oldLength+6) = &H39
Backup(oldLength+7) = &H54
Backup(oldLength+8) = &H45
Backup(oldLength+9) = &Had
Backup(oldLength+10) = &He1
Backup(oldLength+11) = &H3e
Backup(oldLength+12) = &H3c
Backup(oldLength+13) = &H1c
Backup(oldLength+14) = &H80
Backup(oldLength+15) = &Hd1
Backup(oldLength+16) = &H54
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d01", Backup
 
 
'Append to Backup Key for ldap connection settings
sKeyPath = RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\"
oReg.getBinaryValue HKEY_CURRENT_USER,sKeyPath, "01023d0e",Backup
oldLength = UBound(Backup)
ReDim Preserve Backup(oldLength+16)
Backup(oldLength+1) = &H5c
Backup(oldLength+2) = &Hb9
Backup(oldLength+3) = &H3b
Backup(oldLength+4) = &H24
Backup(oldLength+5) = &Hff
Backup(oldLength+6) = &H71
Backup(oldLength+7) = &H07
Backup(oldLength+8) = &H41
Backup(oldLength+9) = &Hb7
Backup(oldLength+10) = &Hd8
Backup(oldLength+11) = &H3b
Backup(oldLength+12) = &H9c
Backup(oldLength+13) = &Hb6
Backup(oldLength+14) = &H31
Backup(oldLength+15) = &H79
Backup(oldLength+16) = &H92
oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d0e", Backup
 
 
'Delete Active Books List Key
sKeyPath = RegistryFolder & "9375CFF0413111d3B88A001" & _ 
           "04B2A6676\{ED475419-B0D6-11D2-8C3B-00104B2A6676}"
oReg.DeleteKey HKEY_CURRENT_USER, sKeyPath

Open in new window

0
Comment
Question by:benje02
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 24381119
Hi there.  In this version of your code, I have placed a If block around each addition to the registry, first checking if each key exists, and only if the key *does not* exist, does it create that key.

It's a bit different from your WScript.Quit idea, in that it allows program execution to continue, but if you wanted to use WScript.Quit, then I suggest you just place
WScript.Quit

into this section

objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\", arrSubKeys
If Err.Number = 0 Then
      On Error GoTo 0
      ' Do Nothing
Else

so that it becomes

objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\", arrSubKeys
If Err.Number = 0 Then
      On Error GoTo 0
      WScript.Quit
Else



Regards,

Rob.
const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\default:StdRegProv")
RegistryFolder = "Software\Microsoft\Windows NT\" & _ 
  "CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\"
 
LDAPdisplayname = "xyz"
LDAPserver = "directory.xyz.abc.com"
LDAPport = "389"
LDAPsearchbase = "ou=employees,ou=people,dc=abc,dc=com"
 
' Check if the key exists before creating it and writing values...
' If it does exist, we don't touch it.
On Error Resume Next
objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "e8cb48869c395445ade13e3c1c80d154\", arrSubKeys
If Err.Number = 0 Then
	On Error GoTo 0
	' Do Nothing
Else
	' If the error is non-zero, then the key does not exist, so we can now create it
	Err.Clear
	In Error GoTo 0
	'Add Ldap Type Key
	sKeyPath = RegistryFolder & "e8cb48869c395445ade13e3c1c80d154\"
	oReg.CreateKey HKEY_CURRENT_USER, sKeyPath 
	oReg.SetBinaryValue HKEY_CURRENT_USER, _
	     sKeyPath, "00033009", Array(0,0,0,0)
	oReg.SetBinaryValue HKEY_CURRENT_USER, _
	     sKeyPath, "00033e03", Array(&H23,0,0,0)
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e3001", "Microsoft LDAP Directory"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e3006", "Microsoft LDAP Directory"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e300a", "EMABLT.DLL"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e3d09", "EMABLT"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e3d13", "{6485D268-C2AC-11D1-AD3E-10A0C911C9C0}"
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, _
	    "01023d0c", Array(&H5c,&Hb9,&H3b,&H24, _
	    &Hff,&H71,&H07,&H41,&Hb7,&Hd8,_
	    &H3b,&H9c,&Hb6,&H31,&H79,&H92)
End If
 
' Check if the key exists before creating it and writing values...
' If it does exist, we don't touch it.
On Error Resume Next
objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\", arrSubKeys
If Err.Number = 0 Then
	On Error GoTo 0
	' Do Nothing
Else
	' If the error is non-zero, then the key does not exist, so we can now create it
	Err.Clear
	In Error GoTo 0
	'Add Ldap connection settings key
	sKeyPath = RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\"
	oReg.CreateKey HKEY_CURRENT_USER, sKeyPath
	oReg.SetBinaryValue HKEY_CURRENT_USER, _
	     sKeyPath, "00033009", Array(&H20,0,0,0)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "000b6613", Array(0,0)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "000b6615", Array(0,0)
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3001", LDAPdisplayname
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d09", "EMABLT"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d0a", "BJABLR.DLL"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e3d0b", "ServiceEntry"
	oReg.SetStringValue HKEY_CURRENT_USER, _
	     sKeyPath , "001e3d13", "{6485D268-C2AC-11D1-AD3E-10A0C911C9C0}"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6600", LDAPserver
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6601", LDAPport
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6602", ""
	oReg.SetStringValue HKEY_CURRENT_USER, _
	     sKeyPath , "001e6603", LDAPsearchbase
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , _
	     "001e6604", "(&(mail=*)(|(mail=%s*)" & _ 
	     "(|(cn=%s*)(|(sn=%s*)(givenName=%s*)))))"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6605", "SMTP"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6606", "mail"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6607", "60"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6608", "100"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6609", "120"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660a", "15"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660b", ""
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660c", "OFF"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660d", "OFF"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660e", "NONE"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e660f", "OFF"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6610", "postalAddress"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6611", "cn"
	oReg.SetStringValue HKEY_CURRENT_USER, sKeyPath , "001e6612", "1"
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "001e67f1", Array(&H0a)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023615", _
	     Array(&H50,&Ha7,&H0a,&H61,&H55,&Hde,_
	     &Hd3,&H11,&H9d,&H60,&H00,_
	     &Hc0,&H4f,&H4c,&H8e,&Hfa)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d01", _
	     Array(&He8,&Hcb,&H48,&H86,&H9c,&H39,_
	     &H54,&H45,&Had,&He1,&H3e,&H3c,_
	     &H1c,&H80,&Hd1,&H54)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01026631", _
	     Array(&H98,&H17,&H82,&H92,&H5b,&H43,_
	     &H03,&H4b,&H99,&H5d,&H5c,_
	     &Hc6,&H74,&H88,&H7b,&H34)
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "101e3d0f", _
	     Array(&H02,&H00,&H00,&H00,&H0c,&H00,_
	     &H00,&H00,&H17,&H00,&H00,&H00,_
	     &H45,&H4d,&H41,&H42,&H4c,&H54,_
	     &H2e,&H44,&H4c,&H4c,&H00,&H42,_
	     &H4a,&H41,&H42,&H4c,&H52,&H2e,_
	     &H44,&Hc,&H4c,&H00)
End If
 
' Check if the key exists before creating it and writing values...
' If it does exist, we don't touch it.
On Error Resume Next
objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\", arrSubKeys
If Err.Number = 0 Then
	On Error GoTo 0
	' Do Nothing
Else
	' If the error is non-zero, then the key does not exist, so we can now create it
	Err.Clear
	In Error GoTo 0
	'Append to Backup Key for ldap types
	sKeyPath = RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\"
	oReg.getBinaryValue HKEY_CURRENT_USER,sKeyPath, "01023d01",Backup
	Dim oldLength
	oldLength = UBound(Backup)
	ReDim Preserve Backup(oldLength+16)
	Backup(oldLength+1) = &He8
	Backup(oldLength+2) = &Hcb
	Backup(oldLength+3) = &H48
	Backup(oldLength+4) = &H86
	Backup(oldLength+5) = &H9c
	Backup(oldLength+6) = &H39
	Backup(oldLength+7) = &H54
	Backup(oldLength+8) = &H45
	Backup(oldLength+9) = &Had
	Backup(oldLength+10) = &He1
	Backup(oldLength+11) = &H3e
	Backup(oldLength+12) = &H3c
	Backup(oldLength+13) = &H1c
	Backup(oldLength+14) = &H80
	Backup(oldLength+15) = &Hd1
	Backup(oldLength+16) = &H54
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d01", Backup
End If 
 
' Check if the key exists before creating it and writing values...
' If it does exist, we don't touch it.
On Error Resume Next
objReg.EnumKey HKEY_CURRENT_USER, RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\", arrSubKeys
If Err.Number = 0 Then
	On Error GoTo 0
	' Do Nothing
Else
	' If the error is non-zero, then the key does not exist, so we can now create it
	Err.Clear
	In Error GoTo 0
	'Append to Backup Key for ldap connection settings
	sKeyPath = RegistryFolder & "9207f3e0a3b11019908b08002b2a56c2\"
	oReg.getBinaryValue HKEY_CURRENT_USER,sKeyPath, "01023d0e",Backup
	oldLength = UBound(Backup)
	ReDim Preserve Backup(oldLength+16)
	Backup(oldLength+1) = &H5c
	Backup(oldLength+2) = &Hb9
	Backup(oldLength+3) = &H3b
	Backup(oldLength+4) = &H24
	Backup(oldLength+5) = &Hff
	Backup(oldLength+6) = &H71
	Backup(oldLength+7) = &H07
	Backup(oldLength+8) = &H41
	Backup(oldLength+9) = &Hb7
	Backup(oldLength+10) = &Hd8
	Backup(oldLength+11) = &H3b
	Backup(oldLength+12) = &H9c
	Backup(oldLength+13) = &Hb6
	Backup(oldLength+14) = &H31
	Backup(oldLength+15) = &H79
	Backup(oldLength+16) = &H92
	oReg.SetBinaryValue HKEY_CURRENT_USER, sKeyPath, "01023d0e", Backup
End If 
 
'Delete Active Books List Key
sKeyPath = RegistryFolder & "9375CFF0413111d3B88A001" & _ 
           "04B2A6676\{ED475419-B0D6-11D2-8C3B-00104B2A6676}"
On Error Resume Next
oReg.DeleteKey HKEY_CURRENT_USER, sKeyPath
Err.Clear
On Error GoTo 0

Open in new window

0
 

Author Comment

by:benje02
ID: 24386099
I added this and it works as did your suggestion. Thanks

sKeyPath = RegistryFolder & "5cb93b24ff710741b7d83b9cb6317992\"
oReg.GetStringValue HKEY_CURRENT_USER, sKeyPath, "001e3001",dwValue
If IsNull(curBonus) Then
      'MsgBox "nap!"
Else
      If dwValue = "xyz" then
            'MsgBox dwValue
            wscript.quit
      Else
            'MsgBox "nap!"
      End If
End If      
0
 

Author Comment

by:benje02
ID: 24386153
I think I screwed up and clicked the wrong button. How do I award the points to Rob?
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advice in Xamarin 21 79
RUNRMTCMD from AS/400 12 47
VB Script: restart service function 30 36
VBscript: send notification based on list.csv v2 (folder, destination) 13 24
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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