It was recently suggested to me that it would be better to use WScriptNetwork than Environ UserName
Is WScrript just for a network environment or is better or what?
User Identifier Approach
-
- Administrator
- Posts: 78465
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: User Identifier Approach
Using WScript, or the WNetGetUserA Winows API function, has the advantage that the user cannot alter it, unlike Environ("username").
So the former are more secure.
So the former are more secure.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: User Identifier Approach
Thanks, that's what I though but wanted to confirm.
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: User Identifier Approach
Just to be sure, I modified the code to use this. Is this correct?
CurrentDb.Execute "INSERT INTO tbllogintime (logintime) VALUES ('" & WScriptNetwork("username") & "')", dbFailOnError
CurrentDb.Execute "INSERT INTO tbllogintime (logintime) VALUES ('" & WScriptNetwork("username") & "')", dbFailOnError
-
- Administrator
- Posts: 78465
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: User Identifier Approach
No, it doesn't work like Environ. WScript is a VBA library, Network is an object in that library, and UserName is a method of that object. You have to create the WScript.NetWork object:
CurrentDb.Execute "INSERT INTO tbllogintime (logintime) VALUES ('" & CreateObject("WScript.Network").UserName & "')", dbFailOnError
CurrentDb.Execute "INSERT INTO tbllogintime (logintime) VALUES ('" & CreateObject("WScript.Network").UserName & "')", dbFailOnError
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 550
- Joined: 30 Jul 2014, 23:58
Re: User Identifier Approach
Ok, I understand now.
Thanks,
Thanks,