Shorten the Windows Subscription check code

This commit is contained in:
WindowsAddict 2024-07-13 04:18:44 +05:30
parent 48fb5fc5fe
commit b7c3f9a98a
3 changed files with 33 additions and 75 deletions

View File

@ -829,30 +829,16 @@ exit /b
:: Get Windows Subscription status :: Get Windows Subscription status
:winsubstatus: :winsubstatus:
$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2) $DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)
$SB = $DM.DefineType('sub_status', 9, [ValueType], 0) [void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$m = [System.Runtime.InteropServices.Marshal]
('enabled#int', 'sku#int', 'state#int').ForEach({ $p = $m::AllocHGlobal(12)
$i = $_ -split '#' $r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)
$n = $i[0]
$t = $i[1] -as [Type]
[void]$SB.DefineField($n, $t, 6)
})
$sub_status = $SB.CreateType()
$MB = $DM.DefineType('PInvoke')
[void]$MB.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [UInt32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$Clipc = $MB.CreateType()
$s = [Activator]::CreateInstance($sub_status)
$p = [Runtime.InteropServices.Marshal]::AllocHGlobal([Runtime.InteropServices.Marshal]::SizeOf($s))
$r = $Clipc::ClipGetSubscriptionStatus([ref]$p)
if ($r -eq 0) { if ($r -eq 0) {
$s = [Runtime.InteropServices.Marshal]::PtrToStructure($p, [type]$sub_status) $enabled = $m::ReadInt32($p)
if ($s.enabled -ne 0) { if ($enabled -ge 1) {
if ($s.state -eq 1) { $state = $m::ReadInt32($p, 8)
if ($state -eq 1) {
"Subscription_is_activated." "Subscription_is_activated."
} }
} }

View File

@ -925,30 +925,16 @@ exit /b
:: Get Windows Subscription status :: Get Windows Subscription status
:winsubstatus: :winsubstatus:
$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2) $DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)
$SB = $DM.DefineType('sub_status', 9, [ValueType], 0) [void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$m = [System.Runtime.InteropServices.Marshal]
('enabled#int', 'sku#int', 'state#int').ForEach({ $p = $m::AllocHGlobal(12)
$i = $_ -split '#' $r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)
$n = $i[0]
$t = $i[1] -as [Type]
[void]$SB.DefineField($n, $t, 6)
})
$sub_status = $SB.CreateType()
$MB = $DM.DefineType('PInvoke')
[void]$MB.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [UInt32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$Clipc = $MB.CreateType()
$s = [Activator]::CreateInstance($sub_status)
$p = [Runtime.InteropServices.Marshal]::AllocHGlobal([Runtime.InteropServices.Marshal]::SizeOf($s))
$r = $Clipc::ClipGetSubscriptionStatus([ref]$p)
if ($r -eq 0) { if ($r -eq 0) {
$s = [Runtime.InteropServices.Marshal]::PtrToStructure($p, [type]$sub_status) $enabled = $m::ReadInt32($p)
if ($s.enabled -ne 0) { if ($enabled -ge 1) {
if ($s.state -eq 1) { $state = $m::ReadInt32($p, 8)
if ($state -eq 1) {
"Subscription_is_activated." "Subscription_is_activated."
} }
} }

View File

@ -2268,30 +2268,16 @@ exit /b
:: Get Windows Subscription status :: Get Windows Subscription status
:winsubstatus: :winsubstatus:
$DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2) $DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)
$SB = $DM.DefineType('sub_status', 9, [ValueType], 0) [void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$m = [System.Runtime.InteropServices.Marshal]
('enabled#int', 'sku#int', 'state#int').ForEach({ $p = $m::AllocHGlobal(12)
$i = $_ -split '#' $r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)
$n = $i[0]
$t = $i[1] -as [Type]
[void]$SB.DefineField($n, $t, 6)
})
$sub_status = $SB.CreateType()
$MB = $DM.DefineType('PInvoke')
[void]$MB.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [UInt32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$Clipc = $MB.CreateType()
$s = [Activator]::CreateInstance($sub_status)
$p = [Runtime.InteropServices.Marshal]::AllocHGlobal([Runtime.InteropServices.Marshal]::SizeOf($s))
$r = $Clipc::ClipGetSubscriptionStatus([ref]$p)
if ($r -eq 0) { if ($r -eq 0) {
$s = [Runtime.InteropServices.Marshal]::PtrToStructure($p, [type]$sub_status) $enabled = $m::ReadInt32($p)
if ($s.enabled -ne 0) { if ($enabled -ge 1) {
if ($s.state -eq 1) { $state = $m::ReadInt32($p, 8)
if ($state -eq 1) {
"Subscription_is_activated." "Subscription_is_activated."
} }
} }