Monthly Archive for August, 2007

The Solution to Windows Vista setup error code 0×80070241

I ran into this error 0×80070241 from the Windows Vista setup at around 50%. It turns out that there are hardly ANY good solutions online. I searched and searched and only found people saying they have found nothing and no fix, including MVPs.

Then, I ran across a little comment buried deep in a blog complaining about it somewhere that said to download Vlite and recompile the image and run it from the hard drive.

Guess what? It works great!

So here is the link to VLite: http://www.vlite.net/download.html

All you have to do is download it, direct the program to the extracted setup files (extract them with winrar) and recompile the image using the wizard built into VLite.

Hopefully this gives enough Google rank that it becomes useful to some people out there!

Automatic and Dynamic All Purpose NTBackup.exe Script with Email Notifications and Log Archiving (EricBackup.bat)

This script can do a SystemState, Normal or Differential backup via NTBackup from any location, to any location and have an email report sent to you shortly before the logfile is archived in your designated directory. All you have to do is set all the settings that i describe below in the top section of the script, put in any mapped drives you need to be mapped (net use x: \\server\share /user:user pass) where I have it commented and run it with the desired backup type specified. You can run ericbackup.bat alone to see a help display, too. This certainly isn’t anything new, but it is handy because this script can be easily molded, with it’s built in settings, to work in almost any situation. If you are running this as a task, you must remember to include the type of backup in the run line of the task. Simply specifying the .bat will not work, you must specify as the example useage below shows.

I would also like everyone to know that this file can be run remotely with psexec… see this article for PowerShell and this article for batch on how to do that. But remember: If you use psexec to run this remotely, the user will be “Default User”.

blatpathThe path to blat.exe, which is used to email your reports to you.
relayserverAn email server your computer has access to. This is required to have your report email sent to you.
emailThe email your reports will be sent to.
fromemailThis is the address the email will appear to be sent from. Important because some mailservers will filter mail baised ont his. Your own email should be fine.
emailuserYour email server user login.
emailpassYour email server password.
sourceThe directory your backup will be targeting. Systemstate backups will ignore this automatically. If you’re targeting the root of a drive, you leave out the ending \ character (ex: c: not c:\). If you want to use a ANSI .bks file, you can specify that here with an @ symbol ahead of it. EX) @c:\filelist.bks Using a unicode .bks file lets you list multiple target locations.
destinationThe location your backup files will be placed into… in *.BKF format. If you’re targeting the root of a drive, you leave out the ending \ character (ex: c: not c:\).
textlogpathPath to the text logfile which will track progress and be emailed then archived.
archivepathThe place logs will be placed for storage. Files will be renamed appropriately.
usernameThis is very important. This is the name of the folder in your user profile. For example, if you opened a CMD window you would see the path to your local profile. This variable is the name of the last folder in that path. If my user folder is eric.greer then this will be eric.greer. Most of the time this folder name is the exact same as the user name it will run under. If this script is running in remotely via PSExec or as the system account, it will require Default User, without quotes, to be entered here.
note
Just a note. This will be placed on your email subject along with on the filename. Good to include the location. Spaces are not supported very well here, and don’t use quotation marks either.

Example Useage: (After setting variables on the top of the script!)

ericbackup.bat normal

ericbackup.bat systemstate

ericbackup.bat differential

This will start a normal backup with the settings you specified within the batch file.

EricBackup.bat

@echo off
:Variables

REM Insert your variables below before running this batch from the command line.

set blatpath=c:\programs\blat.exe
set relayserver=localhost
set email=blog@integrii.net
set fromemail=blog@integrii.net
set emailuser=your.user
set emailpass=your.pass
set source=C:\Scripts
set destination=K:\Backup
set textlogpath=K:\Backup\%computername%-Backup.txt
set archivepath=K:\Backup\OldLogs
set username=administrator
set note=ScriptsBackup

REM Map your drives here if you need to.

REM If you use psexec to run this remotely, the user will be "Default User"
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.
REM Dont touch anything below here.

:TimeStuffFromMichaelSmith

for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set Month=%%j
set Day=%%k
set Year=%%l
set Date=%%j-%%k-%%l
set dirdate=%%j%%k%%l
)
for /f "Tokens=1-2 delims=/ " %%i in ('time /t') do (
set tm=%%i
set ampm=%%j
)

:Preparation

echo.
echo **************************
echo EricBackup.bat Version 2.8
echo EricGreer@GMail.com
echo http://blog.integrii.net/?p=76
echo **************************
echo.

if "%1" == "systemstate" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo
if "%1" == "normal" set backupmode=normal & echo "%1 mode selected." & goto goodtogo
if "%1" == "differential" set backupmode=differential & echo "%1 mode selected." & goto goodtogo
if "%1" == "Systemstate" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo
if "%1" == "Normal" set backupmode=normal & echo "%1 mode selected." & goto goodtogo
if "%1" == "Differential" set backupmode=differential & echo "%1 mode selected." & goto goodtogo
if "%1" == "SystemState" set backupmode=systemstate & echo "%1 mode selected." & goto goodtogo

goto noparams

:goodtogo

set server=%computername%
set logpath=C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data

if not exist "%archivepath%" md "%archivepath%" & echo "Archive Path did not exist, so it was created." >> %textlogpath%
if exist "%textlogpath%" del "%textlogpath%" & echo "Previous %textlogpath% existed, so it was deleted." >> %textlogpath%
if exist "%logpath%\*.log" del "%logpath%\*.log" & echo "Previous ntbackup logfile existed, so it was deleted." >> %textlogpath%

:Backup

echo %server% backup started at %tm% %ampm% on %Year%-%Month%-%Day% into "%destination%" >> %textlogpath%
echo %server% backup starts %tm% %ampm% on %Year%-%Month%-%Day% into "%destination%"

if %backupmode% == systemstate ntbackup.exe backup systemstate "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-SYSTEMSTATE.bkf" >> %textlogpath%
if %backupmode% == differential ntbackup.exe backup "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /m differential /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-DIFFERENTIAL.bkf" >> %textlogpath%
if %backupmode% == normal ntbackup.exe backup "%source%" /n "%server%-Backup" /d "%server%-Backup" /v:no /r:no /rs:no /hc:off /m normal /j "%server%-Backup" /l:s /f "%destination%\%server%-Backup-%Year%-%Month%-%Day%-NORMAL.bkf" >> %textlogpath%

:RenameLogs

if exist "%logpath%\*.log" ren "%logpath%\*.log" %server%-Backup.log
if exist "%logpath%\%server%-Backup.log" copy "%logpath%\%server%-Backup.log" "%archivepath%" /y

echo NTBackup.exe .log file archived at "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log" >> %textlogpath%
echo EricBackup.bat .txt file archived at "%archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt" >> "%textlogpath%"

:Send
%blatpath% "%textlogpath%" -attach "%archivepath%\%server%-Backup.log" -t %email% -s "%server% Backup Log %Year%-%Month%-%Day% at %tm% %ampm%" -i %fromemail% -f "%fromemail%" -q -server "%relayserver%" -u "%emailuser%" -pw "%emailpass%"

:Archive
if exist "%archivepath%\templog.txt" del "%archivepath%\templog.txt"
if exist %textlogpath% copy "%textlogpath%" "%archivepath%\templog.txt"
if exist "%archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt" del %archivepath%\%Year%-%Month%-%Day%-%server%-%note%.txt
if exist %archivepath%\templog.txt ren %archivepath%\templog.txt "%Year%-%Month%-%Day%-%server%-%note%.txt"

if exist "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log" del "%archivepath%\%note%-%server%-%Year%-%Month%-%Day%.log"
if exist "%archivepath%\%server%-Backup.log" ren "%archivepath%\%server%-Backup.log" "%note%-%server%-%Year%-%Month%-%Day%.log"
if exist "%archivepath%\%server%-Backup.log" del "%archivepath%\%server%-Backup.log"
if exist "%logpath%\%server%-Backup.log" del "%logpath%\%server%-Backup.log"

if exist "%textlogpath%" del "%textlogpath%"

goto eof

:noparams
echo This file must be configured by opening it in notepad and setting the variables in the variables section at the top of the script.
echo You do not need to touch anything else beyond the variables with remarks above them!
echo To run the file after you configure it in notepad you must specify a backup type as the first paramiter.
echo.
echo EXAMPLE 1:
echo ericbackup Systemstate
echo.
echo EXAMPLE 2:
echo ericbackup Normal
echo.
echo EXAMPLE 3:
echo ericbackup Differential
echo.
echo **************************
echo.

:eof

Download BLAT

This script has been a lot of work to get just right, and I would appreciate it if any problems are reported to me. This is a big timesaver for me and i use it every other day in different environments with no problems.

Start & Stop Remote Service with WPS [Dynamic Version]

Check out my other version of this, in which the service is directly specified in the script here.

This script is used to stop a remote service on your network via WMI and PowerShell. Much like the other version on this blog where you must specify the service and computer to target in the code, this script does not require that. This script is given two variables, the first being the service name as it shows up in (get-wmiobject win32_service).Name and the second being the hostname of the remote computer you want to target. You could then make a third script to Restart-Remote-Service that would just simply call these one at a time, with the two specified variables.

That code looks like this:

stop-remote-service.ps1 $args[0] $args[1]
start-remote-service.ps1 $args[0] $args[1]

The script will give you a constant status of the service as it switches from running (in green) to stop pending (in yellow) and finally stopped (in red). I like the interactive status updating a lot.

Here’s how you use them:

./Start-Remote-Service.ps1 helpsvc IISServ

./Stop-Remote-Service.ps1 helpsvc IISServ

Here’s a practical example:

PS C:\Scripts> get-wmiobject win32_service -computer IISServ | fw

Then, you find the name of the service you want in the list and do this:

PS C:\Scripts> Stop-Remote-Service.ps1 helpsvc IISServ

The help service on computer IISServ will halt.

Enjoy!

Stop-Remote-Service.ps1

#ericgreer@gmail.com
#stop remote service script

$service = $args[0]
$computer = $args[1]

$query = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”})

$state = $query.State

if (((($query).name).length) -gt 0){

$trigger = 0

while ($state -eq “Running”) {
write-host “`r$service is $state” -nonewline -foregroundcolor green
sleep -milliseconds 100
if ($trigger -lt 1) {
$query.stopservice() | out-null
$trigger = 1
}
$state = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”}).State
}

while ($state -eq “Stop Pending”) {
write-host “`r$service is $state” -nonewline -foregroundcolor yellow
sleep -milliseconds 100
$state = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”}).State
}

if ($state -eq “Stopped”) {
write-host “`r                                   ” -nonewline
write-host “`r$service is $state`n” -nonewline -foregroundcolor red
}

if ($state -eq “Running”) {
write-host “`r                                   ” -nonewline
write-host “`r$service is $state (Failed to Stop)`n” -nonewline -foregroundcolor Green
}
}

else {
write-host “$service not found on $computer” -foregroundcolor Red
write-host “Try: gwmi win32_service -computer $computer | ft” -foregroundcolor green
}

Start-Remote-Service.ps1

#ericgreer@gmail.com
#start remote service script

$service = $args[0]
$computer = $args[1]

$query = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”})

$state = $query.State

if (((($query).name).length) -gt 0){

$trigger = 0

while ($state -eq “Stopped”) {
write-host “`r$service is $state” -nonewline -foregroundcolor red
sleep -milliseconds 100
if ($trigger -lt 1) {
$query.startservice() | out-null
$trigger = 1
}
$state = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”}).State
}

while ($state -eq “Start Pending”) {
write-host “`r$service is $state” -nonewline -foregroundcolor yellow
sleep -milliseconds 100
$state = (gwmi win32_service -computer $computer | where-object {$_.Name -eq “$service”}).State
}

if ($state -eq “Running”) {
write-host “`r                                   ” -nonewline
write-host “`r$service is $state`n” -nonewline -foregroundcolor green
}

if ($state -eq “Stopped”) {
write-host “`r                                   ” -nonewline
write-host “`r$service is $state (Failed to Start)`n” -nonewline -foregroundcolor red
}
}

else {
write-host “$service not found on $computer” -foregroundcolor Red
write-host “Try: gwmi win32_service -computer $computer | ft” -foregroundcolor green
}

Start & Stop Remote Service with WPS [Static Version]

These scripts remotely start and stop a set service with WMI through PowerShell. All you have to do is change the service from ‘Your Service’ to the display name of the service you want to halt, then chnage the ‘Your Computer’ blank to the hostname or IP of the computer the service is running on. The ‘Static Version’ tag above means that this service is specified within the script, and not by the user each time.

The script will give you a constant status of the service as it switches from running (in green) to stop pending (in yellow) and finally stopped (in red). I like the interactive status updating a lot.

Start-Remote-Service.ps1

#SETTINGS
$service = “Your Service”
$computer = “Your Computer”

$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
$trigger = 0

while ($state -eq “Stopped”) {
write-host “`r$service is $state” -nonewline -foregroundcolor red
sleep -milliseconds 100
if ($trigger -lt 1) {
(gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).startservice() | out-null
$trigger = 1
}
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

while ($state -eq “Start Pending”) {
write-host “`r$service is $state” -nonewline -foregroundcolor yellow
sleep -milliseconds 100
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

#SETTINGS
$service = “Servers Alive”
$computer = “Vesuvius”

$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
$trigger = 0

while ($state -eq “Stopped”) {
write-host “`r$service is $state” -nonewline -foregroundcolor red
sleep -milliseconds 100
if ($trigger -lt 1) {
(gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).startservice() | out-null
$trigger = 1
}
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

while ($state -eq “Start Pending”) {
write-host “`r$service is $state” -nonewline -foregroundcolor yellow
sleep -milliseconds 100
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

if ($state -eq “Running”) {
write-host “`r ” -nonewline
write-host “`r$service is $state`n” -nonewline -foregroundcolor green
}

if ($state -eq “Stopped”) {
write-host “`r ” -nonewline
write-host “`r$service is $state (Failed to Start)`n” -nonewline -foregroundcolor red
}

Stop-Remote-Service.ps1

#SETTINGS
$service = “Your Service”
$computer = “Your Computer”

$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
$trigger = 0

while ($state -eq “Running”) {
write-host “`r$service is $state” -nonewline -foregroundcolor green
sleep -milliseconds 100
if ($trigger -lt 1) {
(gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).stopservice() | out-null
$trigger = 1
}
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

while ($state -eq “Stop Pending”) {
write-host “`r$service is $state” -nonewline -foregroundcolor yellow
sleep -milliseconds 100
$state = (gwmi -query “select * from win32_service where DisplayName=’$service’” -computer $computer).State
}

if ($state -eq “Stopped”) {
write-host “`r ” -nonewline
write-host “`r$service is $state`n” -nonewline -foregroundcolor red
}

if ($state -eq “Running”) {
write-host “`r ” -nonewline
write-host “`r$service is $state (Failed to Stop)`n” -nonewline -foregroundcolor Green
}

You can rename this script to anything you like once you set the service name and target computer, effectively giving you control over all your most important services. Works like a charm for monitoring software.