Question

So here goes.. I have grown weary of setting up wireless network profiles on computers and instead would like to just import these settings via the command line. After some research, I decided that I would export my already created profiles in netsh and then create a batch file to run the commands to create the profiles for the user. Then I thought I would wrap it all up as an exe for ease of access for others. What I have is this for a bat file:

@echo off
netsh wlan add profile filename="Wi-Fi-linksys3.xml"
netsh wlan add profile filename="Wi-Fi-linksys2.xml"
netsh wlan add profile filename="Wi-Fi-linksys1.xml"

This fails to import the xml files that are in the same folder. It does not call to the correct folder path to import the files, instead it reports:

"The system cannot find the file supported"

Or if I try something like:

@echo off
netsh wlan add profile filename="%TEMP%\Wi-Fi-linksys3.xml"
netsh wlan add profile filename="%TEMP%\Wi-Fi-linksys2.xml"
netsh wlan add profile filename="%TEMP%\Wi-Fi-linksys1.xml"

It does the same thing.

I think that for some reason netsh is not calling to the correct location. If I put something like "c:[filename]" it will import just fine, but I cannot get something like that to work once it is wrapped up in the exe.

Any suggestions would be amazing. I am even open to trying a different method, just has to be able to run out of box on Windows machines.

Was it helpful?

Solution 2

Assuming you are using iexpress.exe to bundle your bat and xml files, the exe should extract them to a temporary location (somewhere in %appdata%, local temp most likely), but since you probably wont know what the actual path is, try using %~dp0 in place of the path and that should work.

@echo off
netsh wlan add profile %~dp0Wi-Fi-linksys1.xml
netsh wlan add profile %~dp0Wi-Fi-linksys2.xml
netsh wlan add profile %~dp0Wi-Fi-linksys3.xml

When going through the iexpress process, make sure to check the box to keep the long file names or save the xml files with shorter names like conf1.xml and etc (and reflect the changes in your bat).

update here's where I pulled the %dp0 from if you want to know a little more: https://serverfault.com/a/255294/144813

OTHER TIPS

This is working here:

netsh wlan add profile Wi-Fi-linksys3.xml
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top