Jump to content

Having issues with CMD Netsh


Go to solution Solved by jguinch,

Recommended Posts

I am trying to collect the IMEI number off 52 devices as I set them up.

I found the CMD: netsh mbn show interface

This works perfect but I want a way to log/copy this information so I created a .bat file.

 

netsh mbn show interface > %userprofile%\desktop\rename.txt
This works but I wanted to wrap it in autoit so I can have the file be the computer name.

I tried running the .bat file from autoit and tried @ComSpec and none of that works I keep getting an error

"mbn show interface is not a recognized command" or something of that nature.

I assume this has something to do with the start in location, or possibly because netsh has its own sub command shell so its taking the netsh command but then not passing the rest of the command properly. Not sure what it is but could use a bit of expert help for those who have already seen this and figured it out.

Regards,

Edit: one of my earlier attempts

Run(@ComSpec & " /k netsh mbn show interface > %userprofile%\desktop\rename.txt")

While 1
    If FileExists(@DesktopDir & "\" & @ComputerName & ".txt") Then Exit
    Sleep(200)
FileMove(@DesktopDir & "\rename.txt", @DesktopDir & "\" & @ComputerName & ".txt", 1)
WEnd
Edited by ViciousXUSMC
Link to comment
Share on other sites

With a x64 OS, there are some redirected folder and registry keys when you use a x64 program.

With a x86 program (like an au3 script running in x86 mode), @SystemDir or @ComSpec (ore else) are redirected to the SysWOW64 environement (c:windowssyswow64), even if you refer to c:windowssystem32.

In you case, the netsh.exe running is the x86 one (located in c:windowssyswow64, witch seems to have differents options than the netsh.exe located in c:windowssystem32.

You can refer to the x64 System32 directory by refering to c:WindowsSysnative.

An second way could be to disable the folder redirection by calling the WinAPI Wow64DisableWow64FsRedirection function.

An third way could be to compile your script in x64 mode.

DllCall('kernel32.dll', 'bool', 'Wow64DisableWow64FsRedirection', 'ptr*', 0)
Run ( @ComSpec & " /k netsh mbn show interface")

For more explaination about the folder redirection, you can read this MSDN article : https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187%28v=vs.85%29.aspx

In fact,

Sorry if it's not clear...

Link to comment
Share on other sites

No it is clear as I knew about the redirection, I have run across it before with other things (and the HKLM64 issue with registry as well) I just did not realize that is what was happening here, I had no idea netsh had two different executables.

Thanks for the explanation and the appropriate fixes.

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...