Announcement

Collapse
No announcement yet.

Script for Popup Box to Accept Terms on Windows Login

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

  • Script for Popup Box to Accept Terms on Windows Login

    I'm looking to create a pop-up box with my company's Network Terms & Conditions on a user's first login to the domain. In this box I want the user to have a choice to either accept or decline the terms. If the user declines, I would like for windows to log the user off.

    How should I go about this?

    Thanks!

  • #2
    Re: Script for Popup Box to Accept Terms on Windows Login

    Did you manage to find a solution?

    Comment


    • #3
      Re: Script for Popup Box to Accept Terms on Windows Login

      Can do it through AD if you like, dont think that there is much scope for a lot of text but you can at least flash up a warning stating that by logging on you accept the terms an conditions etc etc

      Default Domain Policy: Computer Configuration/Windows Settings/Security Settings/Local Policies/Security Options. Then Interactive logon: Message text... and Interactive logon: Message title...

      Comment


      • #4
        Re: Script for Popup Box to Accept Terms on Windows Login

        Use a logon script and flag file or registry key. When the logon script runs, it checks whether the flag is present. If not, it will show a message to the user. If user accepts, set the flag file. If user declines, just run logoff.exe.

        A VBScript soluiton works quite nicely. Use a msgbox and look for return values.

        -vP

        Comment


        • #5
          Re: Script for Popup Box to Accept Terms on Windows Login

          You can use this code as logon script:

          Code:
           
          <html>
          <head>
          <title>Logon policy acceptance script</title>
          <HTA:APPLICATION
               ApplicationName="Logon HTA"
               SingleInstance="Yes"
               WindowsState="Normal"
               Scroll="No"
               SCROLLFLAT="No"
               Navigable="No"
               SysMenu="No"
               Caption="No"
               Select=яes"
               MaximizeButton="No"
               MinimizeButton="No"
               BORDER = "thick"
               INNERBORDER = "yes"
               SHOWINTASKBAR="No"
               CONTEXTMENU="No"
               Icon = "%SystemRoot%\Explorer.exe">
          ></HEAD>
          <SCRIPT LANGUAGE="VBScript">
            sHorizontal = "500"
            sVertical = "600"
            cnt = 60 'seconds before auto logoff
            Set objWMIService = GetObject _
               ("winmgmts:root\cimv2")
            set objShell = CreateObject _
               ("WScript.Shell")
            Set Fso = CreateObject("Scripting.FileSystemObject")
            Set tempfolder = Fso.GetSpecialFolder(2)
            supportingcode = tempfolder & "\" & Fso.GetTempName
          Sub Window_OnLoad
            'Size Window
            Window.resizeTo sHorizontal,sVertical
            'Center window
            Set colItems = objWMIService.ExecQuery _
               ("Select * From Win32_DesktopMonitor",,48)
            For Each objItem In colItems
              sWidth = objItem.ScreenWidth
              sHeight = objItem.ScreenHeight
              If sWidth > intHorizontal _
                then intHorizontal = sWidth
              If sHeight > intVertical _
                then intVertical = sHeight
            Next
            intLeft = (intHorizontal - sHorizontal) /2
            intTop = (intVertical - sVertical) /2
            Window.moveTo intLeft, intTop
            'default window content
            window.location.href="#Top"
            'iTimerID = window.setInterval("ShowSplash", 15000)
            iTimerID = window.setInterval("y", 1000, "VBScript")
          End Sub
          function y()
             Text1.innerHTML= "Time Left To Make A Decision: " & Cnt
             cnt = cnt - 1
             If cnt < 0 then call logoff
          end function
          Sub reloadHTA()
             location.reload True
          End Sub
          Sub ShowSplash
             Splash.Style.Display = "None"
          End Sub
          Function HTA_Sleep(mSec)
            strRun = supportingcode & ".vbs"
            With Fso.OpenTextFile(strRun, 2, true)
              .WriteLine "On Error Resume Next"
              .WriteLine "Wscript.sleep wScript.Arguments(0)"
              .close
              strCommand = "cscript.exe //NoLogo " & strRun & " " & mSec
              objShell.run(strCommand), 0, True
              Fso.DeleteFile(strRun)
            End With
          End Function
          '-------------------------------------------------------------------
          Sub DeclineScript( oBtt )
             sAction = "LogOff"
             oBtt.style.color            = "white"
             oBtt.style.backgroundcolor  = "red"
             oBtt.style.fontstyle        = "italic"
             call logoff
          End Sub
          Sub logoff
            If Not sAction = "LogOn" Then
              session = objShell.ExpandEnvironmentStrings("%sessionname%")
              If UCase(session) = UCase("Console") Then session = Empty
              strCommand = "%comspec% /c %WinDir%\system32\logoff.exe " & session
              objShell.Run(strCommand),0 ,True
              Cleanup
            End If
          End Sub
          Sub AcceptScript( oBtt )
             sAction = "LogOn"
             oBtt.style.color            = "white"
             oBtt.style.backgroundcolor  = "green"
             oBtt.style.fontstyle        = "italic"
             HTA_Sleep(100)
             'run vbScript from within this script:
             ' strVBS = "\\server\share\folder\file.vbs"
             ' objShell.run("cscript.exe //NoLogo " & strVBS), 0, True
             Cleanup
          End Sub
          Sub Cleanup
             Set objWMIService = Nothing
             set objShell = Nothing
             Set Fso = Nothing
             Set tempfolder = Nothing
             Self.Close()
          End Sub
          </SCRIPT>
          <!-- TABLE STYLE NORMAL--> 
            <STYLE type="text/css">  
              Table.Normal
              { 
                font: 8.25pt Verdana;
                color:#000080;
                font-weight:bold;
                filter:progid:DXImageTransform.Microsoft.Gradient
                (GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');
                padding-top:1;
                padding-bottom:1;
                Text-Align:;
                vertical-align:;
              }
            </STYLE>
           
          <!-- TD STYLE MENUNORMAL -->
            <STYLE type="text/css">  
              TD.MenuNormal
              { 
                font: 8.25pt Verdana;
                color:#000080;
                font-weight:bold;
                filter:progid:DXImageTransform.Microsoft.Gradient
                (GradientType=0,StartColorStr='#eeeeee',EndColorStr='#5e9ab9');
                padding-top:1;
                padding-bottom:1;
                Text-Align:;
                vertical-align:;
                cursor:Hand;
              }
            </STYLE>
          <!-- BODY STYLE NORMAL--> 
            <STYLE type="text/css">  
              Body.Normal
              { 
                font: 10.25pt Verdana;
                color:#000080;
                font-weight:bold;
                filter:progid:DXImageTransform.Microsoft.Gradient
                (GradientType=0,StartColorStr='#86cceb',endColorStr='#5589ab');
                padding-top:1;
                padding-bottom:1;
                Text-Align:;
              }
            </STYLE>
           
          <Body Class='Normal'>
          <Center>
          <Table Class=Normal Width='270' height='30'>
              <TD Class=MenuNormal onClick="reloadHTA()">
               &nbsp;&nbsp;<Span ID="Text1">Countdown
          </Span></TD></Table>
           
          <DIV id="Splash" STYLE="Height:200;Width:400;Border:0.5mm solid green;
           font:14pt arial;
           filter:progid:DXImageTransform.Microsoft.Gradient
          (GradientType=0, StartColorStr='#5589ab', EndColorStr='#86cceb')
          progid:DXImageTransform.Microsoft.dropshadow(OffX=0, OffY=0, 
                  Color='green', Positive='true')">
          <br>
          If you want use this computer<br>
          You need to accept following rules<br><br>
          <font size="2">© 1985-2005 Microsoft Corporation. All rights reserved.</font>
          <br></CENTER><br><br>
          <ul>
            <li>ewgsh hhxd rv hv dbvl edr hwef<br>
            ssv vdrjsrvjeje jeyjv</li>
            <li>rth rgb ughbh ht jh 456 brjtj</li>
            <li>tjt fgcy byj bbby v a ryhu</li>
            <li>itui gb gj 777</li>
            <li>tuktu hfetygjf gg ryjgyjgrthggyj 8</li>
            <li>ewgsh hhxd rv hv dbvl edr hwef</li>
            <li>rth rgb ughbh ht jh 456 brjtj</li>
            <li>tjt fgcy byj bbby v a ryhu</li>
            <li>itui gb gj 777</li>
            <li>tuktu hfetygjf gg ryjgyjgrthggyj 8</li>
            <li>rgdv</li>
          </ul><br>
          </DIV>
          <center><br><br>
          <Input type="button" value="   Accept   " onClick="AcceptScript Me"> &nbsp;
          <Input type="button" value="  Decline  "   onClick="DeclineScript Me">
          </center>
          </body>
          </html>
          Save it as "Logon policy acceptance.hta" and assign it as logon script for company users.

          Comment


          • #6
            Re: Script for Popup Box to Accept Terms on Windows Login

            Originally posted by igor7 View Post
            You can use this code as logon script:

            [...]

            Save it as "Logon policy acceptance.hta" and assign it as logon script for company users.
            You cannot assign HTA applications directly as logonscript, it'll need to be invoked through a logon -batch, -vbscript or -exe. Or else copy the file to the Start folder in the users profile path.

            You can lauch HTA fom within a batch or from within a vbscript,
            OR, you could also try to specify "%SystemRoot%\System32\mshta.exe" as the name of the logonscript and provide the "\\server\share\file.hta" UNC path (included the quotes) as the Script Parameters.

            Whether you create the popup with vbs (vonPryz's suggestion) or, with HTA (igor7's suggestion) you'll probably also want to Enable the policy "Run logon scripts Synchronously". But then make sure that the logon script that starts the HTA script should now always wait for the mshta.exe task to return.
            (Therefore copying the hta file to the Start folder in the user's profile path was actually not a good solution because this way the script will still be loaded Asynchronously)

            If "Run logon scripts Synchronously" for some reason cannot be enabled then alternatively you could instead of lauch it from within a logon script use a computer startup script that is copying the hta file to the local computers (ie the c:\windows folder). The startup script then also add the following entry to the registry on that computer:
            Code:
            key:
            HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
            
            ValueName:
            !AcceptCompanyTerms   (in this scenario the name of the entry must be prefixed with an exclamation point to defer deletion of the value until after the command has been completed)
            
            Type: REG_SZ
            
            Value:
            mshta.exe "%windir%\AcceptCompanyTerms.HTA"
            
            NOTES !
             The RunOnce key under HKLM is an exception to all other "auto Run"-keys that
             can be found in the registry even to the RunOnce key that can be found under
             HKCU. Only the RunOnce key under HKLM and its entries are loaded
             synchronously (before explorer.exe will be loaded) in an undefined order
             when a user logs-on.
             ** One problem with the RunOnce solution is that, the popup message will
             re-appear when a user logs-on after a previous user was forced logged-off
             because s/he had Decline the terms, BUT when the previous user had accepted
             the terms and later on logs-off the computer instead of shutting it down and a
             new user logs-on to that computer s/he will not get the pop-up!!. Therefore for
             this scenario, the hta can best be invoked throug a user logon script or exe.
            The original HTA script comes from this post
            http://forums.petri.com/showthread.p...3619#post83619
            save the hta-script with a HTA extension and go ahead double click on it to see how it runs.

            The sample below is the same script with a little modification on how the window will be centered on the screen.
            AcceptCompanyTerms.HTA
            Code:
            <!-- Author: Remco Simons [NL], 21st October 2007
                 forums.petri.com/showthread.php?p=83619#post83619 -->
            
            <html>
            
            <head>
            <title>Logon policy acceptance Screen</title>
            <HTA:APPLICATION
                 ApplicationName="Logon HTA"
                 SingleInstance="Yes"
                 WindowsState="Normal"
                 Scroll="No"
                 SCROLLFLAT="No"
                 Navigable="No"
                 SysMenu="No"
                 Caption="No"
                 Select=˙es"
                 MaximizeButton="No"
                 MinimizeButton="No"
                 BORDER = "thick"
                 INNERBORDER = "yes"
                 SHOWINTASKBAR="No"
                 CONTEXTMENU="No"
                 Icon = "%SystemRoot%\Explorer.exe">
            ></HEAD>
            
            <SCRIPT LANGUAGE="VBScript">
               'Size of Window
              sHorizontal = "500"
              sVertical = "600"
            
              cnt = 60 'seconds before auto logoff
              
              Dim objWMIService, objShell, Fso
              Dim supportingcode, tempfolder
            
            Sub Window_OnLoad
               Window.resizeTo:Window.moveTo
               'Center Window on the monitor
               With createobject("internetexplorer.application")
                 .navigate2"about:blank"
                 With .document.parentWindow.screen
                   intLeft = (.width - sHorizontal) /2
                   intTop = (.height - sVertical) /2
                 End with
                 .quit '!!!
               End with
               'make visible
               Window.moveTo intLeft, intTop
               Window.resizeTo sHorizontal,sVertical
            
               Set objWMIService = GetObject _
                 ("winmgmts:root\cimv2")
               set objShell = CreateObject _
                 ("WScript.Shell")
               Set Fso = CreateObject("Scripting.FileSystemObject")
               Set tempfolder = Fso.GetSpecialFolder(2)
               supportingcode = tempfolder & "\" & Fso.GetTempName
            
               'default window content
               window.location.href="#Top"
               'iTimerID = window.setInterval("ShowSplash", 5000)
               iTimerID = window.setInterval("y", 1000, "VBScript")
            End Sub
            
            function y()
               Text1.innerHTML= "Time Left Before auto-Logging Off : " & Cnt
               cnt = cnt - 1
               If cnt < 0 then call logoff
            end function
            
            Sub reloadHTA()
               location.reload True
            End Sub
            
            Sub ShowSplash
               Splash.Style.Display = "None"
            End Sub
            
            Function HTA_Sleep(mSec)
              strRun = supportingcode & ".vbs"
               With Fso.OpenTextFile(strRun, 2, true)
                 .WriteLine "On Error Resume Next"
                 .WriteLine "Wscript.sleep wScript.Arguments(0)"
                 .close
                 strCommand = "cscript.exe //NoLogo " & strRun & " " & mSec
                 objShell.run(strCommand), 0, True
                 Fso.DeleteFile(strRun)
               End With
            End Function
            
            '-------------------------------------------------------------------
            Sub DeclineScript( oBtt )
               sAction = "LogOff"
               oBtt.style.color            = "white"
               oBtt.style.backgroundcolor  = "red"
               oBtt.style.fontstyle        = "italic"
               call logoff
            End Sub
            
            Sub logoff
               If Not sAction = "LogOn" Then
                 session = objShell.ExpandEnvironmentStrings("%sessionname%")
                 If UCase(session) = UCase("Console") Then session = Empty
                 strCommand = "%comspec% /c %WinDir%\system32\logoff.exe " & session
                 objShell.Run(strCommand),0 ,True
                 Cleanup
               End If
            End Sub
            
            Sub AcceptScript( oBtt )
               sAction = "LogOn"
               oBtt.style.color            = "white"
               oBtt.style.backgroundcolor  = "green"
               oBtt.style.fontstyle        = "italic"
               HTA_Sleep(100)
               'run vbScript from within this script:
               ' strVBS = "\\server\share\folder\file.vbs"
               ' objShell.run("cscript.exe //NoLogo " & strVBS), 0, True
               Cleanup
            End Sub
            
            Sub Cleanup
               Set objWMIService = Nothing
               set objShell = Nothing
               Set Fso = Nothing
               Set tempfolder = Nothing
               Self.Close()
            End Sub
            
            </SCRIPT>
            
            <!-- TABLE STYLE NORMAL--> 
              <STYLE type="text/css">  
                Table.Normal
                { 
                  font: 8.25pt Verdana;
                  color:#000080;
                  font-weight:bold;
                  filter:progid:DXImageTransform.Microsoft.Gradient
                  (GradientType=0,StartColorStr='#E9E9E9',EndColorStr='#9E9E9E');
                  padding-top:1;
                  padding-bottom:1;
                  Text-Align:;
                  vertical-align:;
                }
              </STYLE>
              
            <!-- TD STYLE MENUNORMAL -->
              <STYLE type="text/css">  
                TD.MenuNormal
                { 
                  font: 8.25pt Verdana;
                  color:#000080;
                  font-weight:bold;
                  filter:progid:DXImageTransform.Microsoft.Gradient
                  (GradientType=0,StartColorStr='#eeeeee',EndColorStr='#5e9ab9');
                  padding-top:1;
                  padding-bottom:1;
                  Text-Align:;
                  vertical-align:;
                  cursor:Hand;
                }
              </STYLE>
            
            <!-- BODY STYLE NORMAL--> 
              <STYLE type="text/css">  
                Body.Normal
                { 
                  font: 10.25pt Verdana;
                  color:#000080;
                  font-weight:bold;
                  filter:progid:DXImageTransform.Microsoft.Gradient
                  (GradientType=0,StartColorStr='#86cceb',endColorStr='#5589ab');
                  padding-top:1;
                  padding-bottom:1;
                  Text-Align:;
                }
              </STYLE>
            
            
            <Body Class='Normal'>
            <Center>
            <Table Class=Normal Width='270' height='30'>
                <TD Class=MenuNormal onClick="reloadHTA()">
                 &nbsp;&nbsp;<Span ID="Text1">Countdown
            </Span></TD></Table>
            
            
            <DIV id="Splash" STYLE="Height:200;Width:400;Border:0.1mm solid black;
             font:14pt arial;
             filter:progid:DXImageTransform.Microsoft.Gradient
            (GradientType=0, StartColorStr='#5589ab', EndColorStr='#86cceb')
            progid:DXImageTransform.Microsoft.dropshadow(OffX=10, OffY=10, 
                    Color='gray', Positive='true')">
            <br>
            A Sample HTA<br>
            The Microsoft Scripting Guys<br><br>
            <font size="2">Copyright 2005 Microsoft Corporation. All rights reserved.</font>
            <br></CENTER><br><br>
            <ul>
              <li>ewgsh hhxd rv hv dbvl edr hwef<br>
              ssv vdrjsrvjeje jeyjv</li>
              <li>rth rgb ughbh ht jh 456 brjtj</li>
              <li>tjt fgcy byj bbby v a ryhu</li>
              <li>itui gb gj 777</li>
              <li>tuktu hfetygjf gg ryjgyjgrthggyj 8</li>
              <li>ewgsh hhxd rv hv dbvl edr hwef</li>
              <li>rth rgb ughbh ht jh 456 brjtj</li>
              <li>tjt fgcy byj bbby v a ryhu</li>
              <li>itui gb gj 777</li>
              <li>tuktu hfetygjf gg ryjgyjgrthggyj 8</li>
              <li>rgdv</li>
            </ul><br>
            </DIV>
            
            <center><br><br>
            <Input type="button" value="   Accept   " onClick="AcceptScript Me"> &nbsp;
            <Input type="button" value="  Decline  "   onClick="DeclineScript Me">
            </center>
            </body>
            </html>
            \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


            • #7
              Re: Script for Popup Box to Accept Terms on Windows Login

              Awesome ideas, this is exactly what I was hoping for. The HTA rocks! I'll test this using a batch file sometime this weekend and let you know how things go.

              Thank you guys for your help!

              Brad
              Last edited by bchnc10; 7th November 2009, 08:33.

              Comment

              Working...
              X