Sign in to follow this  
Followers 0
ViciousXUSMC

Having issues with CMD Netsh

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



That would be my end goal, I was getting past the first issue before combining the pieces :)

It will returns this in my .txt file:

The following command was not found: mbn show interface.

Share this post


Link to post
Share on other sites

That seems to be the ticket, so can you help me wrap my head around the actual issue and why this solves it?

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0