-1

I'm trying to run a VBScript with wscript using the elevated user and not showing any window.

So I have the following myscript.vbs file and to run it, in cmd.exe, I call wscript myscript.vbs


Set Shell = CreateObject("Shell.Application")

Shell.ShellExecute "cmd.exe", "/c netsh interface ip set address name=Ethernet static 192.168.1.5 255.255.255.0 0.0.0.0 && echo helloworld > file.txt", , "runas", 0

The script is then going to run multiple commands on cmd.exe (but asking for elevation just once), as showing above. That actually works.

However it fails if the network interface name have a space, Ethernet 1 instead of Ethernet.

How can I deal with this?

This is my first ever VBScript, please forgive me if I'm doing something unusual.

user692942
  • 15,667
  • 7
  • 74
  • 164
KcFnMi
  • 4,665
  • 8
  • 52
  • 106
  • any reason for the use of VBScript over PowerShell? – jack_skellington May 31 '22 at 10:15
  • 3
    There must be used `name=""Ethernet 1""`. See also [About using Double quotes in Vbscript](https://stackoverflow.com/questions/15770599/about-using-double-quotes-in-vbscript). You should run in a command prompt window `cmd /?` and read very carefully the description how the Windows Command Processor interprets the argument string(s) after option `/C` or `/K`. I recommend to replace also `netsh` by `%SystemRoot%\System32\netsh.exe` (fully qualified file name) to work independent on the environment variables `PATH` and `PATHEXT`. I recommend to use also CMD option `/D` before `/c`. – Mofi May 31 '22 at 10:39
  • @jack_skellington I'm wondering how it would look like in PowerShell. Can I call it using `wscript` not showing any window? – KcFnMi May 31 '22 at 16:05

0 Answers0