.bat and .hta (1 Viewer)

zeetes

carouser
VIP Subscribing Member
Joined
Jan 2, 2010
Messages
21,238
Reaction score
22,739
Location
the hårga
Offline
think i already made this at some point, but..

speaking of notepad++, anyone a fan of batch file menus or .hta programming? i generally despise scripting, but i can make batch files all day long.

eventually, i will post a few examples.
 
Scripting is the greatest thing ever, nothing like spending a few hours to never have to manually perform a task or tasks again.
 
menu batches are handy for people who can't remember commands. for example:

restart.bat

Code:
@ECHO OFF

:START
CLS
ECHO.
ECHO Current HOSTNAME: %computername%
ECHO.
ECHO 1. Restart Local PC
ECHO 2. Restart Remote PC
ECHO.
ECHO E. EXIT
ECHO.
SET /P Choice=Please type your choice and press Enter: 
ECHO.
IF /I '%Choice%'=='1' GOTO LOCAL
IF /I '%Choice%'=='2' GOTO REMOTE
IF /I '%Choice%'=='E' GOTO END
GOTO START

:LOCAL
CLS
ECHO.
ECHO This will restart %COMPUTERNAME%
ECHO.
SET /P CHOICE=Are you sure you want to continue [Y/N]? 
IF /I '%CHOICE%'=='Y' GOTO LRESTART
IF /I '%CHOICE%'=='N' GOTO START
GOTO LOCAL
:LRESTART
SHUTDOWN /R /T 000 /F
GOTO END

:REMOTE
CLS
ECHO.
SET /P HOSTNAME=Please type HOSTNAME or IP address and press Enter: 
PING %HOSTNAME%
ECHO.
ECHO This will restart %HOSTNAME%
ECHO.
:REMOTE2
SET /P CHOICE=Are you sure you want to continue [Y/N]? 
IF /I '%CHOICE%'=='Y' GOTO RRESTART
IF /I '%CHOICE%'=='N' GOTO START
GOTO REMOTE2
:RRESTART
SHUTDOWN /M \\%HOSTNAME% /R /T 000 /F
GOTO END

:END
EXIT

i was tired of explaining how to restart a user os through rdp.
 
I just modified a build .bat today, so it'll copy the test DB from the SQL2008 server, where garbage data can still be generated, to the SQL2012 instance I use for development. Got to be a real drag doing it manually.

Edit: congrats on the GOTOs. Necessary in batch files, of course - but it reminds me of when we were studying Pascal or some equally ancient language in Survey, and I made it a point to use GOTO statements as the sole mechanism for the program's flow control. Just to see if I could do it... and if the professor would let me get away with it. :D
 
menu batches are handy for people who can't remember commands. for example:

restart.bat

Code:
@ECHO OFF

:START
CLS
ECHO.
ECHO Current HOSTNAME: %computername%
ECHO.
ECHO 1. Restart Local PC
ECHO 2. Restart Remote PC
ECHO.
ECHO E. EXIT
ECHO.
SET /P Choice=Please type your choice and press Enter: 
ECHO.
IF /I '%Choice%'=='1' GOTO LOCAL
IF /I '%Choice%'=='2' GOTO REMOTE
IF /I '%Choice%'=='E' GOTO END
GOTO START

:LOCAL
CLS
ECHO.
ECHO This will restart %COMPUTERNAME%
ECHO.
SET /P CHOICE=Are you sure you want to continue [Y/N]? 
IF /I '%CHOICE%'=='Y' GOTO LRESTART
IF /I '%CHOICE%'=='N' GOTO START
GOTO LOCAL
:LRESTART
SHUTDOWN /R /T 000 /F
GOTO END

:REMOTE
CLS
ECHO.
SET /P HOSTNAME=Please type HOSTNAME or IP address and press Enter: 
PING %HOSTNAME%
ECHO.
ECHO This will restart %HOSTNAME%
ECHO.
:REMOTE2
SET /P CHOICE=Are you sure you want to continue [Y/N]? 
IF /I '%CHOICE%'=='Y' GOTO RRESTART
IF /I '%CHOICE%'=='N' GOTO START
GOTO REMOTE2
:RRESTART
SHUTDOWN /M \\%HOSTNAME% /R /T 000 /F
GOTO END

:END
EXIT
i was tired of explaining how to restart a user os through rdp.

Thanks Zeetes. You were running this locally to restart remotely, yes?

*edit - Works well. Answered my own question. I dig the ping first as well.

*2nd edit - Share more, please!
 
I remember making batch files often in the days of dos and have been tempted to pick up some scripting skills but I just can't ever think of enough good things everyday Joe can use either for. The only thing I use scripting for is large batches of photo editing. Is it that it is mainly just useful if you are in a tech field or is my imagination just too inside the box?
 
Zack, it's really only for lazy people. My opinion is that repetitive tasks are what computers are good at - nay, what they are for - so they may as well do that kind of work for me. I'll spend hours writing something to save myself from boring, error-prone repetitive tasks.
 
Zack, it's really only for lazy people. My opinion is that repetitive tasks are what computers are good at - nay, what they are for - so they may as well do that kind of work for me. I'll spend hours writing something to save myself from boring, error-prone repetitive tasks.

pretty much.

i have more fun making them than using them. now, batch files for automating moving files to ftp and crap like that, yay!
 
I just modified a build .bat today, so it'll copy the test DB from the SQL2008 server, where garbage data can still be generated, to the SQL2012 instance I use for development. Got to be a real drag doing it manually.

Edit: congrats on the GOTOs. Necessary in batch files, of course - but it reminds me of when we were studying Pascal or some equally ancient language in Survey, and I made it a point to use GOTO statements as the sole mechanism for the program's flow control. Just to see if I could do it... and if the professor would let me get away with it. :D

hah i loved pascal. goto statements are bomb diggity fo'riggity.

Thanks Zeetes. You were running this locally to restart remotely, yes?

*edit - Works well. Answered my own question. I dig the ping first as well.

*2nd edit - Share more, please!

this is an .hta i sometimes use. i did not write the base code, only modified for my own use. i had a powershell class with the guy who wrote this and he was kind enough to let me reuse it. i'll post the original code after this too. it also includes a script for pulling hostnames off the domain (which i just do via ps in ad).

requires a file in this folder c:\script\Clients.txt 1 hostname per line

wh0d4t.hta

PHP:
<html>
<!--Originally written by Shawn Stugart, sstugart@nhconn.com-->
<head>
<title>wH0d4t</title>
<hta:application
	id="adminHTA"
	applicationname="adminHTA"
	scroll="no"
	singleinstance="yes"
	windowstate="normal"
>
</head>
<style>
body {margin:10px 20px 10px 20px;background-color:#bea540;color:#000;font-style:sans-serif;}
h1,h2 {margin:0;padding-bottom:7px;font:14pt sans-serif;}
p {margin:10px 0 5px 0;}
select {margin-left:0;width:200px;background-color:#ccc;color:#000;font:8pt arial;scrollbar-face-color:#ccc;}
#top {width:450px;}
.cell {float:left;width:225px;}
#bottom {width:100%;}
#clear {float:left;width:200px;}
.ok,.warning,.danger {margin-top:3px;padding:2px 0 2px 0;width:98px;font:bold 9pt;}
.ok {background-color:#0f0;border:2px outset #bea540;color:#000;}
.warning {background-color:#ff0;border:2px outset #bea540;color:#000;}
.danger {background-color:#f00;border:2px outset #fff;color:#fff;}
.check {font-size:14pt;}
#report {height:200px;margin:7px 0 4px 0;padding:4px;overflow-y:scroll;width:425px;background-color:#000;border:none;color:#fff;scrollbar-face-color:#000;}
#clear_button {margin:3px 0 4px 0;padding:2px 0 2px 0;width:125px;background-color:#ccc;border:2px outset #ccc;color:#000;font:9pt;}
#check {float:left;padding-top:2px;width:225px;font:9pt sans-serif;text-align:right;}
</style>

<script language="vbscript">
Sub Window_Onload
	window.setTimeout "window.moveto 75,10", 100
	window.setTimeout "window.resizeto 490,535", 100
	'window.moveto 75,10
	'window.resizeto 500,800
	On Error Resume Next
	dtmProgress = Time
	sMsgLoad = "Loading System List."
	HTAEcho sMsgLoad
    ForReading = 1
    strNewFile = "C:\Script\Clients.txt"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If Not objFSO.FolderExists("C:\Script") Then
    	objFSO.CreateFolder("C:\Script")
    End If 
    Set objFile = objFSO.OpenTextFile _
        (strNewFile, ForReading)
    If Err = 0 Then
	    Do Until objFile.AtEndOfStream
	    	If DateDiff("s",dtmProgress,Time) > 2 Then
	    		sMsgLoad = sMsgLoad & "."
	    		HTAEcho sMsgLoad
	    		dtmProgress = DateAdd("s", 2, dtmProgress)
		    End If
	        strLine = objFile.ReadLine
	        Set objOption = document.createElement("OPTION")
	        objOption.Text = strLine
	        objOption.Value = strLine
	        AvailableComputers.Add(objOption)
	    Loop
	    objFile.Close
	End If
	HTAEcho ""
End Sub
Sub QueryProcs
	On Error Resume Next
	ClearProcessList
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		If PingCheck.Checked Then
			If Pinger(strComputer) = 1 Then 
				For Each proc in GetObject("WinMgmts:\\" & strComputer).InstancesOf("Win32_Process")
			    	strLine = proc.Name
			        Set objOption = Document.createElement("OPTION")
			        objOption.Text = strLine
			        objOption.Value = strLine
			        Processes.Add(objOption)
				Next
				If Err <> 0 Then
					sResult = sResult & "Can't collect running processes on " & strComputer & vbCrLf
					sResult = sResult &  Err.Number & " " & Err.Description
					Err.Clear
					MsgBox sResult
				End If
			Else
				MsgBox strComputer & " did not respond to ping."
			End If
		Else
			For Each proc in GetObject("WinMgmts:\\" & strComputer).InstancesOf("Win32_Process")
		    	strLine = proc.Name
		        Set objOption = document.createElement("OPTION")
		        objOption.Text = strLine
		        objOption.Value = strLine
		        Processes.Add(objOption)
			Next
			If Err <> 0 Then
				sResult = sResult & "Can't collect running processes on " & strComputer & vbCrLf
				sResult = sResult &  Err.Number & " " & Err.Description
				Err.Clear
				MsgBox sResult
			End If
		End If
		HTAEcho ""
		Processes.Disabled = False
	Else
		MsgBox "You forgot to pick a computer...."
	End If
End Sub
Sub KillProc
	On Error Resume Next
	strProcess = "'" & Processes.Value & "'"
	Do While strProcess = "0"
		runbutton3.Disabled = True
	Loop
	runbutton3.Disabled = False
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		Set objWMIService = GetObject("winmgmts:" _
		    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		Set colProcessList = objWMIService.ExecQuery _
		    ("SELECT * FROM Win32_Process WHERE Name = " & strProcess & "")
		For Each objProcess in colProcessList
		    retVal = objProcess.Terminate()
		Next
		If retVal = 0 Then
			MsgBox Processes.Value & " terminated on " & AvailableComputers.Value
		Else
			MsgBox "FAILED to kill " & Processes.Value & " on " & AvailableComputers.Value
		End If
		QueryProcs
	Else
		MsgBox "You forgot to pick a computer...."
	End If
End Sub
Sub GetOSVersion
	On Error Resume Next
	strComputer = GetBoxes
	For i = 0 To UBound(strComputer)
		If DisplayProgress.Checked Then
			HTAEcho "Trying " & strComputer(i)
		End If
    	Set objWMIService = GetObject("winmgmts:\\" & strComputer(i) &  "\root\cimv2")
    	Set colOperatingSystems = objWMIService.ExecQuery _
        	("Select * from Win32_OperatingSystem")
   		For Each objOperatingSystem in colOperatingSystems
    		If Err = 0 Then
	        	sResult = sResult & "<br>" & strComputer(i) & ": " & objOperatingSystem.Caption _
	            	& " Service Pack " & objOperatingSystem.ServicePackMajorVersion  _
	        		& "." & objOperatingSystem.ServicePackMinorVersion
	   		Else
	    		sResult = sResult & "<br>" & "Error reading " & strComputer(i) & "    " _
	    			& Err.Number & " " & Err.Description
	    		Err.Clear
	    	End If
    	Next
    Next
    ' If sResult <> "" Then
' 		Popup sResult
' 	End If
	HTAEcho sResult
	'HTAEcho ""
End Sub
Sub ShutItDown
	On Error Resume Next
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		If PingCheck.Checked Then
			If Pinger(strComputer) = 1 Then
			    Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
			    Set colOperatingSystems = objWMIService.ExecQuery _
			        ("Select * from Win32_OperatingSystem")
			    For Each objOperatingSystem in colOperatingSystems
					objOperatingSystem.Win32Shutdown(1 + 4)
				Next
				If Err = 0 Then
					MsgBox "Shutting Down " & AvailableComputers.Value
				Else
					MsgBox "SHUTDOWN FAILED"
				End If
			Else
				MsgBox strComputer & " could not be pinged. Operation terminated."
			End If
		Else
			Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
		    Set colOperatingSystems = objWMIService.ExecQuery _
		        ("Select * from Win32_OperatingSystem")
		    For Each objOperatingSystem in colOperatingSystems
				objOperatingSystem.Win32Shutdown(1 + 4)
			Next
			If Err = 0 Then
				MsgBox "Shutting Down " & AvailableComputers.Value
			Else
				MsgBox "SHUTDOWN FAILED"
			End If
		End If
	Else
		ManageAll(1)
	End If
	HTAEcho ""
End Sub
Sub Reboot
	On Error Resume Next
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		If PingCheck.Checked Then
			If Pinger(strComputer) = 1 Then
			    Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
			    Set colOperatingSystems = objWMIService.ExecQuery _
			        ("Select * from Win32_OperatingSystem")
			    For Each objOperatingSystem in colOperatingSystems
					objOperatingSystem.Win32Shutdown(2 + 4)
				Next
				If Err = 0 Then
					MsgBox "Rebooting " & AvailableComputers.Value
				Else
					MsgBox "REBOOT FAILED"
				End If
			Else
				MsgBox "Couldn't ping " & strComputer & ". Operation terminated."
			End If
		Else
		 	Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
		    Set colOperatingSystems = objWMIService.ExecQuery _
		        ("Select * from Win32_OperatingSystem")
		    For Each objOperatingSystem in colOperatingSystems
				objOperatingSystem.Win32Shutdown(2 + 4)
			Next
			If Err = 0 Then
				MsgBox "Rebooting " & AvailableComputers.Value
			Else
				MsgBox "REBOOT FAILED"
			End If
		End If
	Else
		ManageAll(2)
	End If
	HTAEcho ""
End Sub
Sub LogOff
	On Error Resume Next
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		If PingCheck.Checked Then
			If Pinger(strComputer) = 1 Then
		    Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
		    Set colOperatingSystems = objWMIService.ExecQuery _
		        ("Select * from Win32_OperatingSystem")
		    For Each objOperatingSystem in colOperatingSystems
				objOperatingSystem.Win32Shutdown(0 + 4)
			Next
			If Err = 0 Then
				MsgBox "Logging Off " & AvailableComputers.Value
			Else
				MsgBox "LOGOFF FAILED"
				End If
			Else
				MsgBox "Couldn't ping " & strComputer & ".  Operation terminated."
			End If
		Else
		 	Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
		    Set colOperatingSystems = objWMIService.ExecQuery _
		        ("Select * from Win32_OperatingSystem")
		    For Each objOperatingSystem in colOperatingSystems
				objOperatingSystem.Win32Shutdown(0 + 4)
			Next
			If Err = 0 Then
				MsgBox "Logging Off " & AvailableComputers.Value
			Else
				MsgBox "LOGOFF FAILED"
			End If
		End If
	Else
		ManageAll(0)
	End If
	HTAEcho ""
End Sub
Sub ManageAll(iType)
	iContinue = MsgBox("Are you sure you want to perform this action " _
			& "on EVERY computer in the list?",vbYesNo + vbCritical _
			+ vbDefaultButton2, "WARNING!!!")
	On Error Resume Next
	If iContinue = vbYes Then
		If RandomPWDCheck = 1 Then
			If PingCheck.Checked Then
				For Each oOption In AvailableComputers.Options
					If Pinger(oOption.Value) = 1 Then
						If oOption.Value <> "0" Then
							strComputer = oOption.Value
							If DisplayProgress.Checked Then
								HTAEcho "Trying " & strComputer
							End If
							Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
			    			Set colOperatingSystems = objWMIService.ExecQuery _
			        			("Select * from Win32_OperatingSystem")
			    			For Each objOperatingSystem in colOperatingSystems
								objOperatingSystem.Win32Shutdown(int(iType) + 4)
							Next
							If Err = 0 Then
								sResult = sResult & oOption.Value & " ---SUCCESS." & vbCrLf
							Else
								sResult = sResult & "OPERATION FAILED ON " & oOption.Value & vbCrLf
							End If
						End If
					Else
						sResult = sResult & "Couldn't ping " & oOption.Value & vbCrLf
					End If
				Next
			Else
				For Each oOption In AvailableComputers.Options
					If oOption.Value <> "0" Then
						strComputer = oOption.Value
						If DisplayProgress.Checked Then
							HTAEcho "Trying " & strComputer
						End If
						Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
		    			Set colOperatingSystems = objWMIService.ExecQuery _
		        			("Select * from Win32_OperatingSystem")
		    			For Each objOperatingSystem in colOperatingSystems
							objOperatingSystem.Win32Shutdown(int(iType) + 4)
						Next
						If Err = 0 Then
							sResult = sResult & oOption.Value & " ---SUCCESS." & vbCrLf
						Else
							sResult = sResult & "OPERATION FAILED ON " & oOption.Value & vbCrLf
						End If
					End If
				Next
			End If
			If sResult <> "" Then
				PopUp sResult
			End If
		Else
			MsgBox "Incorrect code.  Exiting."
		End If
	End If
End Sub
Sub PingIt
	Dim iPingTimeOut, colItems, oItem, oWMI
	If AvailableComputers.Value <> "0" Then
		sComp = AvailableComputers.Value
		iPingTimeOut = "100"
		On Error Resume Next
		Set oWMI = GetObject("WinMgmts://")
		Set colItems = oWMI.ExecQuery("Select * from Win32_PingStatus " _
			& "Where Address = '" & sComp & "'" _
			& "AND Timeout =" & iPingTimeOut, "WQL", 48)
		If Err.Number <> 0 Then 'For pre-XP/2003 Machines that don't support Win32_PingStatus
			Err.Clear
			Dim oShell, oScriptExec
			Set oShell = CreateObject("WScript.Shell")
			Set oScriptExec = oShell.Exec("%comspec% /c ping -n 1 -w 200 " & sComp)
			On Error Resume Next
			Do Until oScriptExec.StdOut.AtEndOfStream
				sPingData = sPingData & oScriptExec.StdOut.ReadLine & "<br>"
			Loop
			HTAEcho sPingData
		Else
		   For Each oItem In colItems
		   	   Select Case oItem.StatusCode
		        	Case "0"
		        		HTAEcho sComp & " PING SUCCESS"
		        	Case "11002"
		        		HTAEcho sComp & " PING ERROR: Destination Net Unreachable"
		        	Case "11003"
		        		HTAEcho sComp & " PING ERROR: Destination Host Unreachable"
		        	Case "11010"
		        		HTAEcho sComp & " PING ERROR: Request Timed Out"
		        	Case "11013"
		        		HTAEcho sComp & " PING ERROR: Time-to-Live Expired in Transit"
		        	Case Else
		        		HTAEcho sComp & " PING ERROR: An unexpected error code was returned"
		        End Select
		    Next
		End If
	Else
		HTAEcho "You forgot to pick a computer...."
	End If
End Sub
Sub RemoteDesktop
	const HKEY_LOCAL_MACHINE = &H80000002
	On Error Resume Next
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
			strComputer & "\root\default:StdRegProv")
		strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server"
		strValueName = "fDenyTSConnections"
		oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
		If Err = 0 Then
			If dwValue = 1 Then
			    valPrompt = MsgBox("Remote Desktop is Currently disabled.  Do you want to ENABLE it?", vbYesNo)
			    If valPrompt = vbYes Then 'note: "prompt" is apparently a reserved keyword in .HTAs
				    dwValue = 0
				    oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
				    MsgBox "Remote Desktop is now ENABLED on " & AvailableComputers.Value
				    Crawler.InnerHTML = "Remote Desktop is now ENABLED on " & AvailableComputers.Value
			    ElseIf valPrompt = vbNo then
				    MsgBox "Remote Desktop is still DISABLED."
			    End If
			ElseIf dwValue = 0 Then
			  	valPrompt = MsgBox ("Remote Desktop is Currently ENABLED.  Do you want to DISABLE it?", vbYesNo)
			  	If valPrompt = vbYes then
				    dwValue = 1
				    oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
				    MsgBox "Remote Desktop is now DISABLED on " & AvailableComputers.Value
				    Crawler.InnerHTML = "Remote Desktop is now DISABLED on " & AvailableComputers.Value
			    ElseIf valPrompt = vbNo then
				    MsgBox "Remote Desktop is still ENABLED on " & AvailableComputers.Value
				    Crawler.InnerHTML = "Remote Desktop is still ENABLED on " & AvailableComputers.Value
			    End If
			Else
				MsgBox "Couldn't set Remote Desktop on " & AvailableComputers.Value & vbCrLf _
				& "Check that the remote system is available and that it supports Remote Desktop."
			End If
		Else
			MsgBox "Couldn't set Remote Desktop on " & AvailableComputers.Value & vbCrLf _
				& "Check that the remote system is available and that it supports Remote Desktop."
		End If
	Else
		MsgBox "You forgot to pick a computer...."
	End If
End Sub
Sub ClearPing
	location.Reload(True)
End Sub
Function GetName(sIP)
	On Error Resume Next
	Dim oWMI, colItems, oItem, sCompName 
	Set oWMI = GetObject("winmgmts:\\" & sIP & "\root\CIMV2")
   	Set colItems = oWMI.ExecQuery("SELECT name FROM Win32_ComputerSystem", "WQL", 48)
   	For Each oItem In colItems
   	  	sCompName = oItem.Name
   	Next
   	GetName = sCompName
End Function
Sub RemoteToIt
	strComputer = AvailableComputers.Value
	If strComputer <> "0" Then
		Set oShell = CreateObject("WScript.Shell")
		oShell.Run("mstsc.exe /f /v:" & strComputer)
	Else
		MsgBox "You forgot to pick a computer...."
	End If
End Sub

Sub ClearProcessList
    For Each objOption In Processes.Options
        objOption.RemoveNode
    Next
    Set objOption = document.createElement("OPTION")
    objOption.Text = "Select a process"
	objOption.Value = "0"
    Processes.Add(objOption)
End Sub
Sub LockBoxButton
	Dim sResult
	sComputer = AvailableComputers.Value
	If sComputer = "0" Then
		iContinue = MsgBox("Are you sure you want to perform this action " _
			& "on EVERY computer in the list?",vbYesNo + vbCritical _
			+ vbDefaultButton2, "WARNING!!!")
		On Error Resume Next
		If iContinue = vbYes Then
			If RandomPWDCheck = 1 Then
				strComputer = GetBoxes
				For i = 0 To UBound(strComputer)
					If DisplayProgress.Checked Then
						HTAEcho "Trying " & strComputer(i)
					End If
					sResult = sResult & LockBox("Rundll32.exe user32.dll,LockWorkStation", strComputer(i), "0")
				Next
			Else
				MsgBox "Incorrect code.  Exiting."
			End If
		End If
	Else
		strComputer = GetBoxes
		For i = 0 To UBound(strComputer)
			sResult = sResult & LockBox("Rundll32.exe user32.dll,LockWorkStation", strComputer(i), "1")
		Next
	End If
	If sResult <> "" Then
  	  	Popup sResult
  	End If
End Sub
Function LockBox (sCommandLine, sBoxName, iMode)
  On Error Resume Next
  Set Proc = GetObject("WinMgmts:\\" & sBoxName & "\root\cimv2:Win32_Process")
  If Err.Number = 0 Then
	  errReturn = Proc.Create(sCommandLine, null, null, intProcessID)
	  If iMode = "1" Then
		  If errReturn = 0 Then
			MsgBox "SUCCESS -- Locked " & sBoxName & VbCrLf
		  Else
			MsgBox "FAILED LOCKING " & sBoxName & VbCrLf
		  End If
	  Else
	  	  If Err.Number = 0 Then
		      LockBox = "SUCCESS -- Locked " & sBoxName & VbCrLf
		  Else
			  LockBox = "FAILED LOCKING " & sBoxName & VbCrLf
		  End If
	  End If
	  Set Proc = Nothing
  Else
  	LockBox = "FAILED LOCKING " & sBoxName & VbCrLf
  	Err.Clear 
  End If
  HTAEcho ""
End Function
Function GetProtocol(sProtocol)
	Select Case sProtocol
		Case "Remote Desktop"
			GetProtocol = "TCP 3389"
		Case "FTP"
			GetProtocol = "TCP 21"
		Case "HTTP"
			GetProtocol = "TCP 80"
		Case "VNC"
			GetProtocol = "TCP 5900"
	End Select
End Function
Sub ManageIt
	sComputer = AvailableComputers.Value
	If sComputer <> "0" Then
		Set oShell = CreateObject("WScript.Shell")
		oShell.Run "compmgmt.msc /computer=" & sComputer
		If Err.Number <> 0 Then
			MsgBox "Error opening computer management on " & sComputer
		End If
	Else
		MsgBox "You forgot to pick a computer...."
	End If
End Sub
Function Pinger(sComp)
	Dim iPingTimeOut, colItems, oItem, oWMI 
	iPingTimeOut = "100"
	On Error Resume Next
	If DisplayProgress.Checked Then
		HTAEcho "Pinging " & sComp
	End If
	Set oWMI = GetObject("WinMgmts://")
	Set colItems = oWMI.ExecQuery("Select * from Win32_PingStatus " _
		& "Where Address = '" & sComp & "'" _
		& "AND Timeout =" & iPingTimeOut, "WQL", 48)
	If Err.Number <> 0 Then
		MsgBox "An error has occurred.  This script " _
			& "must be run on Windows XP/Windows Server 2003 " _
			& "or later."
	Else
	   For Each oItem In colItems
	   	   If oItem.StatusCode = 0 Then
	           Pinger = 1
	       Else
	   	       Pinger = 0
	       End If
	   Next
	End If
End Function
Function GetBoxes
	intSize = -1
	Const ForReading = 1
	Dim sResult2
	sFile = "C:\Script\clients.txt"
	ReDim Preserve arrComputers(intSize)
	If AvailableComputers.Value <> "0" Then
		If PingCheck.Checked Then
			If Pinger(AvailableComputers.Value) = 1 Then
				intSize = intSize + 1
				ReDim Preserve arrComputers(intSize)
				arrComputers(intSize) = AvailableComputers.Value
			Else
				sResult2 = sResult2 & "FAILED PINGING " & UCase(AvailableComputers.Value) & VbCrLf
			End If
		Else
			intSize = intSize + 1
			ReDim Preserve arrComputers(intSize)
			arrComputers(intSize) = AvailableComputers.Value
		End If
	Else
		Set oFSO = CreateObject("Scripting.FileSystemObject")
		Set oInputFile = oFSO.OpenTextFile(sFile, ForReading)
		If PingCheck.Checked Then
			Do Until oInputFile.AtEndOfStream
				sComputer = oInputFile.ReadLine
				If Pinger(sComputer) = 1 Then
					intSize = intSize + 1
					ReDim Preserve arrComputers(intSize)
					arrComputers(intSize) = sComputer
				Else
					sResult2 = sResult2 & "FAILED PINGING " & UCase(sComputer) & VbCrLf
				End If			
			Loop
			oInputFile.Close
		Else
			Do Until oInputFile.AtEndOfStream
				intSize = intSize + 1
				ReDim Preserve arrComputers(intSize)
				arrComputers(intSize) = oInputFile.ReadLine
			Loop
		End If
	End If
	GetBoxes = arrComputers
	If sResult2 <> "" Then
		Set oShell = CreateObject("WScript.Shell")
		iClearNoPings = oShell.Popup(sResult2 & VbCrLf & VbCrLf & "REMOVE FAILED PINGS FROM SYSTEM LIST?", 10, "REMOVE FAILED?", vbYesNo)
		If iClearNoPings = vbYes Then
			If AvailableComputers.Value = "0" Then
				Set oFile = oFSO.CreateTextFile("C:\Script\Clients.txt", True)
				For k = 0 To UBound(arrComputers)
					oFile.WriteLine arrComputers(k)
				Next
				oFile.Close
				ClearPing
			Else
				Set oFSO = CreateObject("Scripting.FileSystemObject")
				Set oOriginalFile = oFSO.OpenTextFile("C:\Script\Clients.txt", ForReading)
				Set oTempFile = oFSO.CreateTextFile("C:\Script\temp_clients.txt", True)
				Do Until oOriginalFile.AtEndOfStream
					sBox = oOriginalFile.ReadLine
					If sBox <> AvailableComputers.Value Then
						oTempFile.WriteLine(sBox)
					End If
				Loop
				oOriginalFile.Close
				oTempFile.Close
				oFSO.DeleteFile "C:\Script\Clients.txt", True
				oFSO.MoveFile "C:\Script\temp_clients.txt", "C:\Script\Clients.txt"
				ClearPing
			End If
		End If
	End If
End Function
Sub Popup(sMessage)
	'Note: MsgBox is limited to 1,023 characters; we use Popup instead
	Set oShell = CreateObject("WScript.Shell")
	oShell.Popup sMessage
End Sub
Sub HTAEcho(sMsg)
	On Error Resume Next
	Report.InnerHtml="" & sMsg & ""
	Call ForceRefresh()
End Sub
Function ForceRefresh()
	Set oShell = CreateObject("WScript.Shell")
	oShell.Run "cmd /c", 0, True
End Function
Sub LoggedOnUser
	sCompName = GetBoxes
	intArraySize = 0
	On Error Resume Next
	For i = 0 To UBound(sCompName)
		If DisplayProgress.Checked Then
			HTAEcho "Trying " & sCompName(i)
		End If
		Set oWMI = GetObject("winmgmts:\\" & sCompName(i) & "\root\cimv2")
		If Err <> 0 Then
			sResults = sResults & "ERROR READING " & sCompName(i) & "<br>"
			Err.Clear
		Else
			Set colItems = oWMI.ExecQuery("Select * from Win32_ComputerSystem",,48)
			For Each oItem in colItems
		    	sResults = sResults & "Logged on user at " & oItem.Name & " is " _
		    		& oItem.UserName & "<br>"
			Next
		End If
	Next
	HTAEcho sResults
End Sub
Sub Sleep(iSeconds)
	Dim sCmd
	Set oShell = CreateObject("WScript.Shell")
	sCmd = "%COMSPEC% /c ping -n " & iSeconds & " 127.0.0.1 > nul"
	oShell.Run sCmd,0,1
End Sub
</script>

<body>
<div id="top">
<div class="cell">
<h1>System List</h1>
<select size="14" name="AvailableComputers"><option value="0">All</option></select>
</div>
<div class="cell">
<h2>Processes</h2>
<select name="Processes" Disabled=True><option value="0">Select a process</option></select>
<input class="ok" type="button" value="Query" name="query"  onClick="QueryProcs">
<input class="danger" type="button" value="KILL" name="kill" onClick="KillProc">
</div>
<div class="cell">
<p>
<input class="ok" type="button" value="Ping" name="ping" onClick="PingIt">
<input class="ok" type="button" value="Logged On" name="loggedon" onClick="LoggedOnUser">
<input class="ok" type="button" value="RDP" name="rdp" onClick="RemoteToIt">
<input class="warning" type="button" value="Enable RDP" name="enablerdp" onClick="RemoteDesktop">
<input class="ok" type="button" value="OS Version" name="os" onClick="GetOSVersion">
<input class="warning" type="button" value="Manage" name="manage" onClick="ManageIt">
</p>
<p>
<input class="ok" type="button" value="Log It Off" name="logoff" onClick="Logoff">
<input class="ok" type="button" value="Lock It" name="lock" onClick="LockBoxButton">
<input class="warning" type="button" value="Reboot" name="reboot" onClick="Reboot">
<input class="danger" type="button" value="SHUT DOWN" name="shutdown" onClick="ShutItDown">
</p>
</div>
</div>
<div id="bottom">
<div id="report"></div>
<div id="clear">
<input id="clear_button" type="button" value="Clear Results" name="clear" onClick="ClearPing">
</div>
<div id="check">
<input type="checkbox" name="PingCheck" value="1" checked="True"><span class="check">&nbsp;Ping First</span>
<input type="checkbox" name="DisplayProgress" value="1" checked="true"><span class="check">&nbsp;Results</span>
</div>
</div>
</body>
</html>
 
I remember making batch files often in the days of dos and have been tempted to pick up some scripting skills but I just can't ever think of enough good things everyday Joe can use either for. The only thing I use scripting for is large batches of photo editing. Is it that it is mainly just useful if you are in a tech field or is my imagination just too inside the box?

Do you have a photoshop script for adding single watermarks to photos? I could use that.
 
pretty much.

i have more fun making them than using them. now, batch files for automating moving files to ftp and crap like that, yay!

RoboFTP will let you script the entire FTP transfer so that you can embed the script call in a SQL procedure that will generate and FTP a file on a schedule. Super helpful :9: I've been using it for years.
 
RoboFTP will let you script the entire FTP transfer so that you can embed the script call in a SQL procedure that will generate and FTP a file on a schedule. Super helpful :9: I've been using it for years.

we're too cheap.
 
I'm pretty sure you can do that in Lightroom. It's only abt $100 and I think it occasionally goes on sale for $79.
 
paint.net can do watermarking and <del>its free</del> it costs one gjallarhorn.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Users who are viewing this thread

    Back
    Top Bottom