Jump to content

Quotation Mark in Quotation Mark


stan0ne
 Share

Recommended Posts

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 by stan0ne
Link to comment
Share on other sites

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

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

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 :)

Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...