HTA to remotely enable/disable automatic login and reboot multiple sequential PCs

Author Message
Kravis

  • Total Posts : 13
  • Scores: 0
  • Reward points : 0
  • Joined: 3/9/2010
  • Status: offline
HTA to remotely enable/disable automatic login and reboot multiple sequential PCs Friday, April 09, 2010 4:09 AM (permalink)
0
Why: At the schools I work for, we routinely need to log in as a particular user account that exists solely for online testing (why we have this account is a long explanation...just accept that it's needed). In the past what we've had to do is log into every machine as that user and let our startup scripts handle setting up autologin and restarting the computer so that the system is ready for the online testing software we're required to run.
 
How: We name our computers like this: campus-room-ws__  with the last two characters being a workstation number. This way we can script for large numbers of computers at once while having the granularity to easily work with individual stations. This script basically asks for the campus-room prefix, and a range of workstation numbers. It then issue a delayed shutdown command and then registry modifications to enable autologin (the registry mods come second because we've had problems with the computer overwriting autologin registry values when shutdown is run)
 
Here's the code:
 
edit: okay, the code tags don't seem to work the same here as they do in other forums. I pasted this from NOTEPAD and it's still not behaving.
 
<html> 
      <head> 
       <title>Online Testing Lab Deployment</title> 
       <HTA:APPLICATION 
        APPLICATION="JBKB tutorial" 
        SCROLL=No 
        SINGLEINSTANCE=YES 
       > 
      </head> 
      <script language="VBScript"> 
       Sub Window_onLoad 
        window.resizeTo 350,250 
       End Sub 
       Sub DeployScript 
        Set WSHShell = CreateObject("WScript.Shell") 
        strLoginUser = "cota" 
        intCount = StopWS.Value - StartWS.Value 
        if intCount < 1 Then 
         MsgBox "Invalid Workstation Range" 
         document.execCommand("Refresh") 
        End If 
        For i=StartWS.Value To StopWS.Value Step 1 
         if i<10 Then 
          strComputer= LabName.Value & "-ws0" & i 
         Else 
          strComputer= LabName.Value & "-ws" & i 
         End If 
         Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 
         Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'") 
         For Each objItem in colItems 
          If  objItem.StatusCode = 0 Then 
     ' 
           WSHShell.Run "shutdown -f -r -t 30 -m \\" & strComputer 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultUserName /f /d " & strLoginUser 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v AutoAdminLogon /f /d 1" 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultPassword /f" 
          Else 
           MsgBox strComputer & " did not respond to ping." 
          End If 
         Next 
        Next 
       End Sub 
       Sub RevertScript 
        Set WSHShell = CreateObject("WScript.Shell") 
        strLoginUser = RevertUser.Value 
        intCount = StopWS.Value - StartWS.Value 
        if intCount < 1 Then 
         MsgBox "Invalid Workstation Range" 
         document.execCommand("Refresh") 
        End If 
        For i=StartWS.Value To StopWS.Value Step 1 
         if i<10 Then 
          strComputer= LabName.Value & "-ws0" & i 
         Else 
          strComputer= LabName.Value & "-ws" & i 
         End If 
         Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 
         Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'") 
         For Each objItem in colItems 
          If  objItem.StatusCode = 0 Then 
           Set FSO=CreateObject("Scripting.FileSYstemObject") 
           strINIfile="\\" & strComputer & "\c$\windows\testnav.bat.ini" 
           If FSO.FileExists(strINIfile) Then 
            FSO.DeleteFile strINIfile 
           End If 
           WSHShell.Run "shutdown -f -r -t 30 -m \\" & strComputer 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultUserName /f /d " & strLoginUser 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v AutoAdminLogon /f /d 0" 
           WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultPassword /f" 
          Else 
           MsgBox strComputer & " did not respond to ping." 
          End If 
         Next 
        Next 
       End Sub 
       Sub CancelScript 
        Self.Close() 
       End Sub 
      </script> 
      <body> 
       <table> 
        <tr> 
         <td align="right"> 
         Lab name (ex. CHS-A1) 
         </td> 
         <td> 
         <input type="text" name="LabName" tabindex=1 /> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
         Start on workstation # 
         </td> 
         <td> 
         <input type="text" name="StartWS" tabindex=2 /> 
         </td> 
        </tr> 
        <tr> 
         <td align="right"> 
         Stop on workstation # 
         </td> 
         <td> 
         <input type="text" name="StopWS" tabindex=3 /> 
         </td> 
        </tr> 
        <tr align="right"> 
         <td> 
          <input class="button" type="button" value="Cancel" onClick="CancelScript" tabindex=5 /> 
         </trd> 
         <td> 
          <input class="button" type="button" value="Deploy" onClick="DeployScript" tabindex=4 /> 
         </td> 
        </tr> 
       </table> 
       <br /> 
       Revert using the following user name:<br /> 
       <input type="text" name="RevertUser" value="your_username_here" tabindex=6 /> 
       <input class="button" type="button" value="Revert to Normal" onClick="RevertScript" tabindex=7 /> 
       </body> 
     </html>

 
Yes, there is a fair bit of replication between the apply and revert code. There was just enough difference between the two that I felt the need to keep them separate.
 
I found it easier to making changes to the remote registries and shut down the PCs using shell commands as the VBScript for this was convoluted and I found the shell far easier to make work consistently.
 
This particular script doesn't let you specify the autologin user because we always use the same account. It would be a simple thing to have it use the same text field as the revert script (and would probably make it easier to reuse some of the code)
 
Comments and suggestions on further improving this are always welcome. I'm new to this :)
<message edited by Kravis on Friday, April 09, 2010 4:14 AM>
 
#1
    KieranWalsh

    • Total Posts : 1
    • Scores: 0
    • Reward points : 0
    • Joined: 4/15/2010
    • Status: offline
    Re:HTA to remotely enable/disable automatic login and reboot multiple sequential PCs Thursday, April 15, 2010 10:57 PM (permalink)
    0
    Not that it's probably going to make a huge amount of difference, but I can see a typo in a closing tag:

    </trd> should be </td>
     
    #2
      Kravis

      • Total Posts : 13
      • Scores: 0
      • Reward points : 0
      • Joined: 3/9/2010
      • Status: offline
      Re:HTA to remotely enable/disable automatic login and reboot multiple sequential PCs Monday, May 17, 2010 3:16 AM (permalink)
      0
      That must have been an artifact of copying and pasting, as it never showed up in the script. I'm working on a cleaner, more useful version of this now that I've had some time to think about it and tinker with HTAs more. It won't be as purpose-built as the first one, which I cobbled together in a hurry as my first real HTA project.
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:HTA to remotely enable/disable automatic login and reboot multiple sequential PCs Monday, May 17, 2010 3:42 AM (permalink)
        0
        Sweet. I look forward to it.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          Kravis

          • Total Posts : 13
          • Scores: 0
          • Reward points : 0
          • Joined: 3/9/2010
          • Status: offline
          Re:HTA to remotely enable/disable automatic login and reboot multiple sequential PCs Wednesday, May 19, 2010 4:34 AM (permalink)
          0
          As promised, a more versatile and leaner app. Now that I've learned how to use subs a bit better, I was able to remove a lot of redundant code.
          I was only able to briefly test it yesterday. I'll do more thorough trials in a few days, but it all *appears* to work. If you see any bugs, let me know. And as always, I welcome input on better or more "proper" ways of doing things.
          Major changes:

          * The username field works for both enable and disable now
          * Hotkeys have been added: Alt + the bracketed key on the button. Why? Because I can :)
          * A password field has been added to support passworded accounts.
          * Shutdown and restart buttons have been added which won't affect autologin settings.
          * I fixed a small bug where it would complain about a single workstation being an invalid range.



          <html> 
                <head> 
                 <title>CISD Lab Deployment Application</title> 
                 <HTA:APPLICATION 
                  APPLICATION="CISD" 
                  SCROLL=No 
                  SINGLEINSTANCE=YES 
                 > 
                </head> 
                <script language="VBScript"> 
                 Window.resizeTo 500,200 
                 Sub Deploy(Action) 
                  Set WSHShell = CreateObject("WScript.Shell") 
                  intCount = StopWS.Value - StartWS.Value 
                  if intCount < 0 Then 
                   MsgBox "Invalid Workstation Range" 
                   document.execCommand("Refresh") 
                  End If 
                  For i=StartWS.Value To StopWS.Value Step 1 
                   if i<10 Then 
                    strComputer= LabName.Value & "-ws0" & i 
                   Else 
                    strComputer= LabName.Value & "-ws" & i 
                   End If 
                   Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") 
                   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'") 
                   For Each objItem in colItems 
                    If  objItem.StatusCode = 0 Then 
                     If Action="Shutdown" Then 
                      WSHShell.Run "shutdown -f -t 30 -m \\" & strComputer 
                     ElseIf Action="Restart" Then 
                      WSHShell.Run "shutdown -f -t 30 -m \\" & strComputer 
                     Else 
                      WSHShell.Run "shutdown -f -r -t 30 -m \\" & strComputer 
                      WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultUserName /f /d " & Username.Value 
                      WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v AutoAdminLogon /f /d " & Action 
                       
                      If Password.Value = "" Then 
                       WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultPassword /f" 
                      Else 
                       WSHShell.Run "reg add ""\\" & strComputer & "\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /v DefaultPassword /f /d " & Password.Value 
                      End If 
                     End If 
                    Else 
                     MsgBox strComputer & " did not respond to ping." 
                    End If 
                   Next 
                  Next 
                 End Sub 
                  
                 Sub Shutdown() 
                  
                 End Sub   Sub Cancel() 
                  Self.Close() 
                 End Sub 
                   </script> 
                <body> 
                 <table> 
                  <tr> 
                   <td>Lab name (ex. CHS-A1)</td> 
                   <td><input type="text" name="LabName" tabindex=1 /></td> 
                   <td><input style="width:150px" class="button" type="button" AccessKey="e" value="(E)nable AutoLogin" onClick="Deploy(1)" tabindex=5 /></td> 
                  </tr> 
                  <tr> 
                   <td>Start on Workstation #</td> 
                   <td><input type="text" name="StartWS" tabindex=2 /></td> 
                   <td><input style="width:150px" class="button" type="button" AccessKey="d" value="(D)isable AutoLogin" onClick="Deploy(0)" tabindex=6 /></td> 
                  </tr> 
                  <tr> 
                   <td>Stop on Workstation #</td> 
                   <td><input type="text" name="StopWS" tabindex=3 /></td> 
                   <td><input style="width:150px" class="button" type="button" AccessKey="s" value="(S)hut Down" onClick="Deploy(Shutdown)" tabindex=7 /></td> 
                  </tr> 
                  <tr> 
                   <td>With the username</td> 
                   <td><input type="text" name="UserName" value="your_username_here" tabindex=4 /></td> 
                   <td><input style="width:150px" class="button" type="button" AccessKey="r" value="(R)estart" onClick="Deploy(Restart)" tabindex=8 /></td> 
                  </tr> 
                  <tr> 
                   <td>Using Password</td> 
                   <td><input type="password" name="Password" tabindex=4 /></td> 
                   <td><input style="width:150px" class="button" type="button" AccessKey="c" value="(C)ancel" onClick="Cancel()" tabindex=8 /></td> 
                  </tr> 
                 </table> 
                </body> 
               </html>

          <message edited by Kravis on Wednesday, May 19, 2010 4:38 AM>
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9