[Batch] The Official Batch File Repository - Learn & ask questions about batch files

Discussion in 'Scripting' started by timesurfer, Oct 11, 2010.

  1. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    497
    909
    10
    #101 DARKOR04, Jan 30, 2011
    Last edited by a moderator: Apr 20, 2017
    I'm trying to slim down woat script and this is the results so far

    Original OEM Activation

    Code:
    :OEMACT
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [W7 OEM ACTIVATION]
    cls
    title WOAT v3.2 OEM/KMS ACTIVATOR
    MODE CON COLS=76 LINES=22
    echo. =======================================
    echo. OEM ACTIVATION.
    echo. =======================================
    echo.
    for /f "tokens=2 delims==" %%A in ('"wmic bios get version /format:list"') do set VAR=%%A & goto:OEMINS
    )
    
    :OEMINS
    echo.
    cscript /b \windows\system32\slmgr.vbs -ilc "%~dp0Certificates\%VAR%"
    echo. OEMID SET AND CERT INSTALLATION: [SUCCESS]
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OEMID SET AND CERT INSTALLED]
    goto:OSDETECT
    ) ELSE (
    goto:INSTALLCERTIFICATE
    )
    
    :OSDETECT
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION START]
    echo.
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 7 Ultimate" >nul
    IF NOT ERRORLEVEL 1 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION SUCCESS] & echo. OS DETECTION: [SUCCESS] & goto:ULTIMATEOEM
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 7 Professional" >nul
    IF NOT ERRORLEVEL 1 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION SUCCESS] & echo. OS DETECTION: [SUCCESS] & goto:PROFESSIONALOEM
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 7 Home Premium" >nul
    IF NOT ERRORLEVEL 1 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION SUCCESS] & echo. OS DETECTION: [SUCCESS] & goto:HOMEPREMIUMOEM
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 7 Home Basic" >nul
    IF NOT ERRORLEVEL 1 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION SUCCESS] & echo. OS DETECTION: [SUCCESS] & goto:HOMEBASICOEM
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName | find /i "Windows 7 Starter" >nul
    IF NOT ERRORLEVEL 1 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION SUCCESS] & echo. OS DETECTION: [SUCCESS] & goto:STARTEROEM 
    ELSE 1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS DETECTION FAIL] & GOTO:FAILURE
    )
    
    :ULTIMATEOEM
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS ULTIMATE OEM]
    echo.
    set keytype=OEM
    echo. KEY INSTALLATION: [IN PROGRESS..]
    set os=WINDOWS 7 ULTIMATE OEM
    set keyw=49PB6-6BJ6Y-KHGCQ-7DDY6-TF7CD
    cscript /b \windows\system32\slmgr.vbs -ipk %keyw% >nul && goto:DONE
    goto:NOTDONE
    )
    
    :PROFESSIONALOEM
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS PROFESSIONAL OEM]
    echo.
    set keytype=OEM
    echo. KEY INSTALLATION: [IN PROGRESS..]
    set os=WINDOWS 7 PROFESSIONAL OEM
    set keyw=74T2M-DKDBC-788W3-H689G-6P6GT
    cscript /b \windows\system32\slmgr.vbs -ipk %keyw% >nul && goto:DONE
    goto:NOTDONE
    )
    
    :HOMEPREMIUMOEM
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS HOME PREMIUM OEM]
    echo.
    set keytype=OEM
    echo. KEY INSTALLATION: [IN PROGRESS..]
    set os=WINDOWS 7 HOME PREMIUM OEM
    set keyw=6RBBT-F8VPQ-QCPVQ-KHRB8-RMV82
    cscript /b \windows\system32\slmgr.vbs -ipk %keyw% >nul && goto:DONE
    goto:NOTDONE
    )
    
    
    :HOMEBASICOEM
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS HOME BASIC OEM]
    echo.
    set keytype=OEM
    echo. KEY INSTALLATION: [IN PROGRESS..]
    set os=WINDOWS 7 HOME BASIC OEM
    set keyw=DX8R9-BVCGB-PPKRR-8J7T4-TJHTH
    cscript /b \windows\system32\slmgr.vbs -ipk %keyw% >nul && goto:DONE
    goto:NOTDONE
    )
    
    :STARTEROEM
    1>>%userprofile%\Desktop\WOATv3.2LOG.log echo.[%date% %time%] [OS STARTER OEM]
    echo.
    set keytype=OEM
    echo. KEY INSTALLATION: [IN PROGRESS..]
    set os=WINDOWS 7 STARTER OEM
    set keyw=36Q3Y-BBT84-MGJ3H-FT7VD-FG72J
    cscript /b \windows\system32\slmgr.vbs -ipk %keyw% >nul && goto:DONE
    goto:NOTDONE
    )
    I slimed it down to this:

    Code:
    :oemact
    set acttype=OEM
    1>>%userprofile%\Desktop\WOATv3.3LOG.log echo.[%date% %time%] [OEM Activation Started]
    cls
    title WOAT v3.3 OEM/KMS Activator
    mode con cols=76 lines=22
    echo. ----------------------------------------------------------
    echo. OEM Acitvation Started.
    echo. ----------------------------------------------------------
    echo.
    for /f "tokens=2 delims==" %%A in ('"wmic bios get version /format:list"') do set VAR=%%A
    cscript /b \windows\system32\slmgr.vbs -ilc "%~dp0Certificates\%VAR%"
    echo. OEMID Set and Cert Installation: [Success]
    1>>%userprofile%\Desktop\WOATv3.3LOG.log echo.[%date% %time%] [OEMID Set and Cert Installed]
    FOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID"') DO SET os=%%A
    1>>%userprofile%\Desktop\WOATv3.3LOG.log echo.[%date% %time%] [OS Edition: %os%]
    echo. OS Edition: %os%
    echo. Product Key Installation: [In Progress]
    if %os% equ Ultiate set wkey=49PB6-6BJ6Y-KHGCQ-7DDY6-TF7CD
    if %os% equ Professional set wkey=74T2M-DKDBC-788W3-H689G-6P6GT
    if %os% equ HomePremium set wkey=6RBBT-F8VPQ-QCPVQ-KHRB8-RMV82
    if %os% equ HomeBasic set wkey=DX8R9-BVCGB-PPKRR-8J7T4-TJHTH
    if %os% equ Starter set wkey=36Q3Y-BBT84-MGJ3H-FT7VD-FG72J
    cscript /b \windows\system32\slmgr.vbs -ipk %wkey% >nul
    if errorlevel 1 goto:Error
    goto:success
    wow! a huge change don't you think? lol, if there any way possible to simplify more? Please let me know thanks
     
  2. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    Hi all,

    Does anyone help me to have a script .BAT or .CMD to restore the tokens.dat file and product key in Windows Vista instead of replace this file in Safemode please ?

    Path:

    C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing\tokens.dat

    Thanks in advance
     
  3. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,480
    1,500
    150
    SLIC Dumpt toolkit? Or the batch above?
     
  4. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    Hello tcntad,

    I need batch please.

    Thanks for your concern

     
  5. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    That batch has an argument, so you can't run it with just a double-click and expect it to work.

    And because it is intended to run from a CMD window, there's no need for a "pause" command.
     
  6. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    #106 Calistoga, Feb 7, 2011
    Last edited by a moderator: Apr 20, 2017
    You script accepts only "5" as an argument and the diamond is hard-coded. I believe that the original intention of the challenge was a batch script that would dynamically generate a diamond based on an argument.

    diamond.bat 5 should return
    Code:
           0 
          0 1 
         0 1 2 
        0 1 2 3 
       0 1 2 3 4 
      0 1 2 3 4 5 
      0 1 2 3 4 5 
       0 1 2 3 4 
        0 1 2 3 
         0 1 2 
          0 1 
           0
    While diamont.bat 3 should return
    Code:
           0 
          0 1 
         0 1 2 
        0 1 2 3 
        0 1 2 3 
         0 1 2 
          0 1 
           0
    diamond.bat 2
    Code:
           0 
          0 1 
         0 1 2 
         0 1 2 
          0 1 
           0
    etc.
     
  7. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    #107 rEApEAt, Feb 7, 2011
    Last edited by a moderator: Apr 20, 2017
    No comments.
     
  8. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    @rEApEAt

    You know what "eg." means?
    It means for example - which implies that it should be able to generate for other numbers as well.
     
  9. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    This is becoming surreal - and, at least for me, a bit comic. Yes, I know what "eg." means. I even know how to analyse a very simple problem like this one.

    "Write a batch file that takes one argument to display a diamond in numbers". The batch file must display a diamond in numbers taking one - and only one - argument. Nothing here disallows the use of a hard-coded diamond.

    "The single argument should be number." The argument must be necessarily 1, 2, 3, 4, 5, 6, 7, 8 or 9.

    "Eg. diamond.bat 5 will give the following output". According to the precedent proposition, it's indifferent to use "diamond 1", "diamond 2", "diamond 3", "diamond 4", "diamond 5", "diamond 6", "diamond 7", "diamond 8" or "diamond 9". Hence, it may be - for example - "diamond 5".

    In your first post, you have said that my solution is not working; but it works. In the second post, you have said that the "original intention" of the challenge is different, which implies that I'm not able to interpretate a problem, or that MasterDisaster could not know how to properly formulate a problem. In the third post, you're suggesting I'm not able to understand plain english. I hope the fuss will end here.
     
  10. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    #110 Calistoga, Feb 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Surreal I agree, and indeed quite comic. Why would MasterDisaster give such a ridiculously simple "challenge"? There is no challenge in hard-coding a diamond in a batch script. See the logic?

    This is what your script does:
    Code:
    echo       0 
    echo      0 1 
    echo     0 1 2 
    echo    0 1 2 3 
    echo   0 1 2 3 4 
    echo  0 1 2 3 4 5 
    echo  0 1 2 3 4 5 
    echo   0 1 2 3 4 
    echo    0 1 2 3 
    echo     0 1 2 
    echo      0 1 
    echo       0
    Your script is just as simple as any "Hello world" script and is no challenge to write at all - but by all means, if you think it is an acceptable solution - that's fine.
     
  11. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    #111 rEApEAt, Feb 8, 2011
    Last edited by a moderator: Apr 20, 2017
    At least we agree in one thing: this is becoming more and more funny.

    Yes, it is an acceptable solution because the challenge was simply to code a simple argument option within a batch file. Replace the diamond with a "Hello World" if you wish, and the challenge will remain just the same! It seems you cannot understand, or accept, the purpose of this thread. It seems you haven't even read its first post.

    You seem to be decided to deny and depreciate the value of my tiny, simple, humble contribution to this thread. Why? This is the only real question in all this purposeless debate.

    Solve your own challenge without hard-coding the diamonds and you'll be much more useful for everybody who is hanging here to learn and share knowledge. Of course you would not propose a challenge that you cannot solve by yourself.
     
  12. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    You seem very angry.

    It's obvious that I'm not the only one that thinks this challenge requires more than just a few echoes, see this for example. There's a reason I haven't provided an example, and that is because it is a complex task and would require some time (yes, I'm saying it is difficult - a challenge).

    I read this as "the number should be used (to) in the generation of the diamond". There is no need for you to agree with me, as I am merely stating my interpretation.

    You seem to suggest that I have something against you personally, which I obviously don't.

    Your script is a nice example on how to use arguments, but it is in my opinion not a solution to the challenge. Agree with me or disagree.

    If you want to continue discussing this, then please reply.
     
  13. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    365
    3,230
    10
    There is no reason to argue with each other both of you are right in that both ways to make the program are good. It doesn't matter how complicated the code is it is still a good script. rEApEAt's code did what the example asked for but like calistoga stated the script could be expanded to use other numbers which is more of a challenge.
     
  14. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    #114 rEApEAt, Feb 8, 2011
    Last edited: Feb 8, 2011
    An angry person is - by definition - unable to be polite.

    I do not - and I think that anyone would - agree with your interpretation of the challenge, which is pretty tortuous (the interpretation, not the challenge). Of course, you're entitled to it. On the other hand, you can hardly call what I have said as an "interpretation", because it relies strictly on what was written.

    In a word, the diamond itself was just what Hitchcock used to call a "MacGuffin". And perhaps no one - not even experienced members - understood the challenge precisely because it was so [censored] simple. It was indeed a challenge for beginners. With a shiny MacGuffin in it to distract the attention. Very well done, I would say.

    The challenge is in the post #4. Take a look at the previous post (#3) and perhaps you'll realize that you are "looking for a horn in a horse's head" (this is a popular saying in my country).

    Cheers and let's turn this page.
     
  15. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    My thoughts exactly.
     
  16. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Ok you guys instead of engaging this dialog which is solving nothing I have project that I need help on. Pm me both if you want to help. I cannot post cause it contains code to create solution for Adobe CS5 unless admins might entertain this .cmd file that will include all three solutions I did this year hence an AIO TS solution with IR4, IORRT and CS5T

    Let me know and let's put our energy into more constructive expression. Maybe you could even collaborate with each other hence take both your awesome scripting talents and merge them in doing something for everybody

    Appreciation for all coders here ;)

    TS
     
  17. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    Oh TS, we were just getting warmed up :starwars:

    Know that I respect your opinions rEApEAt and I may have been wrong :)
     
  18. thethingy

    thethingy MDL Senior Member

    Sep 7, 2010
    301
    41
    10
    windows text editor is quite rudimentary for making batch files, is there any good free text editors that lets you keep track of lines and columns as you are working your way down the batch?

    and is there a way to hide the minimise/maximise buttons on the cmd window?
     
  19. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,222
    22,280
    210
    #119 Alphawaves, Feb 23, 2011
    Last edited: Feb 23, 2011
    I like Notepad ++ ;)
     
  20. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Does anyone know the script in .cmd file to check if ran as admin and to give error if not ran as admin?

    Thanks