OK, with the usual "Use this at your own risk! No warranty or guarantee or support offered! Don't come crying to me if something bad goes wrong!" proviso, here's a script that should work:
Code:
@echo off
setlocal
color 9f
Title %userdomain% Activating Windows and MS Office
echo %userdomain% Windows and Office activation script
echo. Setting variables...
set WindowsFlag=%AllUsersProfile%\DoneWindowsActivation.flg
set OfficeFlag=%AllUsersProfile%\OfficeActivated.flg
set slmgrLog=%AllUsersProfile%\slmgr.log
set osppLog=%AllUsersProfile%\ospp.log
set WindowsKey=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
set ErrorLog=%AllUsersProfile%\ActivationErrorLog.log
if /i exist %ErrorLog% del %ErrorLog%
set eCount=0
:main
echo. Is Windows already activated?
if /i not exist %WindowsFlag% goto ActivateWindows
echo. Apparently so. Skipping to Office activation...
goto ActivateOffice
:ActivateWindows
echo. Apparently not. Activating Windows...
if /i exist "%windir%\System32\Slmgr.vbs" goto RunWindowsActivation
echo. *************************************************************************
echo. * Windows Activation script not found! Skipping to Office Activation... *
echo. *************************************************************************
set /a eCount=%eCount%+1
echo Error %eCount%:>>%ErrorLog%
echo Windows Activation script '%windir%\System32\Slmgr.vbs' not found>>%ErrorLog%
goto ActivateOffice
:RunWindowsActivation
cscript //nologo "%windir%\System32\Slmgr.vbs" /ipk %WindowsKey% >%slmgrLog%
:: Having sent the output from the VBS to the log file, we now check that log file for the word 'Error'
:: If the FindStr command finds the word 'Error' then it returns an errorlevel code of 0 so we increment our Error Counter (eCount)
:: If it doesn't find the word 'Error' then no error was recorded, move on to the second run of the VBS
findstr Error %slmgrLog% >nul
if %errorlevel% geq 1 goto SecondRun
set bWinActErr=True
set /a eCount=%eCount%+1
echo Error %eCount%:>>%ErrorLog%
echo First run of '%windir%\System32\Slmgr.vbs' produced following error:>>%ErrorLog%
type %slmgrLog% >>%ErrorLog%
del %slmgrLog%
:SecondRun
cscript //nologo "%windir%\System32\Slmgr.vbs" /ato >%slmgrLog%
:: Having sent the output from the VBS to the log file, we now check that log file for the word 'Error'
:: If the FindStr command finds the word 'Error' then it returns an errorlevel code of 0 so we increment our Error Counter (eCount)
:: If it doesn't find the word 'Error' then no error was recorded, move on to the 'DoneWindowsActivation' label
findstr Error %slmgrLog%>nul
if %errorlevel% geq 1 goto DoneWindowsActivation
set bWinActErr=True
set /a eCount=%eCount%+1
echo Error %eCount%:>>%ErrorLog%
echo Second run of '%windir%\System32\Slmgr.vbs' produced following error:>>%ErrorLog%
type %slmgrLog% >>%ErrorLog%
:DoneWindowsActivation
echo. Windows activation script completed run on %computername%.
echo Windows activation script completed run on %computername%>%WindowsFlag%
:: If there were any errors in the Windows Activation process then we need to delete the flag file so this script
:: tries the Windows Activation again if run again.
if defined bWinActErr del %WindowsFlag%
:ActivateOffice
echo. Is Office already activated?
if /i not exist %OfficeFlag% goto CheckForOfficeScript
echo. Apparently so.
goto end
:CheckForOfficeScript
echo. Apparently not. Activating Office...
echo. Checking for MS Office activation script...
if /i exist "%ProgramFiles(x86)%\Microsoft Office\Office14\ospp.vbs" goto 32bit
if /i exist "%ProgramFiles%\Microsoft Office\Office14\ospp.vbs" goto 64bit
echo. *************************************************
echo. * Office activation script not found. Quitting. *
echo. *************************************************
set /a eCount=%eCount%+1
echo Error %eCount%:>>%ErrorLog%
echo Office Activation script '%windir%\System32\ospp.vbs' not found>>%ErrorLog%
goto end
:32bit
cscript //nologo "%ProgramFiles(x86)%\Microsoft Office\Office14\ospp.vbs" >%osppLog%
echo. Office (32bit) activated on %computername%>%OfficeFlag%
echo Office (32bit) activated on %computername%>%OfficeFlag%
goto CheckForOfficeErrors
:64bit
cscript //nologo "%ProgramFiles%\Microsoft Office\Office14\ospp.vbs" >%osppLog%
echo. Office (64bit) activated on %computername%>%OfficeFlag%
echo Office (64bit) activated on %computername%>%OfficeFlag%
:CheckForOfficeErrors
:: Again, check for the word 'Error' in the error log. If not found there were no errors recorded so skip to the end
:: Otherwise, increment the error count and log the error text.
findstr Error %osppLog%
if %errorlevel% geq goto end
set /a eCount=%eCount%+1
:: Since there were errors in the Office Activation process we need to delete the flag file so this script
:: tries the Office Activation again if run again.
del %OfficeFlag%
echo Error %eCount%:>>%ErrorLog%
echo '%windir%\System32\ospp.vbs' produced following error:>>%ErrorLog%
type %osppLog% >>%ErrorLog%
:end
echo.
echo %userdomain% Activating Windows and MS Office script finished.
if %eCount%==0 goto eof
if %ecount%==1 (
echo There was %eCount% known error.
) ELSE (
echo There were %eCount% known errors.
)
if /i not exist %ErrorLog% goto eof
Echo Error Log:
echo ----------
type %ErrorLog%
:eof
Title %userdomain% Activating Windows and MS Officescript finished. Known error count = %eCount%
Now, I got errors because
A)I didn't have a Windows Product Key to test with. You'll need to change the hardcoded XXXX-XXXX-XXXX-XXXX to something useable.
B) The PC I was using didn't have MS Office installed.
You can run this script manually once logged on to the PC, or from as a Startup script in a GPO that applies to the OU or OUs that your Windows7 with Office 14 PCs' Computer Accounts get dropped in to.
The script tests for both 32bit and 64bit install paths for Office.
Also, it creates flag files (one for Windows, one for Office) so that if the script is run more than once it doesn't actually try to activate Windows or Office again. These flag files are deleted if the vbs files produce errors.
Look for these flag files in %AllUsersProfiles% (C:\ProgramData). They're called 'DoneWindowsActivation.flg' and 'OfficeActivated.flg'. Just delete them manually if you want the script to run fully again.
You can also refer to the main error log file (%AllUsersProfile%\ActivationErrorLog.log), which contains text like this:
Error 1:
First run of 'C:\Windows\System32\Slmgr.vbs' produced following error:
Error: 0xC004F025 Access denied: the requested action requires elevated privileges
Error 2:
Second run of 'C:\Windows\System32\Slmgr.vbs' produced following error:
Activating Windows(R) 7, Professional edition (9abf5984-9c16-46f2-ad1e-7fe15931a8dd) ...
Error: 0xC004F025 Access denied: the requested action requires elevated privileges
Error 3:
Office Activation script 'C:\Windows\System32\ospp.vbs' not found
Alternatively, if you're using an image to deploy PCs then add in RunOnce entries for each of the VBS files to the HKLM key (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce) immediately prior to taking the image (i.e. as the last thing you do). In theory, thes scripts will run on a new PC after the image has been applied to it and it's rebooted in to Windows.
JJ
[small][purple]
Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]