Announcement

Collapse
No announcement yet.

Server detection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Iain Johnstone
    replied
    OK- tools unloaded and back to programming - its a tough life!

    The reason I need to know if a program is being run from a server
    id down to the protection system I use. This puts a hidden file
    in the system directory (with a convincing name) that contains
    two eight digit numbers. The program does some maths on these
    and continues to run if OK, or else it terminates.

    If the program is installed on a server, it can be run on a
    workstation as the hidden file is on the server and the program
    finds this. This rather defeats the object of the protection,
    and was a glaring oversight on my part.

    The "\\" solution works on my network at home, and will probably
    do the job- if the program detects that it is being run from a
    server, it puts up a frightener message box disclaiming all
    responsibility for data loss due to an incorrect installation,
    then exits, with the suggestion that the program is removed from
    the server.

    The users of this program are drainage and building services
    engineers, so tend not to poke about in the workings of their
    workstations, and can be seriously worried about data loss
    messages, with a network administrator breathing down their
    necks.

    I would like to take this opportunity to thank everybody who has
    helped over the years with this program - I have just received a
    cheque for £5.5K as the proceeds of the first sale of five
    programs to a major international firm of consulting engineers
    (Ove Arup if it rings a bell), so the wolf is away from the door
    for a little while longer! I have also had to to learn how to
    write DLLs, as the base code for the program is just under the
    magic limit - I find it does not compile when the EXE gets to
    over 820K, si it is useful to put extra code in DLLs and call
    them - I cannot see why I was so scared of them in the beginning.
    Many thanks
    Iain Johnstone

    ------------------

    Leave a comment:


  • Iain Johnstone
    replied
    Thanks for the input. I have just got back after six days away
    working (without my trusty laptop) so I have a lot of catching up
    to do. Will therefore post a more detailed reply later!
    Iain


    ------------------

    Leave a comment:


  • Wayne Diamond
    replied
    good points Eric - i haven't tested this with shortcuts yet, but it works fine when the exe is run directly:
    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
       
    FUNCTION AppExeName() AS STRING
    ON ERROR RESUME NEXT
      LOCAL hModule AS LONG
      LOCAL buffer  AS ASCIIZ * 256
      hModule = GetModuleHandle(BYVAL 0&)
      GetModuleFileName hModule, Buffer, 256
      FUNCTION = Buffer
    END FUNCTION
     
    FUNCTION PBMAIN() AS LONG
    ON ERROR RESUME NEXT
    LOCAL AppName AS STRING
    AppName = AppExeName
    IF LEFT$(AppName,2) = "\\" THEN
       'Running from a network
    ELSE
       DIM DriveType AS LONG
       DriveType = GetDriveType(LEFT$(AppName,2))
       IF DriveType = %DRIVE_FIXED THEN
          'Running from hard-drive
       ELSE
          'Running from network or cd-rom or removable or ramdisk etc or other - but not hard-drive
       END IF
    END IF
    END FUNCTION

    ------------------

    Leave a comment:


  • Eric Pearson
    replied
    PMJI, but I don't think that method is reliable. First, it's possible for a Windows shortcut to point to a UNC (\\) location on the local computer. You might be able to work around that by comparing the first segment of the UNC to the GetComputerName string, but...

    Second, if a location on the network is mapped to a drive letter, IIRC the GetModuleFileName API will return the mapped location, like X:\MyDir\MyApp. (I didn't try it, I'm just going from memory, but I'm pretty sure.)

    Iain, can you clarify what you are trying to accomplish? When you say "I need to stop program execution if it is running from the server" do you mean that the application cannot be run on the server's CPU, or that any CPU (including the server) can run the program as long as the program files are located on a "local" hard drive? Or...?

    -- Eric


    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Wayne Diamond
    replied
    Sorry Iain,
    I had "\\" and "//" mixed up... (I guess im not so antipodean after-all )
    Ive edited the code.

    Best of luck,
    Wayne


    ------------------

    Leave a comment:


  • Iain Johnstone
    replied
    Another antipodean genius - many thanks, I'll give it go!
    Iain Johnstone

    ------------------

    Leave a comment:


  • Wayne Diamond
    replied
    As you were specific about NT4 this may not be a solution, but this demo checks the location of the program and if it starts with "\\" you know it's running from a network...
    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
      
    FUNCTION AppExeName() AS STRING
    ON ERROR RESUME NEXT
      LOCAL hModule AS LONG
      LOCAL buffer  AS ASCIIZ * 256
      hModule = GetModuleHandle(BYVAL 0&)
      GetModuleFileName hModule, Buffer, 256
      FUNCTION = Buffer
    END FUNCTION
     
    FUNCTION PBMAIN() AS LONG
    ON ERROR RESUME NEXT
    IF LEFT$(AppExeName,2) = "\\" THEN
       'Running from a network
    ELSE
       'Probably running locally
    END IF
    END FUNCTION
    Best of luck,
    Wayne


    [This message has been edited by Wayne Diamond (edited May 02, 2001).]

    Leave a comment:


  • Iain Johnstone
    started a topic Server detection

    Server detection

    How can I detect if a program is being run from a NT4 server,
    or if it is on a local machine? I need to stop program execution
    if it is running from the server, and only allow local machines
    to run it.

    ------------------
Working...
X