Announcement

Collapse
No announcement yet.

How to prevent logon script execiution on some machine?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to prevent logon script execiution on some machine?

    Hi, everybody!!
    I need to prevent logon script of domain user from execution on some domain client computer. The login script configured to run from user profile (see attached image). I know that I can configure it to run using GPO, WMI filters an so on, but my question is: if it possible to change the code of bat file, so prevent execution of this logon script on some machine?
    Here is logon script code:
    Code:
    %windir%\system32\wscript.exe //NoLogo //T:180 "%~dp0\MMP.vbs"

    I try to use IF /IF NOT command, but it doesn't work. May be it because of syntax error...
    Code:
     
    IF NOT (%COMPUTERNAME%) == (LONDON) GOTO NEXT
    %windir%\system32\wscript.exe //NoLogo //T:180 "%~dp0\MMP.vbs"
    Any help is very appreciated!!
    Attached Files
    Last edited by igor7; 27th January 2009, 11:40.

  • #2
    Re: How to prevent logon script execiution on some machine?

    Are there many computers that need to be excluded in the batch for running the vbscript?

    If there are only a few computers, you can try something like
    Code:
    (Set cmdstr=%windir%\system32\wscript.exe //NoLogo //T:180 "%~dp0\MMP.vbs")
    (Set exclcomp=computer1name,computer2name,computer3name,computer4name,computer5name)
    
    For %%* in (%exclcomp%) Do If /i %computername% NEQ %%* %cmdstr%
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: How to prevent logon script execiution on some machine?

      Rems, thank you!
      This script should be prevented from running just on one client machine. I will try it later and let you know if it’s working.
      BTW, I'm just interested, it can't be done with IF/IF NOT command?
      Last edited by igor7; 27th January 2009, 16:54.

      Comment


      • #4
        Re: How to prevent logon script execiution on some machine?

        Originally posted by igor7 View Post
        BTW, I'm just interested, it can't be done with IF/IF NOT command?
        Sure it can. Rems' loop is just a nice way to check multiple values. Consider that:
        Code:
        Set exclcomp=computer1name,computer2name,computer3name,computer4name,computer5name)
        
        For %%* in (%exclcomp%) Do If /i %computername% NEQ %%* %cmdstr%
        Can be written as:
        Code:
        if /i %computername% NEQ computer1name %cmdstr%
        if /i %computername% NEQ computer2name %cmdstr%
        if /i %computername% NEQ computer3name %cmdstr%
        if /i %computername% NEQ computer4name %cmdstr%
        if /i %computername% NEQ computer5name %cmdstr%
        It should be pretty clear that the first solution is much more clear and easier to maintain.

        You could use a flag file and "if not exist %flagfile%" -structure. This is the preferred way if you have lots of computers to manage and can't use group policy or third-party management tools.

        I guess your script didn't work, as the if statement does case sensitive string comparison. Use the /i switch for case insensitive comparisons. In addition, the computer's name is likely to be LONDON instead of (LONDON). Parenthesis mess up the comparison too.

        -vP

        Comment


        • #5
          Re: How to prevent logon script execiution on some machine?

          Originally posted by vonPryz View Post
          I guess your script didn't work, as the if statement does case sensitive string comparison. Use the /i switch for case insensitive comparisons. In addition, the computer's name is likely to be LONDON instead of (LONDON). Parenthesis mess up the comparison too.
          Here it is!! You are right!! I used /i switch and it working. Big thanks!!The working code is:
          Code:
           
          IF NOT /i %COMPUTERNAME% == LONDON GOTO NEXT
          %windir%\system32\wscript.exe //NoLogo //T:180 "%~dp0\MMP.vbs"

          Comment

          Working...
          X