Solved

Get Unique PC Identifier

Posted on 2013-05-25
11
751 Views
Last Modified: 2013-05-26
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
Comment
Question by:Bob Schneider
11 Comments
 
LVL 14

Assisted Solution

by:Faustulus
Faustulus earned 83 total points
ID: 39197133
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
 

Author Comment

by:Bob Schneider
ID: 39197149
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
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 83 total points
ID: 39197194
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:Bob Schneider
ID: 39197198
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
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 334 total points
ID: 39197217
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
 

Author Comment

by:Bob Schneider
ID: 39197219
I would love to know how to do a Windows API Call to identify the machine name if you would be so kind.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 334 total points
ID: 39197267
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
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 334 total points
ID: 39197270
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
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 334 total points
ID: 39197272
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
 

Author Comment

by:Bob Schneider
ID: 39197655
Awesome!  Thank you!!
0
 

Author Closing Comment

by:Bob Schneider
ID: 39197658
Great stuff!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question