Solved

Conditional Logic If registry key exist

Posted on 2006-10-25
10
1,201 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now