BookmarkSubscribeRSS Feed
pniel

Community Trekker

Joined:

Jun 23, 2011

computer name

Hi jmpers,

I need to build an application in jmp for different users, meaning that different users will have different User Interface.. (it is the same application) I was wondering if is there a way to get user profile? Let say computer name, user name or server name from jmp ? Doing so I can decide which script to open

Tanks

pniel
1 ACCEPTED SOLUTION

Accepted Solutions
JohnPonte

Staff

Joined:

Jun 17, 2013

Solution

Re: computer name

Here is some JSL that I wrote for getting the username from the system. This worked in JMP 10, running on Windows 7.

dll = Load DLL( "mpr.dll" );

dll << DeclareFunction(

     "WNetGetUserA",

      Convention( STDCALL ),

      Alias ( "GetUserName" ),

      Arg( UInt8, "format", input ),

      Arg( AnsiString, "username", output ),

      Arg( UInt64, "length", update ),

      Returns( UInt32 )

);

username = "                                                  ";

unlen = length(username);

result = dll << GetUserName(0, username, unlen);

show(username);

dll << UnloadDLL();

First, you need to load the system DLL. I didn't have any luck with Advapi32.dll. But I found what I needed with mpr.dll. Notice I didn't need to specify a path to the DLL since it was on my system path.

dll = Load DLL("mpr.dll");

Next, you need to declare any method that you are going to call in the DLL. The method I want to use is actually called WNetGetUserA(), but by defining an alias, I can simply call it using GetUserName().

dll << DeclareFunction(

      "WNetGetUserA",

      Convention( STDCALL ),

      Alias ( "GetUserName" ),

      Arg( UInt8, "format", input ),

      Arg( AnsiString, "username", output ),

      Arg( UInt64, "length", update ),

      Returns( UInt32 )

);

Now I want to define the variables that I am going to pass in as arguments. I create a username and initialize it to blanks. Then I use the length() function in JMP to get the current length of the buffer I just created.

username = "                                                  " ;

unlen = length(username);

Now I can call the function. Notice the first argument is input only, so I just use a constant instead of defining a variable. Then the show() command shows my username after making the call.

result = dll << GetUserName(0, username, unlen);

show(username);

Finally, I am done so I clean up.

dll << UnloadDLL();

I hope this works for you. If you come up with a better way, please let us know.

By the way, using loadDLL only works on Windows. It isn't supported on the Mac. For that reason I do a check at the top of my script.

Names Default To Here( 1 );

If( Host is( Mac ),

     Print( "Sorry, this script is not supported on Mac." );

     Stop();

);

Enjoy,

JohnP

15 REPLIES
mattf

Community Trekker

Joined:

Jun 23, 2011

Re: computer name

Hi Pneil:

On Windose, from the start menu, run, cmd opens a DOS window. From the prompt type "set" for the list of active environmental variables.

Also - right-click on the My COmputer icon on the desktop - sleect Advanced tab environmental variables button near the bottom.

JMP 9 includes the handy function to retrieve any one of these from the environment:

cname = Get Environment Variable( "COMPUTERNAME" );

and one can branch accordingly base on the returned value from there.

Best regards,
-Matt
pniel

Community Trekker

Joined:

Jun 23, 2011

Re: computer name

hi,

i am using jmp 8 is there a similar function there that retrieve the computer nam

tanks
ENTHU

Contributor

Joined:

May 13, 2018

Re: computer name

I need to get the computer user name and store it in a column of a datatable.I am using following script - 

 

uname = Get Environment Variable( "COMPUTERNAME" );
dt:user = uname;

where dt is the data table and user is the name of the column.

But I get the following error -

"Cannot set value for the column 'user' because the row number (-1) is not valid."

Can someone pls tell me what is wrong here?

txnelson

Super User

Joined:

Jun 22, 2012

Re: computer name

You have to tell JMP which row in the data table for column User you want to save the value to.

uname = Get Environment Variable( "COMPUTERNAME" );
dt:user[1] = uname;

The above would save the value of "uname" to row 1 value for column "user"

Jim
ENTHU

Contributor

Joined:

May 13, 2018

Re: computer name

It works.But what if I have 10 rows and want to have uname ina ll rows?

Do I use a for loop?

txnelson

Super User

Joined:

Jun 22, 2012

Re: computer name

You can use a For() Loop, or you could do something like the below:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Consumer Preferences.jmp" );

uname = Get Environment Variable( "COMPUTERNAME" );

dt << New Column( "User", character, set each value( uname ) );
Jim
ENTHU

Contributor

Joined:

May 13, 2018

Re: computer name

Awesome! thanks
mattf

Community Trekker

Joined:

Jun 23, 2011

Re: computer name

Hi:

Assuming Windows XP and JMP 8 one can retrive Windoz variables via the LoadDLL command - (also with JMP 9 if one wants to retrieve all of the ENV variables).

Example below uses the "GetEnvironmentStrings" windows function to retrive all the global environmental variables (including COMPUTERNAME) and for fun loads then in a data table and an array.

see:
http://www.nesug.org/Proceedings/nesug10/ad/ad04.pdf


Best regards,
-Matt

pmroz

Super User

Joined:

Jun 23, 2011

Re: computer name

Can someone help me with the syntax for calling a DLL?  I want to get the user's username using the Windows API GetUserName function.  I don't want to look up the username environment variable because that can be spoofed.

Advapi32.dll

BOOL WINAPI GetUserName(

  _Out_    LPTSTR lpBuffer,

  _Inout_  LPDWORD lpnSize

);

Thanks!