Jump to content

Recommended Posts

Posted

Since BAT/CMD scripts have become a real scripting language, there should be also a subforum in the Language Specific Discussion forum.    

Just to prove the power of BAT scripts, here a licence key script.  I know there is also a working au3 solution.

  Reveal hidden contents

@echo off
call :LicenseKeys >"%Temp%\~~%~n0.txt"
"%Temp%\~~%~n0.txt"
erase "%Temp%\~~%~n0.txt"
goto :eof

:LicenseKeys
setlocal enabledelayedexpansion
for /f "tokens=1,2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft" /reg:64 /s /v DigitalProductId  ^&^& reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft" /reg:64 /s /v DigitalProductId') do (
 set t=%%i
 set t=!t:~0,5!
 if .!t!. == .HKEY_. (echo.
  call :ProductInfo "%%i %%j %%k"))
goto :eof

:ProductInfo
    setlocal enabledelayedexpansion
    set FunctionName=%~0
 echo RegistryName=%~1
 for /f "tokens=1,2*" %%i in ('reg query "%~1" /v *Product*  /reg:64') do (
  if %%i==ProductName (echo ProductName: %%k)
  if %%i==ProductId (echo ProductId: %%k)
  if %%i==ProductID (echo ProductID: %%k)
  if /I %%i==DigitalProductId (call :ProductKey "%%k"
   echo ProductKey: !ProductKey!))
 goto :eof

:ProductKey
    setlocal enabledelayedexpansion
    set FunctionName=%~0
    set RegData=%~1
    set Validchars=BCDFGHJKMPQRTVWXY2346789
 if .%RegData:~0,2%. == .A4. set HexString=%RegData:~104,30%
 if .%RegData:~0,2%. == .F8. set HexString=%RegData:~1616,30%
 for /l %%i in (0,2,28) do (set /a j=%%i/2
  set /a StringArray[!j!]=0x!HexString:~%%i,2!)
 set /a "IsWin8=(StringArray[14] & 8)/8"
 set /a "StringArray[14]=StringArray[14] - !IsWin8! * 8"
    for /l %%i in (0,1,24) do (set value=0
        for /l %%j in (14,-1,0) do (set /a value=StringArray[%%j] + !value! * 256
            set /a StringArray[%%j]="( !value! / 24 ) & 255"
            set /a value%%=24
            set /a Win8Pos=!value!)
        for %%j in (!value!) do set key=!Validchars:~%%j,1!!key!)
 If %IsWin8% == 1 (set /A "Win8Pos1=24-Win8Pos"
  set Win8Pos1=-!Win8Pos1!
  call set t1=%%key:~1,!Win8Pos!%%
  call set t2=%%key:~!Win8Pos1!%%
  set key=!t1!N!t2!)
    endlocal & set %FunctionName:~1%=%key:~0,5%-%key:~5,5%-%key:~10,5%-%key:~15,5%-%key:~20,5%
 goto :eof

May we convince the admins to create such a subforum ?

App: Au3toCmd              UDF: _SingleScript()                             

Posted (edited)

Isn't PowerShell really meant to be replacing batch scripting?

Edited by guinness
Typo

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 7/13/2015 at 6:44 PM, guinness said:

Isn't PowerShell really meant to be replacing batch scripting?

Due to the default execution policy 'restriced', it is hard to execute PS-scrpts on other PCs.

But we might expand the powershell forum to also handle BAT and CMD ?

App: Au3toCmd              UDF: _SingleScript()                             

Posted

I would add there, as it's kind of related. I agree with @JohnOne that we don't need a sub forum for every language. I would like Java and PHP there, but am fine with C# too.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Administrators
Posted (edited)
  On 7/13/2015 at 7:30 PM, Exit said:

Due to the default execution policy 'restriced', it is hard to execute PS-scrpts on other PCs.

But we might expand the powershell forum to also handle BAT and CMD ?

If you run it like "powershell.exe -ExecutionPolicy Bypass -File myscript.ps1" then it works fine. 

The idea was to just have the new common sexy(!) IT admin focused languages explicitly listed. Everything else can go in the general dev forum unless it warrants its own forum.

Edited by Jon
  • 1 month later...
Posted

I like this idea.  And, bear in mind that bat and cmd is very close to origins of AutoIt.  GUIs are pretty and probably a whole issue all by themselves

Skysnake

Why is the snake in the sky?

Posted

But learners and newbies are usually using search. :)

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...