[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 809
  • Last Modified:

Get Unique PC Identifier

Hi.  I have a piece of software that I run on multiple machines.  Currently you have the option of running it remotely off of the server db or off of the db on the local machine.  I currently have all of the machines that use the software listed in a dropdown so that the user can either check "Remote" or the name of their machine, and the software finds the database from the machine name.  It works fine but I would like to simplify it and allow them to simply choose "Remote" or "Local".  If they choose "local, it will find the database on the machine that they are on.  

When I am working on another machine I constantly choose my normal machine and then I have to wait until it times out because it can't find it (since that is not the machine that I am on) before I correct my mistake.  There has to be a way to "find" the database on the local machine without hard-coding the name into a dropdown???

Any help?
0
Bob Schneider
Asked:
Bob Schneider
6 Solutions
 
FaustulusCommented:
Couldn't you let the program search for the db in a certain sequence, like, IF the db is found on the local machine, use that db, else look for the db on a remote server?
If you need a method to force the program to select the db of the user's choice you might add a drop-down with the choices "Auto" and "Select" where the former is the process I have just described and the latter the one you presently have.
0
 
Bob SchneiderAuthor Commented:
Good suggestion but I want to be able to choose local or remote because it is quicker to run it off of the local db than the server, but how can I get it to look for a local db?  Here is my current connection string:

    If sWhichSrvr = "Remote" Then
        conn.Open "Provider=SQLNCLI10;Server=216.185.199.1,1433\SQLExpress;Database=VIRA;Uid=uid;Pwd=pwd;"
    Else
        conn.Open "Provider=SQLNCLI10;Server=" & sWhichSrvr & "\SQLExpress;Database=dbname;Trusted_Connection=yes;"
    End If

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
If there is an Install procedure for your program, I would have it make an 'ini' file that tells whether there is supposed to be a local database server or not.  If there is not, then it should always connect to the remote.  If it is local you could store the local part of the connection string in the 'ini' file.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Bob SchneiderAuthor Commented:
Actually I just run it out of the exe for now...may change that later.  Can I conclude that there is no way to determine the machine name or some other identifier using vb6?
0
 
Anthony PerkinsCommented:
Can I conclude that there is no way to determine the machine name or some other identifier using vb6?
There are Windows API calls to identify the machine name.  I can look it up if you want.

Alternatively, you can reduce the connection time so that you do not have to wait 30 seconds.
0
 
Bob SchneiderAuthor Commented:
I would love to know how to do a Windows API Call to identify the machine name if you would be so kind.
0
 
Anthony PerkinsCommented:
Here is one example I found:
http://www.vb6.us/tutorials/simple-windows-api-example

There was a site I used to use around 10 years ago that had every possible Windows API call that you could possibly think of using VB6, but for the life of me the name escapes me.  If i find it I will post it.
0
 
Anthony PerkinsCommented:
Here it is:  VBnet Visual Basic Developers Resource Centre

P.S. Don't let the VBnet name fool you, it is all Visual Basic classic.
0
 
Anthony PerkinsCommented:
On second thoughts, you may not need to use a Windows API (although that would certainly work).  There are a couple of other options:
1. The environment variable COMPUTERNAME contains the name (this should be simple call).  This can be spoofed though.
2. You should be able to use the WScript.Network object model to get it also.
0
 
Bob SchneiderAuthor Commented:
Awesome!  Thank you!!
0
 
Bob SchneiderAuthor Commented:
Great stuff!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now