Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to identify if the user is on a netwroked computer or the standalone being used as a server 2

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
GB
Hi

I posted sometime back about creating folders for documents which works perfectly (thanks to those who contributed) on a standalone computer.

The purpose of the created folders is to store PDF's relating to job sheets, purchase orders etc that are automatically generated by the system.

The working command to create the folder is:

Code:
IF NOT DIRECTORY(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
  "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))

   MKDIR(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
     "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
ENDIF

So this works as mentioned.

However, I now have two computers side by side that are networked via Ethernet cable with a view to using one as the server and the other as a networked computer.

Having installed the runtime files on both computer, the program runs efficiently on both but I have traced back where an error occurs on the networked computer where every time the coding asks to create folder or check if the folder exists the above coding throws up the error "Invalid path or file name". As there is no file (It's creating a folder) it must be the path.

The folder created ends up with a name as an example: 9-2023 Order Name Order Title

I am aware of SYS(0) but by adding that in front of the above e.g. IF NOT DIRECTORY(SYS(0)+"\"+SYS(2003)+"\"+.... it still throws up an error of "Invalid path or file name" on the networked computer.

As I know the code above works on a standalone with no errors, my question is, how do I differentiate the path name if someone is using the local machine as apposed to the networked computer or is there one command that covers both?

Any guidance would appreciated.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Hi Steve,

I maintain a "File Cabinet" for my application that creates folders and stores files associated with jobs. The location for it, as well as my databases and tables, are stored in a registry key in the CURRENT_USER hive. When any of my apps are started, these locations are loaded into my application object and are then referenced whenever I need to "find" or "create" files/folder. If the registry entries don't exists when the app starts, I will prompt the users for the initial setup on the machine. I also have a utility to allow the location to change should I need to move anything (which I haven't had to in many years). As part of the Init, the application checks to see the data is accessible. If not (maybe it has moved, the network is down), it will notify the user that the data can't be accessed and allow them to find it or send an email to support for help.

My base class form has a routine that is executed in DataEnvironment.BeforeOpenTables to update the location of the Database objects with the data location.

I should mentioned that any routines that need to access the data or File Cabinet will use locations held in the application object

I have all my data on a server, with users accessing from networked machines and remote desktop sessions. The only time there is an issue is when the network is acting up.

Using this method, I do not worry about local/network, just if the data/file locations are accessible.

Hope this helps and makes sense
msc
 
Steve,

Looking at the Help for MKDIR, I see this:

If cPath is a directory without a drive designator, the directory is created as a subdirectory of the current Microsoft Visual FoxPro default directory.

This is clearly not what you want.

So, can you put a drive letter in front of the directory path?

Also, I can't see how SYS(0) would help. It returns the user name and the machine ID, but not in a format that will enable the system to identify the server.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
vaxman9, thank you. I’m not really sure what you mean in your post as I’m still relatively new to VFP.

Mike: You mentioned about putting a drive letter but if I put a “C”+”\”+ etc in front, surely that would tell the network computer to look on its own C drive.

I also take your point about SYS(0)

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
I'm not sure what you really want to know.

Because in the first place, if a second computer has a network connection, that alone doesn't make it a LAN (local area network). And the reason for that is not at all related to VFP, it's how Windows works, how profiles works, how a Windows Server OS is different from a Windows XP,Vista,8,10,11 or whatever other Desktop OS. As long as you don't have an actual Windows Server that has the role of a so called primary dommain controller that manages and maintains domain profiles that allow users to log into multiple computer with their profile, the single computers have different local users that are not the same, even if you name them the same. So that's the perspective of Windows user accounts.

The aspect I think you want to find out is how to address the same files from both computers. The short answer is: You have to know as long as yo dont have a domain as a common ground all you have is a network connection and you can define shares and give them share names and address them by the UNC path norm with \\computername\sharename. As long as the share is configured to allow external access. And that's done on the computer that defines the share.

You don't have all options when using desktop Windows versions, but you can define shares with such OSes, too. And then it boils down to knowing them. I agree with Mike knowing SYS(0) will only help you knowing the account name and the local (own) computer name. But obviously, it won't also give you names of all other computers you are connected to. Imagine how long SYS(0) would need to be in a commpany with 1000 employes having a workstation, if that would contain all computernames directly or indirectly connected. So looking into Sys(0) to learn about other computers is a bad idea, it only tells you about yourself.

So knnowing a computer name is just like knowing an internet address or like knowing a phone number. Are there "directories" for that? Well, of course, there are, too, but you don't always want all of all computers to be visible from anywhere else, so at first there is nothing shared, if you don't start to. It also gets into network OS and administration to learn more about this and I'm sure you don't want the deep dive.

So at first just know that you can name your computer in computer system properties:
check-PC-specs-on-windows-11-PC-properties_v5wdnm.jpg


And the simplest way to transfer that knowledge about that name to other computers is you yourself.

And after that's settled you can start as simple as using Windows Explorer to create network shares on the computer that you want to be accessed from other computers. Not on other computers. So you start at the source, which should actually be obvious, otherwise Windows would be unsecured and allow to force access from other computers. It has to start at the origin.

What even a desktop OS allows as option of any folder of any drive of a computer is giving access to other users with this option:
create_a_share_mhm7az.jpg


And then pick specific people:
network_share_xbq0r4.jpg


Well, and at this point I myself realize this is all stuff I'm never confronted with myself, as my developer life starts within a LAN and so the network adminsitration stuff is already done. In a private situation with just two or perpahs three connected computers you usually don't establish a LAN, you establish a workgroup. I've done this in the era of Windows 3.11 one time and again on 95, but it's now not even clear to me if that concept is still available as the smallest type of local network of computers.

You certainly do yourself a favor establishing that with the help of a Windows related forum.

If you're at that stage, there will be a pool of user names and counts that are known within the network and are the base of giving permissions to them. To not need to allow all single users there are user groups you can define and assign users so the share is done with a group and every user belonging to it. Anyway, there's no way to climb this mountain by taking a helicopter to the top, first establish different computer names, let them join to a network aka LAN or at least a workgroupd, then establish network users and usergroups and then you finally arrive at being able to share files.

Chriss
 
Hi Chris,

Using a Terminal Server in a domain makes things even more complicated, it’s one or more (virtual) servers(s) with perhaps hundreds of users and various user rights.

Network systems have lots of challenges.

Regards, Gerrit
 
Gerrit that's true.

In the end, if I just take the question as in the title, the best thing you can do is ask the user.
If the question is about setting up an application with local data for one user vs installing for a company this even becomes a differentiation you do with the setups yourself.

I already talked about creating a server setup and client setup several times and those setup types are also just two types. You can also design an application to be both, i.e. to have it's data locally only and then shared for all users of a computer or just for one user.

And, Steve, what Gerrit also points out is that in case you install a software on a terminal server, you do it like installing it for a client, because later client users will remotely connect and use the server in their sessions as a client. So even if you would determine a computer is a server, it doesn't mean you know or can be sure what's needed is a server installation. In the end it's a question to administrative users, who should do the setup.[pre][/pre]

Chriss
 
Steve W,

FWIW I did this in a totally diffferent way back in the LAN days. It would require code changes and may not be practical in your situation. Anyway...

The administrator logged in like everyone else (about 15 users) with her special password giving her the only access to a dbf containing the ID, login date, time, etc. of each user. You could add the machine's id and would know which machine is the "server".

Just an idea.

Steve
 
Thank you for all the replies.

A bit confused at the moment but I do have access to the code so I'll look into it.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Steve said:
I do have access to the code
Steve
What code are you talking about? The code in your first post?
That creates a directory if it's not found. So after executing it you always find this directory and it won't help you see whether you're the server or a client.

I think I don't really understand what exactly you need to figure out.

Chriss
 
Chris

If you read my post, you would see what I was talking about.

To summarise:
[ul]
[li]I have an application of which I have the source code[/li]
[li]We have used the application for a long time, no errors and all working fine[/li]
[li]Part of the code in the .prg called addnewjob.prg has the following:[/li]
[/ul]

Code:
IF NOT DIRECTORY(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
  "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))

   MKDIR(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
     "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
ENDIF

[ul]
[li]The folder containing the code is called JOBSYSTEM[/li]
[li]Therefore SYS(2003) is \JOBSYSTEM (It's on the C Drive of our standalone)[/li]
[li]I have shared the folder JOBSYSTEM which can now been seen on another computer linked to our standalone[/li]
[li]I installed the relevant runtime files on the computer linked to the standalone[/li]
[li]I created a desktop shortcut to the .exe file on the linked computer[/li]
[li]When you run the program on both the standalone and linked computer, it works perfect[/li]
[li]However, when you get to the point where the linked computer is asking to create a folder, that's when the error occurs.[/li]
[/ul]

The standalone name of my computer is DESKTOP-XXXXXXX (I've removed the actual name obviously)

A friend of mine who had a simliar problem suggested the following (This is her coding):

Code:
IF SYS(2003)="\JOBSYSTEM"  &&  This means I'm using the standalone
  IF NOT DIRECTORY(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
    "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))

     MKDIR(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
       "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
  ENDIF
ELSE  &&  Check for network
  IF NOT DIRECTORY("\\[b]DESKTOP-XXXXXXX[/b]\"+SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
    "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))

     MKDIR("\\[b]DESKTOP-XXXXXXX[/b]\"+SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
       "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
  ENDIF
ENDIF

I am going to try this out later and post back.

I hope the above makes sense and please keep in mind, I am relatively new to this with just a few years experience and for my own use unlike some experts on here who have many years.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
The only problem I have understanding this is if it worked all the time on any computer, how could it have stopped working now?

I mean SYS(2003) is the current directory, no matter if you're on a standalone or a networked computer. Other parts of the path are just data turned into strings.

And the IF statement you now have also only tells you whether your current directory is "\JOBSYSTEM" or not. That's not how you find out where you are. That can also get wrong if you are just on another current directory.

Chriss
 
I would put it that way:

GETENV("COMPUTERNAME") will give you just the computername. That's either the DESKTOP-XXXXXXX or another name, say DESKTOP-YYYYYYY.

But what is the server is something you have to know, it's not an information that's in the name, especially since DESKTOP-whatever is a usual name vendors configure for computers. I do understand you use one of the desktops as a server and you don't use a Windows Server version on it.

If you make code dependent on specific names, this is not transferrable to a general situation. In the end it always boils down to knowing whether your software runs on the server computer or "as" the server or as a client is configuration data.

I mean you can fall into the trap of programming a lot of code that has this specific name DESKTOP-XXXXXXX, but once that computer would be replaced because it gets defect you don't want to modify all that code.

What you are only able to use on the server is a local path like C:\mydata\, on any other computer you'll then need \\DESKTOP-XXXXXXX\something\myddata.

But it doesn't matter, if you simply store that into configuration data. Do you have configuration data? If not then this is the best way to start with it. It would be a dbf or even just a txt file side b side with the EXE or at some local place it's installed like C:\Users\Public\yourapp\config.txt and that's what you read in at start and use.

Besides that, a network share can also be mapped to a drive letter. And you could do that mapping in such a way that on the "server" Desktop computer the data is in D:\mydata\ and on all other computers D: is a mapped drive letter that points to the servers D: drive so that again also D:\mydata will be the data directory. Then it won't matter whether D:\ is a local drive or a mapped network share.

Chriss
 
Chriss

I was able to resolve my issue with the following which is now working without errors:

Code:
USE URNTABLE SHARED  &&  This dbf stores URN's and the network path
STORE SPACE(40) TO mserverpath
STORE SERVERPATH TO mserverpath
USE

* Server path looks like: \\DESKTOP-XXXXXXXX\JOBSYSTEM

USE JOBS SHARED
GO mrecno  &&  Record number of the job

IF SYS(3)+SYS(2003)="C:\JOBSYSTEM"

  IF NOT DIRECTORY(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+ ;
    LTRIM(STR(JOBNUMB))+"-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+ ;
    " "+ALLTRIM(JOBTITLE))

      MKDIR(SYS(2003)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
        "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
  ENDIF

ELSE  &&  Server Path (Standalone name)
		
  IF NOT DIRECTORY(ALLTRIM(mserverpath)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+ ;
    LTRIM(STR(JOBNUMB))+"-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+ ;
    " "+ALLTRIM(JOBTITLE))

    MKDIR(ALLTRIM(mserverpath)+"\"+LTRIM(STR(JOBYEAR))+" jobs\"+LTRIM(STR(JOBNUMB))+ ;
      "-"+LTRIM(STR(JOBYEAR))+" "+ALLTRIM(ICOMPANY)+" "+ALLTRIM(JOBTITLE))
  ENDIF

ENDIF

WAIT "Job Number: "+LTRIM(STR(JOBNUMB))+"/"+LTRIM(STR(JOBYEAR))+CHR(13)+CHR(13)+ ;
  "Client: "+ALLTRIM(ICOMPANY)+SPACE(10)+CHR(13)+CHR(13)+"Job: "+ALLTRIM(JOBTITLE)+ ;
  CHR(13)+CHR(13)+"is now active" WINDOW NOWAIT

So whether this is the right or wrong way, it works now and as we are only a small business, I'm happy to go with this.

Thanks to all those who posted on this thread.


Thank you

Steve Williams
VFP9, SP2, Windows 10
 
If that works it's okay of course. I'd be worried about the current directory set wrongly, which could fool that code into thinking it's not the server.

On the other side, also on the server itself the path \\DESKTOP-XXXXXXXX\JOBSYSTEM will address the local folder, it just addresses it via its network share address. So there would be no reason to differentiate this and you could run the ELSE part for anyone.

The other thing I notices in the first line is that you already have what I suggested to use anyway: USE URNTABLE SHARED opens up a dbf that is configuration data. Some very specific configuration data, but it contains the server path. So that's already using what I suggested. You just didn't noticed that.

Now, it would be ironic if URNTABLE.DBF is a dbf in the network, that every EXE opens up because that would mean you have solved how to address a shared central directory containing the URNTABLE.dbf before all this code already, just not noticing that. If URNTABLE.DBF is a file that's installed per computer in the same place, side by side by the EXE, for example, you could use that to store \\DESKTOP-XXXXXXXX for networked PCs and C:\JOBSYSTEM for the server and you have what I suggested, too.

Overall I see no real need for your IF statement at all.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top