?
Solved

Wscript - Check machine OU membership

Posted on 2004-09-22
6
Medium Priority
?
584 Views
Last Modified: 2008-03-10
We run a single login script in our W2K environment at the top level for users, this script performs various actions depending upon group memberships (map drives etc). I need to add a section to the script to perform the following actions:

Check if the user logging on is a member of the Test OU within user departments.
If so ensure the machine they are logging on to is a member of the Desktops\Test OU.
If the machine is from any other OU the users should be logged off.

Here's what I've tried, but it seems to log everyone off, no matter what. Help greatly appreciated. Variables are set further up the script for DIM settings, domain name etc.

'Don't allow Test users to log on to non test machines

      Set sMachineOU = GetObject ("LDAP://cn="&sComputerName&",ou=Test,ou=Desktops,DC="&sDomain&",DC=intra")
            bFoundTestMachine = TRUE
            If Err.Number = E_ADS_OBJECT_NOT_FOUND Then
                  bFoundTestMachine = FALSE
            end if
            
      Set oTestUser = GetObject ("LDAP://cn="&sUserName&",ou=Test,ou=Departments,DC="&sDomain&",DC=intra")
            bFoundTestUser = TRUE
            If Err.Number = E_ADS_OBJECT_NOT_FOUND Then
                  bFoundTestUser = FALSE
            end if
      
      If bFoundTestUser = TRUE and bFoundTestMachine = FALSE Then
                   sRunner = oshell.run ("Nologon.exe",false)
                  WScript.Sleep 5000
                        sRunner = oshell.run ("logoff.exe /N /F", HIDE_WINDOW ,TRUE)
                  wscript.quit(1)      
          end if
      Err.Clear
0
Comment
Question by:youre1m
[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
  • 3
  • 3
6 Comments
 
LVL 6

Author Comment

by:youre1m
ID: 12121314
PS. Nologon.exe is a self written .exe that displays a message explaining to the user what is happening, stored within netlogon share.
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 12121999
youre1m
Try this:

'Don't allow Test users to log on to non test machines

     Set sMachineOU = GetObject ("LDAP://cn="&sComputerName&",ou=Test,ou=Desktops,DC="&sDomain&",DC=intra")
          bFoundTestMachine = TRUE
          If Err.Number <> 0 bFoundTestMachine = FALSE
          end if
         
     Set oTestUser = GetObject ("LDAP://cn="&sUserName&",ou=Test,ou=Departments,DC="&sDomain&",DC=intra")
          bFoundTestUser = TRUE
          If Err.Number <> 0 then bFoundTestUser = FALSE
          end if
     
     If bFoundTestUser = TRUE and bFoundTestMachine = FALSE Then
                sRunner = oshell.run ("Nologon.exe",false)
               WScript.Sleep 5000
                        sRunner = oshell.run ("logoff.exe /N /F", HIDE_WINDOW ,TRUE)
               wscript.quit(1)    
          end if
     Err.Clear





Cheers

JamesDS
0
 
LVL 6

Author Comment

by:youre1m
ID: 12319291
James,

Sorry about the long delay, I've been working on something else for a while.

I have tried to use your script but get an error message stating a "then" was expected on the line I have put a * next to below. I have tried adding a then but still get the same error message. Any ideas??

Set sMachineOU = GetObject ("LDAP://cn="&sComputerName&",ou=Test,ou=Desktops,DC="&sDomain&",DC=intra")
          bFoundTestMachine = TRUE
          If Err.Number <> 0 bFoundTestMachine = FALSE *
          end if
         
     Set oTestUser = GetObject ("LDAP://cn="&sUserName&",ou=Test,ou=Departments,DC="&sDomain&",DC=intra")
          bFoundTestUser = TRUE
          If Err.Number <> 0 then bFoundTestUser = FALSE
          end if
     
     If bFoundTestUser = TRUE and bFoundTestMachine = FALSE Then
                sRunner = oshell.run ("Nologon.exe",false)
               WScript.Sleep 5000
                        sRunner = oshell.run ("logoff.exe /N /F", HIDE_WINDOW ,TRUE)
               wscript.quit(1)    
          end if
     Err.Clear
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 16

Accepted Solution

by:
JamesDS earned 1500 total points
ID: 12320558
youre1m
Oops, missing that "then" statement!
Try this

Set sMachineOU = GetObject ("LDAP://cn="&sComputerName&",ou=Test,ou=Desktops,DC="&sDomain&",DC=intra")
          bFoundTestMachine = TRUE
          If Err.Number <> 0 then bFoundTestMachine = FALSE
          end if
         
     Set oTestUser = GetObject ("LDAP://cn="&sUserName&",ou=Test,ou=Departments,DC="&sDomain&",DC=intra")
          bFoundTestUser = TRUE
          If Err.Number <> 0 then bFoundTestUser = FALSE
          end if
     
     If bFoundTestUser = TRUE and bFoundTestMachine = FALSE Then
                sRunner = oshell.run ("Nologon.exe",false)
               WScript.Sleep 5000
                        sRunner = oshell.run ("logoff.exe /N /F", HIDE_WINDOW ,TRUE)
               wscript.quit(1)    
          end if
     Err.Clear

Cheers

JamesDS
0
 
LVL 6

Author Comment

by:youre1m
ID: 12337298
Ok, below is what I've found that works, but you can have the points for effort, couldn't get your solution to work.

'Determine whether user is a test User

bTestUser = FALSE

If strUserOU = "test" then
      bTargetuser = TRUE
end if

'Determine Whether machine is in Target Training machine

bTargetMachine = FALSE
If strCompOU = "test machine" then
      bTestMachine = TRUE
end if

If bTestuser = TRUE and bTestMachine = FALSE then
      sRunner = oshell.run ("Nologon.exe",false)
                  WScript.Sleep 5000
                        sRunner = oshell.run ("logoff.exe /N /F", HIDE_WINDOW ,TRUE)
                  wscript.quit(1)
end if
0
 
LVL 16

Expert Comment

by:JamesDS
ID: 12337556
youre1m

Odd that it fails for you, it works fine here when I mod it for my domain.
Nevertheless, thanks for the points and i'm glad you got it sorted.

Cheers

JamesDS
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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
"Any files you do not have backed up in at least two [other] places are files you do not care about."
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 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