How i can check whether application is running locally or remotely?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Developer111
    New Member
    • Apr 2010
    • 28

    How i can check whether application is running locally or remotely?

    My desktop application is developed in VB.Net and can be run through two types of users, one who install it on their local machine and execute locally.

    Second type of users will run the application remotely from the server.i.e. Application will install on the server and user will execute that application from client side. Server can be a Citrix Meta Frame or any server accessed through Remote Desktop Connection.
    I want to maintain single exe for both types of users.

    Is there any mechanism/way through which I can come to know programmaticall y whether application is running locally or remotely?
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Perhaps you can check for the applicationdire ctory? Something like My.Application. Info.DirectoryP ath...

    Steven

    Comment

    • Developer111
      New Member
      • Apr 2010
      • 28

      #3
      Originally posted by MrMancunian
      Perhaps you can check for the applicationdire ctory? Something like My.Application. Info.DirectoryP ath...

      Steven
      Steven, thank for reply

      Directory Path returns “C:\Progra m Files\[Application Folder]” either executing the application locally or remotely, which doesn't make any difference. I tried for both Citrix and Remote Desktop.

      Please advice.

      Comment

      • robjens
        New Member
        • Apr 2010
        • 37

        #4
        That doesnt really make sense. Why would the server side user have the same local directory structure as the one who is running it actually local?

        Either way, if the appl. path won't help you, I suggest you simply set a application boolean as flag for either running local or remote. How do you know which user will run local/remote? Do you install every time they login/connect? Or keep a .xml file somewhere with this data? User setting perhaps, app.config or???

        Many many options here.

        Comment

        • Developer111
          New Member
          • Apr 2010
          • 28

          #5
          Robjens, thanks for reply

          I think I was unable to explain my problem specially using Remotely and locally mechanism, let me try again.

          I have two types of users.

          1- Who can install the application to their machine and launch it locally.
          2- Second type of users has nothing install on their local machines (client)
          they will login to the server and launch the program from server.

          Important thing is that I have to maintain same version of program for local and server machines. So I need to check at the start of the program whether it is launched by local user or remote user? As program behave differently for local and remote launching.

          Hence directory structure is same but scenarios are different.

          Hope its make sense, other wise I 'll try to explain it in more detail :)

          Comment

          • robjens
            New Member
            • Apr 2010
            • 37

            #6
            I am wondering, how do the local people obtain their copy of the application? In other words, how do you distribute it? Since you are the creator, you'd be in full control there. In those scenario's where you have virtual machines, the local installs would usually be automatically be ran from some kind of update manager so the network admins can control every aspect of the software package.

            You already know that the remote version is the correct one right? The question is if the local installed people have a) internet connection and b) have their own workstations. That would make it a lot easier. All you would need to do is write a script that checks a remote db/file/whatever to see if they have the latest version and if not, force a upgrade on them.

            Basically it's a two way street and you can go either way. Or they check with you on a server if the versions match, or you check on their workstations most probably some setup log file that you want to verify. That is also pretty easy.

            If you cannot rely on them having a connection of some sort and you do not wish to disable the program completely, well that's about it then. You are officially out of options besides having to rely on "hard" media such as asking people face to face what versions they have and send CD's by regular mail....I guess you get the idea ... we don't like that and boy would the co-workers have a field day ;)


            Hope I could have been of some help even though it ain't much...

            Comment

            • robjens
              New Member
              • Apr 2010
              • 37

              #7
              And reading your post again....you say:

              "As program behave differently for local and remote launching.
              Hence directory structure is same but scenarios are different."

              Why rely on a directory structure to do your verification when you can easily check for the version through either a txt, xml or registry key for that matter. There are literally dozens of options there.

              In steps:

              1) distribute the local copies and include a script for writing a version integer/string to a shared file on a network server somewhere, or have the script write to the system registry.

              2) every time you distribute a package or have one ready, you write to a file version +1

              3) whenever remote people connect they already have the right version

              4) when a local user starts the program, get (intranet/internet) access to the shared file and if TheirVersion <> YourVersion = ForceUpdate

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                How does the user "log into the server"?

                I think that you really have 2 separate applications here.

                You could use precompiler statements to build 2 different applications based on the same code. One compiled version will be tailored to be installed and run on the server and the other version will be tailored to be installed and run locally.


                So say you have a function in your code that logs errors. This function, when compiled for the server, will log an error message into the Windows Event Log. When this function is compiled for the local desktop client, error will be appended to a Log.txt file.

                You would have the following code for the "LogError" subroutine:
                Code:
                Public Sub LogError(ByVal errorMessage As String)
                #If APPLICATIONTYPE = "Server"
                  'Code that writes the error message to a 
                  'Windows Event Log called "ServerApplicationLog"
                
                  Dim thelog As New System.Diagnostics.EventLog
                  Dim theSource As String = "ServerApplicationLog"
                  thelog.Source = theSource
                  'Recording the error
                  thelog.WriteEntry(errorMessage, Diagnostics.EventLogEntryType.Error)
                  thelog.Dispose()
                #End If
                
                #If APPLICATIONTYPE = "Local"
                  'Code that writes the error message to a TXT file
                  'called "clientLog.txt" that exists in the application's startup path.
                
                 Dim logFilePath As String = Application.StartupPath + "\clientLog.txt" 
                  Using outfile As New StreamWriter(logFilePath)
                    outfile.Write(errorMessage)
                  End Using
                #End If
                End Sub
                You would define the APPLICATIONTYPE variable by adding it the "Custom Constraints" in the Advanced Compiler Settings for your application.
                To do this:
                • Right click on your project name in the Solution Explorer and click Properties
                • Click the Compiler tab/button
                • Click the "Advanced Compile Options..." button
                • In the Custom Constraints text box type: APPLICATIONTYPE = "ServerApplicat ionLog" if you are compiling the application for the server...otherw ise type APPLICATIONTYPE = "Local"
                • Click the Ok button
                • Build your application


                -Frinny

                Comment

                • Developer111
                  New Member
                  • Apr 2010
                  • 28

                  #9
                  Thanks Frinavale and robjens...I am already aproaching some workarounds...

                  Comment

                  Working...