Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 7 and Office 2010 Activation

Status
Not open for further replies.

JROY2011

IS-IT--Management
Aug 24, 2011
12
0
0
US
I don't know much about VBscripts, but I am thinking one could help me with my situation. I am creating my companies corporate image and we have volume license keys for both products. I would to run a script that would active both Windows 7 and Office 2010 without having to manually do it.

I have found that

"C:\Windows\System32\Slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
C:\Windows\System32\Slmgr.vbs /ato"

is what activates Windows 7

and

"c:\Program Files\Microsoft Office\Office14\ospp.vbs"

is what activates Office 2010. Can someone please write me a quick script that could run both of these files? Thanks in advance if this is possible.
 
What do you mean by write a script to run the files? They already are scripts...

What are you trying to achieve? Automatic Windows/Office Activation? If so, and assuming you have Active Directory, then you might look at using GPOs. Specifically a Computer Configuration GPO that runs the scripts as 'Startup Scripts'.

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]
 
Yes. I understand they are already scripts. Currently when our helpdesk images a pc, they have to go to my computer and activate windows, then open an office application for office to active as well. I would like to do a "run once" type of script that can run those scrips automatically after the pc boots up for the first time.
 
Yeah, that is annoying, and we have to do the same thing so let's help each other to work this out (you've already done your part by educating me that these scripts even exist!)

So, we want these scripts to run only once, although presumably if they work everytime a PC boots up there's not likely to be any harm done.

When a computer is added to the domain the account goes in to the Computers container (not the same as an OU). You can't apply a GPO directly to a container, only to OUs or to the root of the domain which would then apply to all other OUs and Containers.

If you move all computer accounts to more sensible OU to which a GPO can apply instead of applying at the domain root then this will be easy.

I usually create the Computer Account directly to the intended OU prior to joining a PC to the domain. So, I might try an OU called Activate, apply the GPO to run the startup scripts there then move the computer account to where it really belongs...but that's all getting a bit messy.

Loopback Processing is something I've heard of which might help here.

I'm waffling, it's late, I've had a couple of glasses of wine...I'll think on this more and try to come up with a more elegant solution.

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]
 
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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top