ENVIRON absolute- logging terminal IP in RTC

ugxfmsugxfms Member Posts: 7
edited 2012-11-28 in NAV Three Tier
I wanted to track any changes in NAV done by a user using the login ID and terminal IP at the time of changes.

When i open RTC, i get an error that ENVIRON is absolute thus RTC never opens as the error keeps popping up.
Below is the code used in CU1


IF ISCLEAR(WindowShell) THEN BEGIN
CREATE(WindowShell);
WindowShell.CurrentDirectory(ENVIRON('windir') + '\system32\');
txtCommand := 'ipconfig';
WSHExec := WindowShell.Exec(txtCommand);
WSHTextStream := WSHExec.StdOut;

i := 0;
WHILE (NOT WSHTextStream.AtEndOfStream) AND (i < 8) DO BEGIN
txtMsg := WSHTextStream.ReadLine();
i += 1;
END;
IF GUIALLOWED THEN
UserSetup."User ID" := USERID;
UserSetup."IP Address" := COPYSTR(txtMsg,45);
recRef.GETTABLE(UserSetup);
UserSetup."IP Address" := '';
xrecref.GETTABLE(UserSetup);
ChangeLogMgt.LogModification(recRef,xrecref);

END;
Globals

Name Subtype DataType Length
WindowShell 'Windows Script Host Object Model'.WshShell Automation
WSHExec 'Windows Script Host Object Model'.WshExec Automation
WSHTextStream 'Windows Script Host Object Model'.TextStream Automation

Is there any other way of achieving the same but ensuring RTC is not affected

Comments

  • ppavukppavuk Member Posts: 334
    ENVIRON is not supported by RTC. You have to find another way to track workstation IP.
  • ppavukppavuk Member Posts: 334
    BTW, apparently your code will always return terminal server ip. I cant see any reference to local machine.
  • ara3nara3n Member Posts: 9,256
    You just don't want to run the code for RTC?

    If yes then use
    IF ISSERVICETIER then
    exit;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ugxfmsugxfms Member Posts: 7
    Rashed,

    I was a way of achieving this through RTC
  • ppavukppavuk Member Posts: 334
    ppavuk wrote:
    BTW, apparently your code will always return terminal server ip. I cant see any reference to local machine.


    em, you mean "terminal" is local machine, I just misunderstood you. Anyway, just use Windows Script Host Object Model to get local machine IP. I think you don't need to specify path for ipconfig, as WSH.run should be able to run ipconfig from any path.
  • SogSog Member Posts: 1,023
    oh and because wsh is a automation. Make sure you load this on the client. (cfr automations in RTC)
    Else you will receive the ip from the server
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • ugxfmsugxfms Member Posts: 7
    ppavuk wrote:
    ppavuk wrote:
    BTW, apparently your code will always return terminal server ip. I cant see any reference to local machine.


    em, you mean "terminal" is local machine, I just misunderstood you. Anyway, just use Windows Script Host Object Model to get local machine IP. I think you don't need to specify path for ipconfig, as WSH.run should be able to run ipconfig from any path.

    I used that in the variables as above.
    Could you suggest a modification on my code to point me in the correct path.. [-o<
  • ugxfmsugxfms Member Posts: 7
    Sog wrote:
    oh and because wsh is a automation. Make sure you load this on the client. (cfr automations in RTC)
    Else you will receive the ip from the server

    Perhaps if you help me with how the code would look like? [-o<
    A modification of mine above.... :-k
  • SogSog Member Posts: 1,023
    ugxfms wrote:
    Sog wrote:
    oh and because wsh is a automation. Make sure you load this on the client. (cfr automations in RTC)
    Else you will receive the ip from the server

    Perhaps if you help me with how the code would look like? [-o<
    A modification of mine above.... :-k

    replace CREATE(WindowShell); with CREATE(WindowShell,False,True);
    And if you went into the help and look at the description of create, you can figure out why false is false and true is true.

    Next is the environ "problem".
    Ask yourself if shell really needs to run under the systemdir to succesfully run ipconfig.cmd.

    Disclaimer: if we tell you how to write that code we can't be sure you GET the code you've written. And codemonkeys are frowned upon.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • ara3nara3n Member Posts: 9,256
    Change ENVIRON('windir') to 'C:\windows\' temporary to make it work on RTC.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ppavukppavuk Member Posts: 334
    most of windows are installed in c:\windows, but not all :) Better not to teach people to hardcode anything :)
  • ara3nara3n Member Posts: 9,256
    Thanks ppavuk I didn't know that. How stupid of me.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ppavukppavuk Member Posts: 334
    No worries, mate. I just mean that you maybe removed hardcoding after testing, but most people - don't. So for me this is a rule - don't tell to nubs to hardcode anything.
Sign In or Register to comment.