Advertisement
Alive4ever

Hostednetwork Easy Setup for Windows 7 / Windows 8

Jun 29th, 2013
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. CLS
  3. TITLE Hostednetwork Easy Setup
  4. ECHO =============================
  5. ECHO ----------Welcome------------
  6. ECHO =============================
  7. ECHO This script will help you configuring hostednetwork easily.
  8. ECHO Especially made for those in need of wireless network sharing via laptops/PCs.
  9. ECHO -----------------------------------------
  10. ECHO Press any key when you are ready to go...
  11. pause > nul
  12. goto check_os_version
  13. :check_os_version
  14.     ver | find /n /i "6.2" > nul
  15.     if %errorlevel% equ 0 (
  16.         goto checkPrivileges
  17.     ) else (
  18.         goto recheck_os_version
  19.         )
  20. :recheck_os_version
  21.     ver | find /n /i "6.1" > nul
  22.     if %errorlevel% equ 0 (
  23.         goto checkPrivileges
  24.     ) else (
  25.         goto not_supported_os
  26.         )
  27.        
  28. :not_supported_os
  29.     cls
  30.     title "ERROR DETECTED! :("
  31.     echo ------------------------------------------------------------------
  32.     echo Sorry, your operating system is not supported to run hostednetwork.
  33.     echo Please upgrade to Windows 7 or Windows 8 to enable hostednetwork.
  34.     echo ------------------------------------------------------------------
  35.     echo Press any key to exit...
  36.     pause > nul
  37.     exit /B
  38.  
  39. :checkPrivileges
  40. NET FILE 1>NUL 2>NUL
  41. if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
  42.  
  43. :getPrivileges
  44. if '%1'=='ELEV' (shift & goto gotPrivileges)  
  45. ECHO.
  46. ECHO **************************************
  47. ECHO Invoking UAC for Privilege Escalation
  48. ECHO **************************************
  49.  
  50. setlocal DisableDelayedExpansion
  51. set "batchPath=%~0"
  52. setlocal EnableDelayedExpansion
  53. ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
  54. ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
  55. "%temp%\OEgetPrivileges.vbs"
  56. exit /B
  57.  
  58. :gotPrivileges
  59. ::::::::::::::::::::::::::::
  60. :START
  61. ::::::::::::::::::::::::::::
  62. setlocal & pushd .
  63.  
  64. REM Run shell as admin (example) - put here code as you like
  65. :runscript
  66.     cls
  67.     TITLE Hostednetwork Easy Setup
  68.     ECHO What do you want to do?
  69.     ECHO 1. Check hostednetwork support on your wireless adapter
  70.     ECHO 2. Setup hostednetwork name (SSID) and passphrase
  71.     ECHO 3. View hostednetwork SSID and passphrase
  72.     ECHO 4. Start hostednetwork
  73.     ECHO 5. Stop hostednetwork
  74.     ECHO 6. View hostednetwork status
  75.     ECHO 7. Exit this batch
  76.    
  77.     CHOICE /C:1234567 /M "Make your selection by typing the number of your choice."
  78.     IF %errorlevel% equ 7 GOTO exitbatch
  79.     IF %errorlevel% equ 6 GOTO connectionstat
  80.     IF %errorlevel% equ 5 GOTO stophostednetwork
  81.     IF %errorlevel% equ 4 GOTO starthostednetwork
  82.     IF %errorlevel% equ 3 GOTO viewsssidkey
  83.     IF %errorlevel% equ 2 GOTO setuphostednetwork
  84.     IF %errorlevel% equ 1 GOTO checkhostednetwork
  85.  
  86. :checkhostednetwork
  87.     cls
  88.     echo Detecting hostednetwork support on your wireless drivers.
  89.     echo Please wait...
  90.     echo ==========================================================
  91.     timeout 2 > nul
  92.     set search_string=Hosted network supported  : Yes
  93.     netsh wlan show drivers | find /i "%search_string%" > nul
  94.     if %errorlevel% == 0 (
  95.         title Hostednetwork supported
  96.         echo ---------------------------------------------------------
  97.         timeout 1 > nul
  98.         echo Congratulations, your wifi adapter supports hostednetwork.
  99.         echo You can create wireless infrastructure on it.
  100.         echo ---------------------------------------------------------
  101.         timeout 1 > nul
  102.         echo Press any key to return to main menu
  103.         pause > nul
  104.         cls
  105.         goto runscript
  106.         ) else (
  107.         title Hostednetwork not supported
  108.         echo ---------------------------------------------------------
  109.         timeout 1 > nul
  110.         echo Sorry, your wifi adapter doesn't support hostednetwork.
  111.         echo Upgrade your wifi driver with latest version available.
  112.         echo If your problem persists after upgrading,
  113.         echo contact your wifi manufacturer for support.
  114.         echo ---------------------------------------------------------
  115.         timeout 1 > nul
  116.         echo Press any key to return to main menu
  117.         pause > nul
  118.         cls
  119.         goto runscript
  120.         )
  121.  
  122. :setuphostednetwork
  123. goto setssid
  124.  
  125.     :setssid
  126.     cls
  127.     ECHO Configuring wireless SSID and passphrase
  128.     ECHO =========================================
  129.     timeout 1 > nul
  130.     set /p ssid=Type the name of your wireless SSID to create:
  131.     if defined ssid (
  132.         ECHO Your SSID is %ssid%
  133.         ECHO ===================
  134.         timeout 1 > nul
  135.         goto setkey
  136.     ) else (
  137.         ECHO Error. You must specify an SSID for your hostednetwork.
  138.         ECHO Press any key to retype SSID
  139.         pause > nul
  140.         goto setssid
  141.         )
  142.     :setkey
  143.     set /p key=Type the key to use on created network (8 characters or more):
  144.     if defined key (
  145.         ECHO Your passphrase key is %key%
  146.         ECHO ===============================
  147.         timeout 1 > nul
  148.         goto configwlan
  149.     ) else (
  150.         ECHO Error. You must specify a passphrase key for your hostednetwork.
  151.         ECHO Press any key to retype passphrase
  152.         pause > nul
  153.         goto setkey
  154.         )
  155.        
  156.     :configwlan
  157.     ECHO Please wait while configuring SSID and passphrase
  158.     ECHO ==================================================
  159.     timeout 2 > nul
  160.     netsh wlan set hostednetwork mode=allow key=%key% keyusage=persistent ssid=%ssid% > nul
  161.     if %errorlevel% equ 0 (
  162.         ECHO Your hostednetwork has been configured
  163.         ECHO Press any key to return
  164.     ) else (
  165.         ECHO Failure configuring hostednetwork
  166.         ECHO Press any key to return
  167.         )
  168.     pause > nul
  169.     cls
  170.     goto runscript
  171.  
  172. :viewsssidkey
  173.     cls
  174.     ECHO Please wait while gathering information...
  175.     ECHO ==========================================
  176.     timeout 2 > nul
  177.     if defined key (
  178.     ECHO Here is your hostednetwork details
  179.     ECHO ----------------------------------
  180.     ECHO Wireless Network Name : %ssid%
  181.     ECHO Password              : %key%
  182.     ECHO ----------------------------------
  183.     timeout 2 > nul
  184.     ECHO Press any key to return...
  185.     pause > nul
  186.     cls
  187.     goto runscript
  188.     ) else (
  189.         ECHO ---------------------------------------
  190.         ECHO You didn't specify SSID and passphrase.
  191.         ECHO ---------------------------------------
  192.         timeout 2 > nul
  193.         ECHO Press any key to return...
  194.         pause > nul
  195.         goto runscript
  196.     )  
  197.    
  198. :starthostednetwork
  199.     cls
  200.     ECHO Starting hostednetwork. Please be patient...
  201.     ECHO ============================================
  202.     timeout 2 > nul
  203.     goto checksupport
  204.    
  205.     :checksupport
  206.     set search_string=Hosted network supported  : Yes
  207.     netsh wlan show drivers | find /i "%search_string%" > nul
  208.     if %errorlevel% equ 0 (
  209.     goto checkavailability
  210.     ) else (
  211.         ECHO The hostednetwork can't start.
  212.         ECHO Make sure your wireless adapter supports hostednetwork.
  213.         ECHO If problem persists, contact your wifi adapter manufacturer for support.
  214.         ECHO Press any key to return...
  215.         pause > nul
  216.         cls
  217.         goto runscript
  218.     )
  219.    
  220.     :checkavailability
  221.     set absentstring=Not available
  222.     netsh wlan show hostednetwork | find "%absentstring%" > nul
  223.     if %errorlevel% equ 1 (
  224.     goto definedkey
  225.     ) else (
  226.     ECHO Hostednetwork is unavailable
  227.     ECHO -----------------------------------------------
  228.     ECHO Make sure that wireless adapter is switched on.
  229.     ECHO -----------------------------------------------
  230.     timeout 2 > nul
  231.     ECHO Press any key to return
  232.     pause > nul
  233.     goto runscript
  234.     )
  235.    
  236.     :definedkey
  237.         if defined key (
  238.             goto starting_up
  239.        
  240.         ) else (
  241.             ECHO You didn't specify SSID and passphrase.
  242.             ECHO Press any key to return to selection
  243.             pause > nul
  244.             cls
  245.             goto runscript
  246.         )
  247.    
  248.     :starting_up
  249.             ECHO Please wait while checking hostednetwork status...
  250.             =======================================================
  251.             timeout 2 > nul
  252.             set startedstatus=Not started
  253.             netsh wlan show hostednetwork | find "%startedstatus%" > nul
  254.             if %errorlevel% equ 0 (
  255.                 ECHO Starting up...
  256.                 ECHO --------------------------------------------
  257.                 timeout 1 > nul
  258.                 netsh wlan start hostednetwork > nul
  259.                 timeout 1 > nul
  260.                 ECHO The hostednetwork is started successfully
  261.                 ECHO --------------------------------------------
  262.                 ECHO Press any key to return...
  263.                 pause > nul
  264.                 cls
  265.                 goto runscript
  266.             ) else (
  267.                 timeout 1 > nul
  268.                 ECHO ------------------------------
  269.                 ECHO The hostednetwork is running.
  270.                 ECHO ------------------------------
  271.                 ECHO Press any key to return...
  272.                 pause > nul
  273.                 cls
  274.                 goto runscript
  275.             )
  276.  
  277. :stophostednetwork
  278.     cls
  279.     ECHO Stopping hostednetwork. Please wait...
  280.     ECHO ======================================
  281.     timeout 2 > nul
  282.     set startedstatus=Status                 : Started
  283.     netsh wlan show hostednetwork | find /i "%startedstatus%" > nul
  284.     if %errorlevel% equ 0 (
  285.         netsh wlan stop hostednetwork > nul
  286.         ECHO -----------------------------------------
  287.         timeout 1 > nul
  288.         ECHO The hostednetwork is stopped successfully
  289.         ECHO -----------------------------------------
  290.         timeout 1 > nul
  291.         ECHO Press any key to return...
  292.         pause > nul
  293.         cls
  294.         goto runscript
  295.     ) else (
  296.         ECHO -----------------------------------------
  297.         timeout 1 > nul
  298.         ECHO The hostednetwork is not running.
  299.         ECHO -----------------------------------------
  300.         timeout 1 > nul
  301.         ECHO Press any key to return...
  302.         pause > nul
  303.         cls
  304.         goto runscript
  305.     )
  306.  
  307. :connectionstat
  308.     cls
  309.     ECHO Please wait while gathering stats...
  310.     ECHO =====================================
  311.     timeout 1 > nul
  312.     netsh wlan show hostednetwork
  313.     timeout 1 > nul
  314.     ECHO =====================================
  315.     ECHO Press any key to return...
  316.     pause > nul
  317.     goto runscript
  318.    
  319.    
  320. :exitbatch
  321.     cls
  322.     echo Are you sure?
  323.     timeout 1 > nul
  324.     echo -----------------------------------
  325.     echo Press Y to exit, otherwise press N.
  326.     timeout 1 > nul
  327.     echo -----------------------------------
  328.     choice /c YN
  329.     if %errorlevel% equ 2 (
  330.         cls
  331.         goto runscript
  332.         )
  333.     if %errorlevel% equ 1 exit /B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement