Jump to content

How to use a string variable inside of a cmd script?


mportal
 Share

Recommended Posts

I am new to autoit, this is my first programming language. As a starter i want to create a script with an inputbox asking the user what the preferred SSID of a network that your trying to connect to; declairing the input as a variable to be used in a cmd script. But cant figure out how to call the variable within the cmd script. So far i have compiled this with no success. I also checked the help file with examples inclding the return values, which have me confused. This is what i have so far.

$answer = InputBox ( "Start Program", "This process will restart your Wireless Network Connection and start Program. Please Enter the SSID of the Wireless Network", "Type SSID Here", "", _ - 1, -1, 0, 0 )
If $answer == 1 Then
Run ('C:\WINDOWS\System32\cmd.exe' & " /c " & 'netsh wlan disconnect interface="Wireless Network Connection"', "", @SW_HIDE)
Sleep ( 2000 )
Run ('C:\Program Files (x86)\program.exe')
Sleep ( 10000 )
Run ('C:\WINDOWS\System32\cmd.exe' & " /c " & 'netsh wlan connect name='$answer' ssid='$answer' interface="Wireless Network Connection"', "", @SW_HIDE)
ElseIf $answer == 2 Then
ProcessClose("program.exe")EndIf

How should i go about the first "if" statement?I want the string of what the user put into the inputbox to run inside my cmd "netsh wlan connect" script.Also if i were to exicute the script without '$answer' inside my cmd script. The program's windows will be in the top left hand side of the screen. I wanted to get it centered. But Any help is appriciated!

Edited by wakrein
Link to comment
Share on other sites

!= isn't valid AutoIt syntax.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

InputBox returns a string, so change your if to:

If $answer Then
or try to follow thru the Helpfile example again. Take a look at these Tutorials in the Wiki too. Welcome to the Forum.

But what im trying to do is get the $answer and use the user input text within my "netsh wlan connect" cmd script.

But thanks i will check out the tutorials

Edited by wakrein
Link to comment
Share on other sites

It was somdcomputerguy who posted previously, but removed the post.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

InputBox returns a string, so change your if to:

If $answer Then
or try to follow thru the Helpfile example again. Take a look at these Tutorials in the Wiki too. Welcome to the Forum.

I Figured it out :sorcerer: Check it out:

$answer = InputBox ( "Starting Program", "This process will disconnect your wireless network connection and prompt you to enter your connection name.", "", " M" )
If @Error == 0 Then
Run ('C:\WINDOWS\System32\cmd.exe' & " /c " & 'netsh wlan disconnect interface="Wireless Network Connection"', "", @SW_HIDE)
Sleep ( 2000 )
Run ('C:\Program Files (x86)\Program\program.exe')
Sleep ( 10000 )
Run ( @ComSpec & " /c " & "netsh wlan connect " & $answer )
ElseIf @Error == 1 Then
ProcessClose("Program.exe")
EndIf
Link to comment
Share on other sites

Here the WLAN_Restart.cmd script solution:

@echo off & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
echo:&echo:Restart WLAN&echo:&echo:Select SSID to connect or "C" to cancel&echo:&set C=C
for /F "usebackq tokens=1,2* delims=:" %%i in (`netsh wlan show networks`) do (set /A L=!L!+1 & if "!L!" == "2" (set I=%%j)
set t=%%i&if "!t:~0,4!" == "SSID" (set /A N=!N!+1&set C=!C!!N!
set SSID!N!=%%j&echo:%%i = %%j))
echo:&Choice /C %C% /N > NUL 2>&1
if .%Errorlevel%.==.1. (echo:WLAN NOT changed.&goto:eof)
set /A X=%Errorlevel%-1
set SSID=!SSID%X%:~1!&echo:SSID=!SSID!&echo:
netsh wlan connect name="%SSID%" ssid="%SSID%" I="%I:~1,-1%"

Even the CMD language is powerful :thumbsup:

Edited by Exit

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...