+ Reply to Thread
Results 1 to 8 of 8
  1. Senior Member tstrip007's Avatar
    Join Date
    May 2013
    Posts
    296

    Certifications
    VCP5-DCV
    #1

    Default Any Goog Batch Scripters In here?

    Im trying to put together a simple batch script that creates an entry in the registry. I would like the script to check to see if it exists, if it doesnt, it adds it and if it does exists the command closes. This is what Ive got but it doesnt work, is adds the reg, but when i test it again it asks me if I wont to add it again. Any help would be appreciated.

    if exist "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servi ces\PolicyAgent\AssumeUDPEncapsulationContextOnSen dRule" goto End
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servi ces\PolicyAgent" /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d 2

    :End
    cls
    exit
    Reply With Quote Quote  

  2. SS
  3. Senior Member tstrip007's Avatar
    Join Date
    May 2013
    Posts
    296

    Certifications
    VCP5-DCV
    #2
    Thats Good* not goog, lol
    Reply With Quote Quote  

  4. Senior Member tstrip007's Avatar
    Join Date
    May 2013
    Posts
    296

    Certifications
    VCP5-DCV
    #3
    ugh looks like i can add a /f at the end to force overwrite but if there's a better way. I'm all ears.
    Reply With Quote Quote  

  5. Senior Member wd40's Avatar
    Join Date
    May 2007
    Location
    Bahrain
    Posts
    934

    Certifications
    CISA, eJPT, CompTIA x 6, MCP, MCTS
    #4
    I don't think if exist works like this in a batch file.

    I am not an expert but I "googled it"

    Take a look at reg query

    https://docs.microsoft.com/en-us/pre...42028(v=ws.11)

    https://docs.microsoft.com/en-us/pre...643(v%3dws.11)
    Reply With Quote Quote  

  6. Senior Member
    Join Date
    Jan 2015
    Location
    Chicago, IL
    Posts
    1,071

    Certifications
    Too many MCPs and MCTS, MCSA: Security, MCSE: Security, MCSA: 2003, 2008, 2012, MCITP: EA, CISSP-ISSAP, SCS DLP, GREM
    #5
    :: by gespenstern @ TE 2018 for tstrip007

    :: first we establish if there's an entry.
    :: the next command will set %errorlevel% variable to 0 if
    :: successful (i.e. the entry exists) or 1 (or anything
    :: besides 0) if unsuccessful (we assume no entry)

    reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule

    :: checking errorlevel variable if the query has failed
    :: and if so create an entry

    if %errorlevel% EQU 0 goto end else (
    reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d 1
    )

    :end
    Reply With Quote Quote  

  7. Self-Described Huguenot blargoe's Avatar
    Join Date
    Nov 2005
    Location
    NC
    Posts
    4,130

    Certifications
    VCAP5-DCA; VCP 3/4/5/6 (DCV); MCSA 2016/2012/2K3/2K; MCSE:S 2K3/2K; MCSE:M 2K3/2K; MCTS:Exch2K7; EMCSA:CLARiiON; Linux+; Security+; A+
    #6
    Why not Powershell?


    $path = "HKLM:SYSTEM\CurrentControlSet\Services\PolicyAgen t\AssumeUDPEncapsulationContextOnSendRule"
    $name = "AssumeUDPEncapsulationContextOnSendRule"
    $value = 1

    if (test-path $path -ne $true) {
    new-item -path $path -name $name
    set-itemproperty -path $path -name $name -value $value -propertytype dword
    }
    IT guy since 12/00

    Recent: 1/29/2018 - Passed 70-743 - MCSA 2016 Complete; 1/13/2018 - Passed 70-411 - MCSA 2012 complete
    Working on: Being a better coder, build/test/deploy automation fundamentals
    Future: Renew VCP (due 2/2019), possibly with an adjacent VCP or VCAP
    Reply With Quote Quote  

  8. California Kid JoJoCal19's Avatar
    Join Date
    Mar 2009
    Location
    Jacksonville, FL
    Posts
    2,541

    Certifications
    CISSP, CISM, CISA, CRISC, GCIA, GSEC, AWS CCP, CEHv8, CHFIv8, ITIL-F, MSISA, BSBA
    #7
    I second what blargoe said, why not look into Powershell? I had been trying to do some batch scripting about two years back and it seemed like I found a bunch more resources in Powershell for doing the same thing I was trying to learn. I ended up creating a mostly working PS script instead. If I remember correctly, you can even tie in old cmd script commands into PS. Also, it seems PS commands end up being more simple and easier to learn and remember.
    Have: CISSP, CISM, CISA, CRISC, GCIA, GSEC, AWS CCP, CEHv8, CHFIv8, ITIL-F, BSBA - UF, MSISA - WGU
    Currently Working On: MS Cybersecurity, AWS Certified Security - Specialty, Learning Linux & Python
    Next Up:​ AWS Certified Solutions Architect - Associate
    Reading:​ A Cloud Guru, Code Academy
    Reply With Quote Quote  

  9. Senior Member
    Join Date
    Jan 2015
    Location
    Chicago, IL
    Posts
    1,071

    Certifications
    Too many MCPs and MCTS, MCSA: Security, MCSE: Security, MCSA: 2003, 2008, 2012, MCITP: EA, CISSP-ISSAP, SCS DLP, GREM
    #8
    Just to give some ideas, why sometimes it's not PS.

    1. There could be Windows 2003 servers or XP/Vista workstations without WMF installed (no PS).
    2. PS could be disabled enterprise-wide for security reasons (had some clients with that).
    3. WinRM could be disabled/not configured which makes using PS remotely a problem, while RPC is open almost everywhere, so tools like psexec, paexec, smbexec, winexe work fine (and they have issues with PS).
    4. From offensive perspective, modern PS became VERY visible and transparent.
    Reply With Quote Quote  

+ Reply to Thread

Social Networking & Bookmarks