stan0ne Posted January 17, 2020 Share Posted January 17, 2020 (edited) Hello there, I came to the end of a project but I encountered a small problem. How will I solve this problem? ................. ................. Func Reboot() Local $sCommand $sCommand = "cmd /K @echo off & title Reboot & net start DOT3SVC & for /f "tokens=1* delims=: " %%a in ('netsh lan show interfaces') do if %%a == Name set activeAdapter=%%b & netsh interface set interface name="%activeAdapter%" newname="LAN" & net user administrator /active:yes & net user administrator password & net user bislem /delete & shutdown /r /t 5 /c " & '"Bilgisayar yeniden basliyor.."' RunWait($sCommand, "", @SW_MINIMIZE) EndFunc ;==>Reboot error: syntax error error: syntax error error: delims(): undefined function. problem after adding the following code: for /f "tokens=1* delims=: " %%a in ('netsh lan show interfaces') do if %%a == Name set activeAdapter=%%b & netsh interface set interface name="%activeAdapter%" newname="LAN" Edited January 17, 2020 by stan0ne Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2020 Share Posted January 17, 2020 Just wrap your double quotes in single quotes and single quotes in double quotes for example (untested but should give you an idea): $sCommand = @ComSpec & ' /K @echo off & title Reboot & net start DOT3SVC & for /f "tokens=1* delims=: " %%a in (' & "'netsh lan show interfaces'" & ') do if %%a == Name set activeAdapter=%%b & netsh interface set interface name="%activeAdapter%" newname="LAN" & net user administrator /active:yes & net user administrator password & net user bislem /delete & shutdown /r /t 5 /c "Bilgisayar yeniden basliyor.."' Link to comment Share on other sites More sharing options...
stan0ne Posted January 17, 2020 Author Share Posted January 17, 2020 thank you for your answer but it doesn't work Link to comment Share on other sites More sharing options...
stan0ne Posted January 17, 2020 Author Share Posted January 17, 2020 1 hour ago, Subz said: Just wrap your double quotes in single quotes and single quotes in double quotes for example (untested but should give you an idea): $sCommand = @ComSpec & ' /K @echo off & title Reboot & net start DOT3SVC & for /f "tokens=1* delims=: " %%a in (' & "'netsh lan show interfaces'" & ') do if %%a == Name set activeAdapter=%%b & netsh interface set interface name="%activeAdapter%" newname="LAN" & net user administrator /active:yes & net user administrator password & net user bislem /delete & shutdown /r /t 5 /c "Bilgisayar yeniden basliyor.."' thank you for your answer but it doesn't work Link to comment Share on other sites More sharing options...
Nine Posted January 17, 2020 Share Posted January 17, 2020 Why not creating a batch file and simply runt it ? Anyway, if you insist on creating a string like that, use this approach : $sCommand = @ComSpec & ' /K @echo off & ' & _ 'title Reboot & ' & _ 'net start DOT3SVC & ' & _ 'for /f "tokens=1* delims=: " %%a in ( & ' & _ '"netsh lan show interfaces" & ' & _ ') do if %%a == Name set activeAdapter=%%b & ' & _ 'netsh interface set interface name="%activeAdapter%" newname="LAN" & ' & _ 'net user administrator /active:yes & ' & _ 'net user administrator password & ' & _ 'net user bislem /delete & ' & _ 'shutdown /r /t 5 /c "Bilgisayar yeniden basliyor.."' MsgBox (0,"",$sCommand) It increases readability, and reduces the chances of making an error. Just so you know, my DOS is way too far to make sure I use the right syntax. Do not post back telling me it is not working, it is just an example of how you should do it...You are the expert in DOS not me “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted January 17, 2020 Share Posted January 17, 2020 You need to remember that single line commands will treat variables different to batch so %% would become %. Recommend you test the command line manually to check for errors here is a working example: #RequireAdmin Reboot() Func Reboot() ;~ Line below is for testing and doesn't include shutdown command Local $sCommand = @ComSpec & ' /k @Echo Off & Title Reboot & Net Start DOT3SVC & For /f "tokens=1* delims=: " %a In (' & "'Netsh lan show interfaces'" & ') Do (If %a EQU Name Netsh interface set interface name="%b" newname="LAN" & Net user administrator /active:yes & Net user administrator password & Net user bislem /delete)' ;~ Line below is for manually testing the command line InputBox("Command Line for Testing", "Copy and Paste input into Cmd", StringReplace($sCommand, @ComSpec & ' /k @Echo Off & ', ""), "", 800, 130) If @error Then Exit ;~ Line below includes the shutdown command, uncomment to use ;~ Local $sCommand = @ComSpec & ' /k @Echo Off & Title Reboot & Net Start DOT3SVC & For /f "tokens=1* delims=: " %a In (' & "'Netsh lan show interfaces'" & ') Do (If %a EQU Name Netsh interface set interface name="%b" newname="LAN" & Net user administrator /active:yes & Net user administrator password & Net user bislem /delete) & shutdown /r /t 5 /c "Bilgisayar yeniden basliyor.."' RunWait($sCommand, "", @SW_MINIMIZE) EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now