beatcracker / VSCELicense

PowerShell module to get and set Visual Studio Community Edition license expiration date in registry
Microsoft Public License
304 stars 95 forks source link

cscript? #8

Closed pipiscrew closed 4 years ago

pipiscrew commented 4 years ago

hi,

any possibility to convert it to CScript ?

here on win7 w/ powershell v2, cant work. I dont need to install 64mb of Windows Management Framework just to run this script.. .

https://i.imgur.com/jIHqyjG.jpg

pipiscrew commented 4 years ago
using Microsoft.Win32;
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;

//read license
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"Licenses\41717607-F34E-432C-A138-A3CFD7E25CDA\09278",true);
//RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Licenses\41717607-F34E-432C-A138-A3CFD7E25CDA\09278", true);
byte[] data = (byte[])key.GetValue(null);

//unprotect
byte[] unprotected = ProtectedData.Unprotect(data, null, DataProtectionScope.LocalMachine);
//Array.Reverse(unprotected);

//store the array position for the date
int unprotected_date_index = unprotected.Length - 16;

//create an array with the needed data only
byte[] needed = new byte[6];
Array.Copy(unprotected, unprotected_date_index, needed, 0, 6);
Console.WriteLine(BitConverter.ToInt16(needed.Take(2).ToArray<byte>(), 0));
Console.WriteLine(BitConverter.ToInt16(needed.Skip(2).Take(2).ToArray<byte>(), 0));
Console.WriteLine(BitConverter.ToInt16(needed.Skip(4).Take(2).ToArray<byte>(), 0));

//create our new expiration date
DateTime d = DateTime.Now.AddYears(1);

//copy to array
byte[] newdate = new byte[6];
Array.Copy(BitConverter.GetBytes(d.Year), newdate, 2);
Array.Copy(BitConverter.GetBytes(d.Month), 0, newdate, 2,2);
Array.Copy(BitConverter.GetBytes(d.Day), 0, newdate, 4, 2);

//copy back the needed data
Array.Copy(newdate, 0, unprotected, unprotected_date_index, 6);

//protect the modified unprotected
byte[] protected_modded = ProtectedData.Protect(unprotected, null, DataProtectionScope.LocalMachine);

key.SetValue(null, protected_modded, RegistryValueKind.Binary);
//key2.SetValue(null, protected_modded, RegistryValueKind.Binary);