Solved

Conditional Logic If registry key exist

Posted on 2006-10-25
10
1,208 Views
Last Modified: 2009-07-29
In a login script, I need to condition logic to read the conditions of 2 registry values, I have it in Kix but am trying to convert that over to vbscript.

I have this so far:

Dim WSHShell, RegKey, Session, WSHNetwork

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

RegKey = "HKCU\Volatile Environment\SESSIONNAME"

Session = WSHShell.RegRead(RegKey & "")
If Session <> "Console" Then
WScript.Quit

Else

That part works fine, but I want it to condition first checking the OS version, if >= 5.1 AND the above to quit

In Kix, it looks like this:

If @DOS >= 5.1 AND ReadValue("Volatile Environment", "SESSIONNAME") <> "Console"
    GoTo "END"
EndIf
0
Comment
Question by:rtmcmullen
  • 4
  • 3
  • 3
10 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 17808965
dim strComputer
Dim WSHShell, RegKey, Session, WSHNetwork
strComputer = "."

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

RegKey = "HKCU\Volatile Environment\SESSIONNAME"
Session = WSHShell.RegRead(RegKey & "")

For Each objItem in colItems
   
if objItem.version  >= 5.1 AND session <> "Console"

WScript.Quit

else

'do what yo want here
 
end if

Next
0
 
LVL 27

Expert Comment

by:Ark
ID: 17809041
if objItem.version  >= 5.1 AND session <> "Console"

WScript.Quit

else
   'Debug.Print "Where did you get WMI ??? :)"
end if
0
 
LVL 27

Expert Comment

by:Ark
ID: 17809043
Oops, sorry, Debug.print should be wscript.Echo
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 17809234
Forget the THEN in the if statement... HEHEHE!

if objItem.version  >= 5.1 AND session <> "Console"  then '<------ forget this

WScript.Quit

else

'do what yo want here
 
end if
0
 
LVL 27

Accepted Solution

by:
Ark earned 250 total points
ID: 17809305
You can use following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\ProductVersion

5.0 = Win2K Server
5.1 = WinXP
5.2 = Win2003

And HKLM\System\CurrentControlSet\Control\ProductOptions\ProductSuite = "Terminal Server" for NT4 TSE
0
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.

 

Author Comment

by:rtmcmullen
ID: 17810588
I'm getting the following when running that;

(15, 1) Microsoft VBScript runtime error: Type mismatch: '[string: "5.2.3790"]'
0
 

Author Comment

by:rtmcmullen
ID: 17814403
Had to quote around OS ver.. thanks JackOfPH
0
 
LVL 27

Expert Comment

by:Ark
ID: 17816091
Seems rtmcmullen accepted JackOfPH answer but accidently press wrong button
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 17817706
I Think so...
0
 

Author Comment

by:rtmcmullen
ID: 17820707
Sorry about that JackOfPH , I intended that to go to you
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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now