?
Solved

Conditional Logic If registry key exist

Posted on 2006-10-25
10
Medium Priority
?
1,237 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
Independent Software Vendors: 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 750 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

752 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