#212297 - 2017-02-16 10:01 PM
NetSH issue
|
sliver16
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
|
|
|
|
#212299 - 2017-02-17 01:58 AM
Re: NetSH issue
[Re: Glenn Barnas]
|
sliver16
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
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Note: once an instructor, always... 
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!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 601 anonymous users online.
|
|
|