RafaelWolf.com

The son of "The most interesting man in the world" (Dos Equis )

Browsing Posts in Batch Files

In the past I’ve created batch files to do some scripted redundant scheduled task for me, usually it’s related to backing up folders or files but I have a colleague who set one up when his server reboots or specific users log on to their systems on his terminal server.  When the script is done I usually have it call and execute an email VB script letting me know the task was completed with a specific message telling me what happened.

I ran into a bit of a problem recently with  Server 2008!

In the past I’ve used these well written, simple and useful scripts from Paul Sadowski but they failed to work on Server 2008.  Here’s the link to Paul’s site, all his stuff works GREAT on Server 2003 or Windows XP and I continue using them on those systems.  –> Link.  By the way, my scripting ability is limited so I have to once again thank people like Paul and James (who’s script I ended up using) for posting their scripts online for us to use!

If I tried executing his scripts on Server 2008 I’d get weird errors like these:

  • “The server rejected the sender address. The server response was 530 5.5.1:
  • “Send Error: The server rejected the sender address. The server response was: 550 Access denied – Invalid HELO name (See RFC2821 4.1.1.1)”
  • “550 Access denied – Invalid HELO name”
  • “CDO.Message.1 error ’80040213′ The transport failed to connect to the server”

* Also keep in mind that all these errors were not specifically from Paul’s scripts that he so kindly shared, most of them were due to me trying to edit and tweak his existing script in an attempt to eliminate the errors which I did a poor job of doing :)

I decided to start over and I stumbled upon James Koopman’s script:  http://www.jameskoopmann.com/?p=20

Thanks James for your excellent script!  You can download his script from the site above or download the script I edited and used (sensitive security information gone of course!) here –> Server 2008 compatible Email VBscript

For your information my script does NOT use a local email server, most of my problems were because I wanted to use an external email server.  The above errors are due to not having a username type in correctly, the wrong password, trying to use ssl or NTLM when you should use the “1″ option for clear text.  A security wonk might balk at the idea of a clear text email authentication BUT I’d also like to remind the wonk that the script sitting on the physical server isn’t encrypted either although it’s in a safe place :) .  This solution “works”, it’s not the best but it’s not the worst.

Good luck out there!

To all my brothers and sisters out in Internet land!  I had an unusual time finding this download, I finally found it on some obscure Micro$oft website but have since lost the actual link.  I tried to find the link for a colleague and I gave up shortly thereafter realizing I already had the file and that I could just send it to him.  If you’re looking for the RoboCopy Gui (which also includes robocopy.exe) get it here!

–> RoboCopy Gui

Robocopy is a great utility, it’s a bit more robust than xcopy, it has some great options like backup mode which from what I gather uses the system account to leverage shadow copy for backing up files with different permissions than the user you’re running your script with.  It’s good stuff all around.

Here’s an example robocopy script I happen to use, it backups up end user files once a week.  I run it 4 times per month and store the data in 4 different locations, week1, week2, etc, etc.  It backs user data up, then my next line says to move the log to a different location and finally it calls my email notifier letting me know the job was complete.

  • robocopy “\\myserver\users” “E:\myusers_Users_Backup\Week1″ /E /SEC /COPYALL /V /XO /LOG:”Week1_backup.log” /FFT /Z /B /ZB /R:10 /W:30
  • move /Y “C:\Documents and Settings\Administrator.MYDOMAIN\Application Data\Microsoft Robocopy GUI\Scripts\Week_1_backup.log” “E:\Users_Backup”
  • call “\\myserver\myshare\somesubfolder1\User Documents\Week_1_Email_Notification.vbs”

Get it while it’s HOT!  For years ClamAV has probably been protecting you to some degree without you even knowing it.  It has historically been used for appliances like email servers, web servers, file servers, etc and usually only on a Linux OS.  Why?  Because that’s where it all started :) .

At one point they had a Windows version of ClamAV called ClamWin but it must have been a few years ago it vanished (or at least seemingly vanished) because they decided to develop it further.  I have been keeping my eye open and occasionally checking for a Windows version and it’s now finally out!

If it’s good enough to scan your email it’s good enough to protect the desktop.  I suppose there are several schools of thought on this.  One saying you’ll want one AV scanner to scan inbound files on the server, a different one on the firewall (if it has that feature) and yet another on the desktop.  Sure – but for home losers like us anything that’s both good and free works for me!

The good thing about ClamAV for windows:

  • Real-Time Scanning
  • Simple feature set
  • Folder exclusion
  • Open Source



The bad thing about ClamAV:

  • Doesn’t seem to do a “full system scan” from the gui, I have a batch file to help you though (for WindowsXP, ClamAV version 1.0.26, feel free to edit for your OS’s directory path –> Here)
  • Currently have to be “online” for it to scan (they plan on offline in the future)



I’d HIGHLY recommend it though, it’s good enough for me!  –> Download

NTP stands for “Network Time Protocol“, it’s a method for computer time synchronization.  If your computer is a member of a Windows Domain your computer automatically synchronizes to the PDC or Primary Domain Controller.  The problem is, where does the PDC synchronize to? I found the domain clock off by 5 minutes today (and it wasn’t the first time), which I suppose isn’t that big of a deal unless you use the computer clock for things like appointments or meetings.    Better late than never right? :)

I found a cool website called ntp.org that will allow you to leverage their extremely accurate time servers.  If you have a windows server try these commands!  This is a combination of commands found here and here:

Network time is controlled by this method: net time /setsntp:pool.ntp.org
You can “refresh” a server or workstation with this command: net stop w32time && net start w32time

* I failed to mention this and I’m editing this old post.

Server command:  net time /setsntp:pool.ntp.org

Workstation command: net time /setsntp:yourserver.com

This way all your network hosts are staying on your internal network and you’re not killing poor ntp.org with all the requests :)

Have you ever WISHED you could capture a stream of your favorite audio program on the net?  What about capturing your favorite NPR program?  I know I know, they usually make them available for download but some sites don’t, all they do is stream it once and it’s gone forever especially some less popular websites or genres of music.

I found a program on the net call “MPlayer“.  It’s AWESOME!

Once you download it you have to figure out where it installed, if you have Windows XP like me it’s in your program files (C:\Program Files\SMPlayer\MPlayer).  If you open a command prompt and cd there like this…

cd\
cd “Program Files\SMPlayer\MPlayer”

You’re there!

Now you can issue a few commands like this.  These are some streams I helped a buddy hook onto but they’re great examples.

__________________________________________________________________

Captures a stream from The Pulse Rocks – some Christian Rock Music station into a wma file:

mplayer -dumpfile ThePulseRocks.wma -dumpstream -playlist http://www.thepulserocks.com/StreamFiles/wqrp2.asx

Captures a stream from The Pulse Rocks – some Christian Rock Music station into an mp3 file:

mplayer -dumpfile ThePulseRocks.mp3 -dumpstream -playlist http://www.thepulserocks.com/StreamFiles/wqrp2.asx

Although NPR usually makes their shows available for download here is one for WMUK in Kalamazoo, MI:

mplayer -dumpfile WMUK.wma -dumpstream -playlist http://ummedia12.rs.itd.umich.edu:8004/listen.pls

* New – Capture “French in action” from Learner.org :-)

Windows:

mplayer -dumpfile French_03.asf -dumpstream mms://media.scctv.net/annenberg/French_In_Action_03.wmv

mplayer -dumpfile French_04.asf -dumpstream mms://media.scctv.net/annenberg/French_In_Action_04.wmv

Mac (Thanks for my good buddy Mark!):

./Applications/MPlayer\ OS\ X\ 2.app/Contents/Resources/mplayer.app/Contents/MacOS/mplayer -dumpfile French_03.asf -dumpstream mms://media.scctv.net/annenberg/French_In_Action_03.wmv

./Applications/MPlayer\ OS\ X\ 2.app/Contents/Resources/mplayer.app/Contents/MacOS/mplayer -dumpfile French_04.asf -dumpstream mms://media.scctv.net/annenberg/French_In_Action_04.wmv

…etc!  Enjoy!

__________________________________________________________________

You could do a lot of different things with this tool.  One serious challenge is to find the source for your stream.  If WMUK didn’t post their direct link on their help URL I would have struggled to figure it out (but I would have gotten it eventually!).  I might post some methods to find your stream source or just let me know if you need some help!

Lastly, you can even capture streaming video!

I learned this command from a colleague at my present job and over the past two weeks have learned to LOVE it.  The “AT Command” which schedules a task on either local or remote PC’s.  I only use it on XP PC’s so I’m not sure if it’s available on other OS’s like Vista, Windows 7 or legacy OS’s.

There’s also another command which Microsoft says is “more powerful” – schtasks.  This command replaces the “at” command and is probably more relevant to the newer OS’s like Vista and Windows 7.

In the end I think the syntax is similar so using either is your choice!

If you want to schedule a command locally use a command like this:

at 00:00 “\\yourserver\yourshare\batchfile.bat”

This simply schedules the task “at” midnight on your local computer calling “batchfile.bat”, within “batchfile.bat” you can have your script which does something.  Maybe it installs software, deletes files, sets security permissions, etc, etc?  Possibilities are a plenty!

Here are some more examples of an at job:

:: Schedules a job at midnight on a remote PC

at \\networkcomputer 00:00 “\\yourserver\yourshare\batchfile.bat”

:: Schedules a job next tuesday on a remote PC

at \\networkcomputer 00:00 /next:Tuesday “\\yourserver\yourshare\batchfile.bat”

:: View a scheduled task on a remote computer

at \\networkcomputer

:: Delete a scheduled task on a remote computer, job number 1, if it’s job 15 you’d replace the 1 with 15

at \\networkcomputer 1 /delete

at \\network computer 15 /delete

:: Schedule a job at midnight every Tuesday

at \\networkcomputer 00:00 /every:Tuesday “\\yourserver\yourshare\batchfile.bat”

:: Here’s a for loop to schedule a job on a list of PC’s at 11 PM:

for /f %i in (c:\pclist.txt) do at \\%i 23:00 “\\yourserver\yourshare\batchfile.bat”

:: Here’s a for loop to delete the scheduled job on a list of PC’s at 10 PM just in case you want to delete the job!

for /f %i in (c:\pclist.txt) do at \\%i 1 /delete

 

I hope this helps anyone looking for AT command help!

After looking on the web and getting NO answers I finally bumped into an M$ article on the subject –> Here.  It was helpful so check it out if you have questions or ask me!  I’m finding searching the Internet for solutions these days a daunting task so hopefully some search engine will find this worthy and move it to the top of their list.

MSIZAP – first, get it from the link below…this is version2 of MSIZAP and includes both the 32 bit and 64 bit versions, just read the “readme.txt” file in the archive for more details.  The MSIZAP.EXE is the 32 bit one, I renamed the MSIZAPU.EXE to just MSIZAP.EXE.  For your computing pleasure the GUI is also included ;-)

Download MSIZAP.EXE –> Here

I experimented with 7 zip’s MSI –> Here, extracted to “C:\Temp”.  Install it, open Add/Remove Programs in your Control Panel, make sure it’s installed.  After you confirm it’s installed you can then run this command to see what it does.  Open a command prompt, start > run > cmd > enter > cd \ > cd temp > type in the following and press enter:

msizap TPSWMG! “C:\temp\7z465.msi” > c:\temp\7zip.log

or what you’ll need to do is find the MSI package in your installer cache “C:\Windows\Installer\whatevermsi.msi”

msizap TPS! “C:\windows\installer\e85e2799.msi” > c:\temp\7zip.log

* Be sure to have all the exe’s in the same folder, I used “c:\temp”, my command prompt would be “c:\temp\msizp TPS!…etc”, I’m also not sure if 7zip’s installer cache ends up being e85e2799.msi for all installs but if it’s the same for you then it is, let me know!

Review your log, my logs did say it failed to clear all items but I think it’s good enough for government work!  Is a Windows system or any system for that matter really ever 100 percent clean?  I think anyone with an ounce of experience will tell you truthfully it’s no!  The end result will be the package being blown away (i.e. zapped!), it shouldn’t show up in the registry or the Control Panel’s Add/Remove Programs.  I’m still experimenting with the process but I thought it valuable to have some clarity with the command syntax and thanks to M$’s command help page I found we can all benefit.

Tail is a helpful Linux utility and Windows also has a tail option, but you have to download it.  It’s part of the “Windows Server 2003 Resource Kit Tools” from Microsoft.  As of this posting I don’t think there is a resource kit for Server 2008 that’s been released but I bet this version works on 08 as well.  There are other tail versions on the net for Windows but I’d stick with what M$ provides in the resource kit, it’s simple and just works!

This small helpful utility allows you to watch log files as they populate or fill up in a command prompt.  Download it –> Here or you can download the resource kit previously mentioned where the file is also contained.

What you should do is copy tail.exe to your “%systemroot%\system32″, on my machine it’s “C:\Windows\System32 but depending on how Windows was installed yours might be different.  Click Start > Run > copy that %system…line in quotes into the run dialog then click OK, then copy your tail.exe into that folder.

by default many Windows log files are kept in a subdirectory in your System32 folder, particularly the firewall log on a Windows XP systems ( “%windir%\System32\LogFiles”).  I’d poke around and see what you see.  Lets next open a command prompt, Start > Run > CMD.

Lets try the firewall.log file!

Type:

tail -f  “%windir%\pfirewall.log”

Your firewall log file might be in a different location so be sure to find it and change where tail is looking, if it’s wrong tail won’t work until it can read a file that exists.  Depending on what your firewall is logging you should see your screen light up with activity.  This can be particularly helpful for troubleshooting potential firewall problems, or maybe you’re running IIS servers or other servers that log to readable text based files.  If so tail is for you!

Lastly – from the command line you can type “tail /?” for options, there aren’t many but you might want to display only the last 50 lines of the log in your screen.  For this we’d type:

tail -n 50 -f “c:\whateverfolders\morefolders\yourlogfile.log”

50 lines are easier to follow than the default 10 lines.

Have you ever needed to gather system information from remote machines and wish you had a sweet script or batch file to do it?  I happened to have one!

It’s an easy one, Keep It Simple Stupid (KISS) right?

What you’ll need:

  • sysinfo.exe (which I bumped into on Windows XP in some service pack directory)
  • Text file of machines you want to query

You can find sysinfo.exe in “C:\Windows\ServicePackFiles\i386″, for the list of machines to query it’s all you!

Here’s what to do:

Put your sysinfo.exe and pclist.txt files in a directory anywhere on your computer.  Open a command prompt, Start > Run > CMD > OK.  Navigate to the directory with sysinfo.exe and your text file in it.

Type:  for /f %i in (pclist.txt) do sysinfo /S %i /U %i\administrator /P “your local admin password can have spaces” /FO CSV >>PClist.csv

What this does is “for” every line  in your text file (computer1, computer2, etc) it calls the sysinfo.exe command to get the system information of a particular system, i.e. /S %i.  By using our “for loop” we tell it to iterate through the file repeating our system information request on as many machines as we’ listed in the text file.  Our command continues executing on each line then it appends the result “>>” to a CSV file we can then open with Excel or manipulate in other ways.

/S is system, specifying the REMOTE system connection

/U is our credentials, domain\username OR as we did %i\username, we used the local administrator account!

/P is our password, it’s plain text here people so don’t type this while Joe Shmoe is looking over your shoulder!

/FO is our format, we specified a CSV but you also have “TABLE” and “LIST” which might be helpful.

You should get output that has great information in it.  The stuff I was looking for were host-name, OS, a hardware vender like Dell, HP, etc what type of processor it has, the up-time is great to have, how many processors it has (class of processor) and the service pack level.  It’s an easy way to run a quick audit because it also lists the patches you have installed, it doesn’t hurt to take a quick look at them.

Do you need to install Java with an MSI installer?  This is how you do it!

* Based on instructions from Sun with tweaks because their instructions are a bit off

Download the latest Java from here but pick the “Offline” link –> Java

Install it without the Yahoo Toolbar – (who really wants that anyway?).  Once installed go to this folder on your Windows XP system.

“C:\Documents and Settings\%username%\Application Data\Sun\Java”, there you’ll see folders for whatever versions you’ve installed.  Open the newest folder and find your MSI.

* C:\Documents and Settings\%username%\Application Data\Sun\Java\whateverversionyoujustinstalled\yourjavaversion.msi

You can push it out via several methods.

  1. Make an Active Directory Group Policy (best method!)
  2. Batch file:  msiexec /i jre1.6.0_17.msi

Test your Java Version here –> Test Java Version

Any questions let me know and I’ll post them with a solution!

Powered by WordPress Web Design by SRS Solutions © 2010 RafaelWolf.com Design by SRS Solutions
2 visitors online now
2 guests, 0 members
Max visitors today: 4 at 06:25 am GMT+5
This month: 14 at 09-07-2010 06:16 pm GMT+5
This year: 36 at 08-30-2010 02:32 am GMT+5
All time: 36 at 08-30-2010 02:32 am GMT+5