none
Script won't work RRS feed

  • Question

  • my script will run, but won't change anything. Any help would be appreciated. Thanks! 

    Here's my script:

    @ECHO OFF

    :Main
    cls
    ECHO Choose something to run
    ECHO -----------------------
    ECHO.
    ECHO Disable Guest Account
    ECHO. 
    ECHO Enable the FireWall
    ECHO.
    ECHO Enable Updates
    ECHO.
    ECHO Change Password Length
    ECHO.

    set /p "option=Enter something to run: "
    if %option%== Disable Guest Account goto :Guestacc
    if %option%== Enable the FireWall goto :firewall
    if %option%== Enable Updates goto :updates 
    if %option%== Change Password Length goto :Password
    goto :Main

    :Guestacc
    cls
    net user guest /active:no

    PAUSE

    :firewall
    cls
    netsh adcfirewall set allprofiles state on

    PAUSE

    :updates
    cls
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOption /t REG_DWORD /d 4 /f

    PAUSE

    :Password
    cls
    net accounts /minpwlen:8

    PAUSE


    • Edited by Logodapolo Friday, November 22, 2019 5:46 PM
    Friday, November 22, 2019 5:45 PM

Answers

  • Just to make you keen about Powershell ... there are easier ways but that would be a proper way to create a text menu with the given options. 

    $title      = "Actions Menu`n"
    $message    = "Choose something to run.`n"
    $Guest      = New-Object System.Management.Automation.Host.ChoiceDescription "Disable &Guest Account", "This option disables the Guest Account"
    $Firewall   = New-Object System.Management.Automation.Host.ChoiceDescription "Enable the &Firewall", "This option enables the Firewall"
    $Updates    = New-Object System.Management.Automation.Host.ChoiceDescription "Enable &Updates", "This option enables Windows Update Service"
    $Password   = New-Object System.Management.Automation.Host.ChoiceDescription "Change &Password Length", "This option changes the minimum password length to 8"
    $Cancel     = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel", "Cancel the Actions Menu ..."
    
    $options = [System.Management.Automation.Host.ChoiceDescription[]]($Guest, $Firewall, $Updates, $Password, $Cancel)
    $result = $host.ui.PromptForChoice($title, $message, $options, 4) 
    
    switch ($result) {
        0 { "`n`tYou choose 'Disable Guest Account'.`n"; net user guest /active:no ; break }
        1 { "`n`tYou choose 'Enable the Firewall'.`n"; netsh adcfirewall set allprofiles state on ; break }
        2 { "`n`tYou choose 'Enable Updates'.`n"; reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOption /t REG_DWORD /d 4 /f ; break }
        3 { "`n`tYou choose 'Change Password Length'.`n"; net accounts /minpwlen:8 ; break }
        4 { "`n`tYou choose 'Cancel ... '.`n"; break }
    }

    With this code there is actually no chance for the user to make something wrong. Only the given options will be treated as valid inputs.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, November 22, 2019 10:45 PM

All replies

  • First of all - please format your code as code ... How to Use the Code Feature in a TechNet Forum Post.

    Then: You should use Powershell instead of cmd. It's way more advanced and easier to learn, easier to write and easier to debug.

    Next: Do you really want to force the user of this "script" to enter a phrase like "Disable Guest Account" to get a task done? Wouldn't be much easier to ask for an index number you place before or after the actual description? That would be less errror prone and easier to type. ;-)


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, November 22, 2019 10:34 PM
  • Just to make you keen about Powershell ... there are easier ways but that would be a proper way to create a text menu with the given options. 

    $title      = "Actions Menu`n"
    $message    = "Choose something to run.`n"
    $Guest      = New-Object System.Management.Automation.Host.ChoiceDescription "Disable &Guest Account", "This option disables the Guest Account"
    $Firewall   = New-Object System.Management.Automation.Host.ChoiceDescription "Enable the &Firewall", "This option enables the Firewall"
    $Updates    = New-Object System.Management.Automation.Host.ChoiceDescription "Enable &Updates", "This option enables Windows Update Service"
    $Password   = New-Object System.Management.Automation.Host.ChoiceDescription "Change &Password Length", "This option changes the minimum password length to 8"
    $Cancel     = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel", "Cancel the Actions Menu ..."
    
    $options = [System.Management.Automation.Host.ChoiceDescription[]]($Guest, $Firewall, $Updates, $Password, $Cancel)
    $result = $host.ui.PromptForChoice($title, $message, $options, 4) 
    
    switch ($result) {
        0 { "`n`tYou choose 'Disable Guest Account'.`n"; net user guest /active:no ; break }
        1 { "`n`tYou choose 'Enable the Firewall'.`n"; netsh adcfirewall set allprofiles state on ; break }
        2 { "`n`tYou choose 'Enable Updates'.`n"; reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOption /t REG_DWORD /d 4 /f ; break }
        3 { "`n`tYou choose 'Change Password Length'.`n"; net accounts /minpwlen:8 ; break }
        4 { "`n`tYou choose 'Cancel ... '.`n"; break }
    }

    With this code there is actually no chance for the user to make something wrong. Only the given options will be treated as valid inputs.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, November 22, 2019 10:45 PM
  • Thank you very much! Is there a way to keep it running until the user cancels it? Do you know of any website that has all the commands on it for these?
    • Edited by Logodapolo Tuesday, November 26, 2019 2:57 PM
    Tuesday, November 26, 2019 2:55 PM
  • Thank you very much! Is there a way to keep it running until the user cancels it?
    What do you mean with "Keep it running"? The user has to make a choice from the given options or cancel it. There's no other way out except of killing the script itself.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Tuesday, November 26, 2019 3:01 PM
    Tuesday, November 26, 2019 3:00 PM
  • What I mean is that when the script runs after the user has chosen what to do it close the script, I want to know if there is a way for it to present the options over and over until the User chooses to cancel it.
    Tuesday, November 26, 2019 3:20 PM
  • Of course there is a way. But why would you like to do that? It does not make any sense to present a choice and if the user choose one option to present the same choice again.

    If you like to do it anyway you should read the help for about_do and about_while. Please always read the complete help including the examples to learn how to use it.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, November 26, 2019 7:08 PM