Solved

Conditional Logic If registry key exist

Posted on 2006-10-25
10
1,212 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 59
VBA/SQL - Connect to SQL server and pull data 4 108
VBA: Select SQL query based on a config Sheet v2 11 44
Set email body to html using vbscript 6 41
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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