ILogic code to reference Windows login name

ILogic code to reference Windows login name

jmfowler1996
Advocate Advocate
2,320 Views
11 Replies
Message 1 of 12

ILogic code to reference Windows login name

jmfowler1996
Advocate
Advocate

Hi. 

 

I have been making some adjustments to our company drawing template. 

One thing which I have become fond of is the idea of having an iLogic form with many useful links to file locations et cetera.

I am currently making one of such shortcuts; this one for the user's scanner file.

The location of the file is as follows, using my name, Jonathan Fowler, as an example:

\\HDSDC02\Scanner\Jonathan.Fowler

 

I have come up with the following code:

 

MyName = ?

ScannerLocation = ("\\HDSDC02\Scanner\" & Left(MyName, InStrRev(MyName, " ")-1) & "." & Right(MyName, Len(MyName)-InStrRev(MyName, " ")))

ThisDoc.Launch(ScannerLocation)

It works, however, the MyName variable has no value. 

I need a way to set this variable to be my Windows login name (Jonathan Fowler).

I have tried

MyName = Environ("Username")

and 

MyName = ThisApplication.UserName

 , but both of these result in an abbreviated form of the user's name. In my case, it is jfowler.

 

 

If you know any way of referencing the Window's login name using iLogic, I would be very grateful if you could share it.

 

Many thanks,

[MyName]

Accepted solutions (2)
2,321 Views
11 Replies
Replies (11)
Message 2 of 12

mcgyvr
Consultant
Consultant

How about this?

Its not the Windows login name but rather the username from tools..application options..general tab

No idea if ilogic can pull the actual Windows username

 

SyntaxEditor Code Snippet

'get the user name from the Inventor Options
myName= ThisApplication.GeneralOptions.UserName

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 12

jmfowler1996
Advocate
Advocate

Thanks, but unfortunately, this returns a value of "jfowler" in my case, whereas I am looking for my full name, "Jonathan Fowler", so that I can use it in the file location.

0 Likes
Message 4 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi jmfowler1996,

 

Give this a try:

 

WSHnet = CreateObject("WScript.Network")
UserName = WSHnet.UserName
UserDomain = WSHnet.UserDomain
objUser = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
'get user name
UserFullName = objUser.FullName
'remove space and replace with dot
oDotUserName = Replace(UserFullName," ",".")

'return both variations
MessageBox.Show( "Full User Name: " & vbCrLf & UserFullName & vbCrLf & oDotUserName, "iLogic")

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 5 of 12

jmfowler1996
Advocate
Advocate

Thanks, Curtis.

 

That's much appreciated.

This worked perfectly for me and I am definately going to have a long look at this to understand how you got to that solution. 'Grats.

 

I'll check out that other forum too. 

Ta!

0 Likes
Message 6 of 12

mcgyvr
Consultant
Consultant

@jmfowler1996 wrote:

Thanks, Curtis.

 

That's much appreciated.

This worked perfectly for me and I am definately going to have a long look at this to understand how you got to that solution. 'Grats.

 

I'll check out that other forum too. 

Ta!


Its vb stuff it seems.. I learn so much from the code Curtis can write.. I would love to be able to do it like that just don't have the time to sit down and figure it all out..

But here..

https://msdn.microsoft.com/en-us/library/s6wt333f(v=vs.84).aspx

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 7 of 12

Curtis_Waguespack
Consultant
Consultant

mcgyvr wrote:

Its vb stuff it seems..


Hi jmfowler1996,

 

mcgyvr makes a good point. iLogic is a tool set that has it's own limited set of functions and calls, but you can mix in VBA and VB.NET code as well. I almost never write pure iLogic, and have probably confused a few people over the years by not making the distinction between ilogic, VBA and VB.NET.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 8 of 12

dusan.naus.trz
Advisor
Advisor

@Curtis_Waguespack 

Hi, If I have a PC at home, then your code does not work = it says ActiveX component cannot be created. Is it possible to make it work somehow? If I have my PC connected at work, then your code works.

0 Likes
Message 9 of 12

petHYD9W
Observer
Observer

Any answers?

0 Likes
Message 10 of 12

dusan.naus.trz
Advisor
Advisor

Hello. I didn't get an answer. I am not using the code above. I used a different code and it works for me.

'get the user name from the Inventor Options
myName = ThisApplication.GeneralOptions.UserName
Dim myNumber As String

myNumber = "myPCName"

0 Likes
Message 11 of 12

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@dusan.naus.trz @petHYD9W 

 

edit: oops, sorry I answered the wrong question

 

You might try this :

sComputerName = Environ$("computername")

MsgBox(sComputerName,,"iLogic")

 

Try this:

sUserName = Environ$("UserName")

MsgBox(sUserName,,"iLogic")

 

or this

 

sUserName = System.Windows.Forms.SystemInformation.UserName 

MsgBox(sUserName,,"iLogic")

EESignature

Message 12 of 12

Frederick_Law
Mentor
Mentor

@dusan.naus.trz wrote:

Hello. I didn't get an answer. I am not using the code above. I used a different code and it works for me.

'get the user name from the Inventor Options
myName = ThisApplication.GeneralOptions.UserName


 

It get User Name from Inventor.  Enter whatever you want here.

Username-01.jpg