Archive - November 2009-test

Contents Under Construction


Contents
bar1
PING List Of PCs With Online/Offline Logs
How To Add An Expiration Date To Your Script
How To Create Hidden Launch Using Batch
Scan IIS Log For -500 Type Errors
Install Inf From The Command Line
Devcon.exe
How To Use Send Keys


bar1

.

Δ PING List Of PCs Script With Offline/Online Logs
+Uses The Offline Machines As The New Workstation List+Looping
Written by Eddie Jackson on Day, 11/30/2009 xx:xx:00 PM [filed under Shell]
bar1

Okay, you're right, you saw something similar to this last month, however now there has been notable additions made to the script. The original ping'd a list of workstations from a text file, and recorded the results in a single, time-stamped text file. Now, there is the need to have separate online and offline logs, along with some way to use the offline machine names as our new workstations.txt file; we need to loop the script, never pinging an online machine name twice. So we accomplished all this by adding a second variable OutputFile2 as our offline list, the script cycles through the workstations.txt text file pinging each machine. The online responses go into the online text file and the offline responses go into the offline text file. Now the cool part, the offline machine names also get written into a newlist.txt file. After ping is done with our workstation list, the workstations.txt gets deleted, the newlist.txt gets renamed to workstations.txt. This keeps any "online" machines from getting ping'd more than once, as only offline machines now exist in the workstations.txt list. Repeats every 60 minutes. Nice!

bar1
Here are our specs:






Must ping a computer
Must cycle through workstation list text file
Must have online log
Must have offline log
Must Loop
Must not ping an online machine more than once
bar1



@rem ************************************************************************************
@rem Script Language: Shell
@rem Script Name: PINGQ.cmd
@rem Purpose: PING a list of workstations, writing to OFFLINE and ONLINE logs every hour
@rem Creation Date: 11/30/09
@rem Last Modified:
@rem Directions: double-click the PINGQ.cmd
@rem Author: Eddie Jackson
@rem Email: MrNetTek@gmail.com
@rem ************************************************************************************

@ECHO OFF
title=Pinging list of computers &color 9e

:MAIN
cls
::datestamp
for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
(set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)

(Set OutputFile=C:\PING_ONLINE_%yy%-%mm%-%dd%_%HHMM%.txt)
(Set OutputFile2=C:\"PING_OFFLINE_%yy%-%mm%-%dd%_%HHMM%.txt")
(Set WS=C:\workstations.txt)

@ECHO OFF
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (C:\workstations.txt) do (
ping -a -n 2 -w 750 %%a | find "Reply" > nul
if errorlevel 1 (echo %%a, OFFLINE >> "%OutputFile2%" & echo %%a OFFLINE & echo %%a >> "C:\newlist.txt"
) else (
echo %%a, ONLINE >> "%OutputFile%" & echo %%a ONLINE
)
)
Echo Sleeping for 1 hour...
DEL /Q workstations.txt
REN newlist.txt workstations.txt
sleep 3600

goto MAIN


bar1
 
bar1





Δ How To Add An Expiration Date To Your Script
Written by Eddie Jackson on Day, 11/28/2009 xx:xx:00 PM [filed under Shell]
bar1


Let's say have you a great little script, it does exactly what you want it do. You burn it to a CDR or put it on a flash/jump drive and send it out to your end-users. But now you realize that the script will need to be updated and sent out quarterly, and the staff should not re-use older scripts. How do programmatically make sure that the end-users won't be using old scripts on old media? Well, I'm glad you asked. You will have to program an expiration date at the beginning of your code. It will compare their current date to the static date you have set, and voila you now have a way to "expire" your script. Here it is....

bar1
Proof of concept: Make your script expire
bar1


@echo off

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B

FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B

FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B

FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B

SET datedone=%yyyy%%mm%%dd%

if %datedone% GTR 20100201 Echo Time has expired & GoTo EXPIRED

Echo Time has not expired


I do a little date parsing and add a single condition that if yes goes to EXPIRED which jumps to the end of the script (over all the main code) and lets end-user know the script has expired.

bar1
 

bar1






Δ How To Create Hidden Launch Using Batch
Written by Eddie Jackson on Day, 11/03/2009 xx:xx:00 PM [filed under Shell]
bar1

Everyone has needed at one time or another the ability to launch a large batch file setup...however, you couldn't seem to get rid of the infamous console window, the command prompt, the "DOS" window. This is how you would change the security context and launch your main process called MAIN.CMD completely hidden. Note: you could have easily used only VBScript with the sanur.exe to also make this completely silent

bar1
Here are our specs:
Change security context
Launch a batch file silently
bar1


@ECHO OFF
@REM Script Language: Shell
@REM Author: Eddie Jackson
@REM Date: 11/21/09
@REM Purpose: Proof of concept for silent batch file


Echo Set objShell = CreateObject("WScript.Shell") > %temp%\hidden.vbs
Echo objShell.Run "MAIN.CMD", 0 >> %temp%\hidden.vbs

@runas /u:administrator "wscript %temp%\hidden.vbs" | sanur.exe PASSWORD


bar1
 

bar1



 

Δ Scan IIS Log For - 500 Type Errors
Written by Eddie Jackson on Day, 11/xx/2009 xx:xx:00 PM [filed under VBScript]
bar1

 

For my reference:

bar1
Here are our specs:
Scan IIS log for 500 type errors
Echo to screen the 500 type errors
bar1



'L A N G U A G E
'VBScript
'
'S C R I P T N A M E
'Scan_iis.vbs
'
'P U R P O S E
To scan iis log for -500 errors and outputs results to screen.
'
'U S A G E
Launch file
'
'A U T H O R
'Eddie S. Jackson
'
'D A T E C R E A T E D
'11/19/09


Dim strFilename, obj, objTS, strLine

strFilename = "IIS.log"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(strFilename)
Do Until objTS.AtEndOfStream
strLine = objTS.ReadLine
If InStr(1,strLine," - 500") <> 0 Then
WScript.Echo strLine
End If
Loop
objTS.Close


bar1
 

bar1






Δ Install INFs From The Command Line
Written by Eddie Jackson on Day, 11/xx/2009 xx:xx:00 PM [filed under Shell]
bar1

 

For my reference:

How to install INFs from the command line.


bar1
Proof of concept: Install an .inf from command console
bar1

rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 .\.inf


bar1
 

bar1





Δ Devcon.exe
Written by Eddie Jackson on Day, 11/xx/2009 xx:xx:00 PM [filed under General]
bar1

For my reference:

The DevCon utility is a command-line utility that acts as an alternative to Device Manager. Using DevCon, you can enable, disable, restart, update, remove, and query individual devices or groups of devices. DevCon also provides information that is relevant to the driver developer and is not available in Device Manager.

Device Console Help:
devcon.exe [-r] [-m:\\] [...]
-r if specified will reboot machine after command is complete, if needed.




classfilter Allows modification of class filters.
classes List all device setup classes.
disable Disable devices that match the specific hardware or instance ID.
driverfiles List driver files installed for devices.
drivernodes Lists all the driver nodes of devices.
enable Enable devices that match the specific hardware or instance ID.
find Find devices that match the specific hardware or instance ID.
findall Find devices including those that are not present.
help Display this information.
hwids Lists hardware ID's of devices.
install Manually install a device.
listclass List all devices for a setup class.
reboot Reboot local machine.
remove Remove devices that match the specific hardware or instance ID.
rescan Scan for new hardware.
resources Lists hardware resources of devices.
restart Restart devices that match the specific hardware or instance ID.
stack Lists expected driver stack of devices.
status List running status of devices.
update Manually update a device.
UpdateNI Manually update a device without user prompt
SetHwID Adds, deletes, and changes the order of hardware IDs of root-enumerated devices.

bar1

bar1

 

 

Δ How To Use Send Keys
Written by Eddie Jackson on Day, 11/07/2009 xx:xx:00 PM [filed under VBScript]
bar1


For my reference:

WshShell.Sendkeys keys

or

WshShell.SendKeys("10")

BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER} or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
SHIFT +
CTRL ^
ALT %

bar1

bar1






 

 

 


pic_main_1

 


..About

..I'm a Computer
..Systems Engineer


..L
iving and loving life

........................................


..Author
....




..Categories

....< AD
....< Exchange
....< SQL
....< Windows
....< VBScript
....< Shell
....
<
Javascript
....< HTA
....< PowerShell
....< Reporting
....< Healthcare
....< Networking
....< General



..
Archives


....< December 2009
....<
November 2009

....<
October 2009
....<
September 2009

....
<
August 2009