JSI Tip 6690. How can I toggle Windows Product Activation (WPA) on and off?

Alex K. Angelopoulos, a fellow MVP, contributed the following:

The Windows Server 2003 Activation notification is a significant annoyance
when I'm doing testing, since I often run a system for a good month or so
then trash it and start over; I don't tend to activate until close to the
activation deadline just in case anyway.  It gets REALLY annoying when I'm
doing TS testing, since I may run 5-6 sessions with admin permissions off
the same test server at once.

Here's a script I use for toggling the notification off and back on, with
a few bells and whistles.  Here's how it works.  \{WARNING - this just
toggles the notification; if you use it, make sure you're tracking when
you actually need to activate - it WILL need to do it within 60 days.\}

If you run it with no arguments, it assumes it will be executed against
the local host; if run with a single argument, it deals with WPA
notification on a system with the name you supplied as an argument.

If the system is already activated, it echoes a message to that effect and
quits.  If not, it handles a couple of things.
First, it echoes out current status of the wpabaln notification,
servername, remaining grace period, and the install ID (just in case you
screw up, forget the install date, and need to activate in a hurry).
Second, it toggles the notification status - so if you have it switched
off and want to kick it back on, it does so.  Every time you run it it
toggles the notification.

If you need to do phone/fax activation, the install ID echo is extremely
useful; instead of needing to read off a 54-character string from the
server console, you can have it handy...

Option Explicit
dim host, wpa, str(7), bNotify, iid, friendlyhostname

Select case wscript.arguments.count
	case 0
		' if no arguments, then we assume we want the local host
		host = "."
		friendlyhostname = "The local system"
	case 1
		host = WScript.Arguments(0)
		friendlyhostname = host
	case else
		wscript.echo "Supply either no arguments or a single remote host name."
end select

set wpa = GetFirstInstance(host, "Win32_WindowsProductActivation")
' get info on whether activation is required

if wpa.ActivationRequired then
	str(0) = friendlyhostname & " still needs to be activated."
	str(1) = "Server: " & wpa.ServerName
	bNotify = CBool(wpa.IsNotificationOn)
	str(2) = "Notification On? " &  yn(CBool(bNotify))
	str(3) = "Grace Period (days): " &  wpa.RemainingGracePeriod
	Call  wpa.GetInstallationID (iid)
	str(4) = "Install ID: " & iid
	str(5) =  "------ " & vbCrLf
	str(6) = "Toggle succeeded? " & yn(SetNotification(Not bNotify))

	' now refresh...
	set wpa = GetFirstInstance(host, "Win32_WindowsProductActivation")
	str(7) = "Notification status on now? " & yn(wpa.IsNotificationOn)
	wscript.echo Join(str, vbCrLf)
	' we don't need host any longer; reuse it.
	wscript.echo friendlyhostname, "has already been activated."
end if

function SetNotification(byval value)
	' sets notification status; returns true-false for success
	value = abs(CBool(value))
	SetNotification = Not CBool(wpa.SetNotification(value))
end function

function GetFirstInstance(host, \[class\])
	' Generic call to return the first instance of WMI
	' class "\[class\]" on "host".
	dim instances, instance
	set instances = GetObject("winmgmts:" _
	& "\{impersonationLevel=impersonate,(Backup)\}!\\" _
	& host & "\root\cimv2"). _
	for each instance in instances
		set GetFirstInstance = instance
		exit function
end function

function yn(bool)
	if CBool(bool) then yn = "Yes" else yn = "No"
end function

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.