PROCEDURE IsConfigurationMode@50010() : Boolean; VAR LowercaseCommandLine@50000 : Text; BEGIN LowercaseCommandLine := LOWERCASE(GetCurrentCommandLine()); EXIT((STRPOS(LowercaseCommandLine, '-configure') <> 0) OR (STRPOS(LowercaseCommandLine, '/configure') <> 0)); END; LOCAL PROCEDURE GetCurrentCommandLine@50020() : Text; VAR FileMgt@50000 : Codeunit 419; NavClientProcess@50001 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Diagnostics.Process" RUNONCLIENT; ManagementObjectSearcher@50002 : DotNet "'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Management.ManagementObjectSearcher" RUNONCLIENT; ManagementObjectCollection@50003 : DotNet "'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Management.ManagementObjectCollection" RUNONCLIENT; ManagementObject@50004 : DotNet "'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Management.ManagementObject" RUNONCLIENT; Enumerator@50005 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.IDictionaryEnumerator" RUNONCLIENT; CommandLine@50006 : Text; BEGIN IF (NOT GUIALLOWED) OR (NOT FileMgt.IsWindowsClient()) THEN BEGIN EXIT(''); END; NavClientProcess := NavClientProcess.GetCurrentProcess(); ManagementObjectSearcher := ManagementObjectSearcher.ManagementObjectSearcher( STRSUBSTNO('SELECT CommandLine FROM Win32_Process WHERE ProcessId = %1', NavClientProcess.Id)); ManagementObjectCollection := ManagementObjectSearcher.Get(); Enumerator := ManagementObjectCollection.GetEnumerator(); WHILE Enumerator.MoveNext() DO BEGIN ManagementObject := Enumerator.Current; CommandLine += STRSUBSTNO(' %1', ManagementObject.Item('CommandLine')); END; EXIT(CommandLine); END;This is what we use to identify configuration mode in Windows Client to modify the System Indicator. HTH.
Answers
Carsten
==> How To Ask Questions The Smart Way
This post is my own opinion and does not necessarily reflect the opinion or view of my employer.
Thanks, this works great. I would never have figured this out myself.
Remco van de Ven
Env : DotNet : System.Environment.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
cmdArgs : DotNet : System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
cmdArgs := Env.GetCommandLineArgs;
IF LOWERCASE(FORMAT(cmdArgs.GetValue(1))) = '-configure' THEN
MESSAGE('Config Mode')
ELSE
MESSAGE('User Mode');
Franz Kalchmair, MVP
Alias: Jonathan Archer
please like / agree / verify my answer, if it was helpful for you. thx.
Blog: http://moxie4nav.wordpress.com/
Is there an advantage of using the ManagementObjectSearcher over the comparably simple System.Environment.GetCommandLineArgs?
I would go for the shorter Version. But keep into Account that configure is Not neccesarily the First Parameter...
Carsten
==> How To Ask Questions The Smart Way
This post is my own opinion and does not necessarily reflect the opinion or view of my employer.