ENVIRON absolute- logging terminal IP in RTC

ugxfms
Member Posts: 7
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
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
0
Comments
-
ENVIRON is not supported by RTC. You have to find another way to track workstation IP.0
-
BTW, apparently your code will always return terminal server ip. I cant see any reference to local machine.0
-
You just don't want to run the code for RTC?
If yes then use
IF ISSERVICETIER then
exit;0 -
Rashed,
I was a way of achieving this through RTC0 -
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.0 -
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 server0 -
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<0 -
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.0 -
Change ENVIRON('windir') to 'C:\windows\' temporary to make it work on RTC.0
-
most of windows are installed in c:\windows, but not all
Better not to teach people to hardcode anything
0 -
Thanks ppavuk I didn't know that. How stupid of me.0
-
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions