Solved

Conditional Logic If registry key exist

Posted on 2006-10-25
10
1,220 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
[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
  • 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 28

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 28

Expert Comment

by:Ark
ID: 17809043
Oops, sorry, Debug.print should be wscript.Echo
0
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!

 
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 28

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
 

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 28

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

730 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