Page 1 of 1 1
Topic Options
#212297 - 2017-02-16 10:01 PM NetSH issue
sliver16 Offline
Fresh Scripter

Registered: 2007-12-10
Posts: 10
Hello...I am trying to run a very simple netsh command to stop a trace via .kix The command we are looking to run is as follows:

netsh.exe trace stop

for some reason...no matter what the syntax is I get the same error message over and over.

'The following command was not found: trace stop.'

Here is the latest syntax I tried:

Shell "cmd.exe /c netsh.exe trace stop"

I run things via shell all the time and have never come across this issue...if I do it in a .bat file everything works fine?

Any ideas?

Top
#212298 - 2017-02-17 12:19 AM Re: NetSH issue [Re: sliver16]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Kix is a 32-bit app. When you run something in a command prompt on an x64 platform, you're running a 64-bit command. Try this to invoke the 32-bit version of the command:
 Code:
$Cmd = '%COMSPEC% /c %WINDIR%\SysWOW64\netsh.exe trace stop'
'Running: ' $Cmd @CRLF
Shell $Cmd
@SERROR @CRLF
Always use environment vars to specify CMD (COMSPEC) and C:\Windows (WINDIR) so it adjusts to the local system configuration.

Some utilities just won't run from the 32-bit shell, but usually have 32-bit versions in the alternate folder location. When weird stuff like this happens, check the folder and adjust the path of what you're calling. Without a full path, it will default to the 64-bit version.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#212299 - 2017-02-17 01:58 AM Re: NetSH issue [Re: Glenn Barnas]
sliver16 Offline
Fresh Scripter

Registered: 2007-12-10
Posts: 10
Thanks for the response Glenn. I did some additional testing with the different versions and it looks like the version of NetSH in syswow64 (the 64 bit version) doesn't even have the trace command available. If I launch the 32 bit version of netsh from c:\windows\system32\netsh.exe everything is there. Oddly enough I tried the following and it still failed with the same error.

Code:
$Cmd = "c:\windows\system32\cmd.exe /c c:\windows\system32\netsh.exe trace stop"
'Running: ' $Cmd @CRLF
Shell $Cmd
@SERROR @CRLF
sleep 10

Very very weird.....

Note: Understand your point around env. variables...I always use them first but am spelling it out here so everyone can see the paths.

Top
#212300 - 2017-02-17 03:06 AM Re: NetSH issue [Re: sliver16]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Note: once an instructor, always... \:D

May seem weird, but sadly it isn't. I just went through several dozen Kix scripts in my monitoring environment with this issue - it's frustrating enough to have to find the problem and search for the 32-bit utility, but even more so when you find that it isn't 100% compatible with the 64-bit version.

Only alternate solution I can offer is a workaround that will run the 64 bit version, but it will be asynchronous to Kix and unable to directly return any results.. It's a method I use to run tasks with elevated rights. There's really no way to run a 64-bit command directly from a 32-bit shell.

The tcLib UDF Library contains a collection of UDFs that make it easy to use the Windows Task Scheduler. A scheduled event consists of a task (what to run and who to run as) and zero or more triggers (when to run). A task with no trigger might seem pointless, but once you define the command and run as credentials in the Task part, you can run it immediately via the API.

Since the scheduled task runs in its own context, it runs the 64-bit version, which should work for you. You'll need to query the task result, which actually has two values - the Task Start result and Task Run result - you'll need to insure that the task started, and then check the run result. The package is pretty well documented.

This might seem complicated, but the tcLib allows you to define and execute the task with just 4 UDF calls - tcInit(), tcSetEvent(), tcExecute(), and tcGetEvent(). The tcGetEvent returns the status as well as the event configuration. tcDelEvent() will delete the event after you collect the results. If you don't need to check the result, you can enable the DWD (Delete When Done) flag.

The latest version is on the web site in my sig. Go to the Resources page and you'll find my production Kix UDF library.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#212301 - 2017-02-17 04:28 AM Re: NetSH issue [Re: sliver16]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Just want to correct something you said... syswow64 contains the 32bit apps and system32 contains the 64bit apps on a 64bit Version of Windows... Stupid I know, but you will have to ask MS why they chose to do this.
Top
#212302 - 2017-02-17 01:01 PM Re: NetSH issue [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Allen,
I don't see what you're referring to re: "syswow64 having" - If it wasn't clear or correct, I'll update it.

As for the name, it's the system folder for wow64 - Windows running on Windows64. "Windows" implies x86. From a software engineering perspective, the name makes sense, but so would creating System64 for x64 components. That probably would have broken too much legacy crap.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#212303 - 2017-02-17 03:36 PM Re: NetSH issue [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
it was re: silver. In his comments he's got it backwards about the folders.
Top
#212304 - 2017-02-17 08:27 PM Re: NetSH issue [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
OK - gotcha!
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.062 seconds in which 0.029 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org