views:

290

answers:

5

I need a way for my .Net Winform app to detect if my app is opened on a Laptop or a Workstation.

I have looked at Environment and SystemInformation but to no avail. Would WMI do the trick?

Thanks for the direction....


As requested I have an application that uses Merge Replication to allow our users to work in Members homes. Some who use the program never go in the field and as such only have towers. This is a WORK only app so our systems are somewhat controlled. As in, no UPS on Desktops and No Laptop CPU either.

I have setup my DAL to be able to switch, based an a setting, between local SQL and the Central SQL Server. I would like to be able to set this automatically based on there system.

If a laptop then they should be pointing local if a tower, centrally.

Does this help? I deliberately left it off before to don't clutter the answers. My apologies for apologies for accomplishing the opposite.

+3  A: 

Get the type of processor using (see this question):

System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")

If you can determine it is a mobile processor, you have your answer.

(It's worth noting that WMI will give you better info, as explained in the question I linked.)

JYelton
@JYelton - Although it is possible to get a desktop processor in a laptop.
Thomas
…And some people use laptop processors on desktop for lower power consumption. =)
Arkku
Perhaps the definition of laptop and desktop need to be explained, in other words, does the OP want to know the processor type, or the chassis style? If the latter, there's just no way to know!
JYelton
+4  A: 

http://msdn.microsoft.com/en-us/library/Aa394474

then look at

ChassisTypes

Value Meaning
1 Other
2 Unknown
3 Desktop
4 Low Profile Desktop
5 Pizza Box
6 Mini Tower
7 Tower
8 Portable
9 Laptop
10 Notebook
11 Hand Held
12 Docking Station
13 All in One
14 Sub Notebook
15 Space-Saving
16 Lunch Box
17 Main System Chassis
18 Expansion Chassis
19 SubChassis
20 Bus Expansion Chassis
21 Peripheral Chassis
22 Storage Chassis
Keith Nicholas
I didn't know this existed - I doubt it is useful, how would this data get populated? I've built hundreds of desktop PCs and never set any sort of chassis type variable.
JYelton
I'm sure for desktops it would be rarer too populate it.... however, for laptops? as they tend to be OEM, I would think they would be set correctly. (perhaps)
Keith Nicholas
Aah, Pizza Box. Used to have one of those form factors. I doubt this value is often accurate or useful.
Broam
That class has some amazing properties. `ServicePhilosophy` (`ServiceFromTop`, `ServiceFromSide`, ...), `CableManagementStrategy`, `HeatGeneration` (in BTUs/hour), `NumberOfPowerCords`.
Michael Petrotta
I thought you were kidding when you said Pizza Box. Silly me.
Tim Lovell-Smith
+12  A: 

This is a really hard problem to solve because of the edge cases involved. I don'tk now how accurate you need to be for your application, but here is a reliable way to find out if the user is on a sterotypical laptop.

Win32_Battery

You might want to take a look at EstimatedRunTime.

EstimatedRunTime

Data type: uint32
Access type: Read-only

Estimate in minutes of the time to battery charge depletion under the

present load conditions if the utility power is off, or lost and remains off, or a laptop is disconnected from a power source. This property is inherited from CIM_Battery.

You also might want to check:

Win32_PortableBattery

Also, here's an interesting discussion of a similar problem and dealing with UPS.

http://forum.bigfix.com/viewtopic.php?pid=19908

Specifically:

"Microsoft ACPI-Compliant Control Method Battery"

Also, as noted in the comments, you will have to consider users on a laptop plugged into the wall with the battery disconnected.

Robert Greiner
Can a desktop employ a battery (other than UPS)?
JYelton
@JYelton: I haven't heard of one; but UPS causes a bunch of false positives. Win 7 itself is confused by them. For example, if you have a UPS connected to a desktop, 7 believes you are running on battery power and therefore won't give you the windows experience index numbers.
Chris Lively
Yeah, I've been thinking about that. The edge cases here could lead to some false positives/negatives. For instance, what if the user is using a laptop that is connected to the wall with the battery disconnected. Do you call it a laptop because the guy at Fry's said it was? Or do you count it as a desktop because that's how it's being used at present? These are design decisions that will have to be decided on before the application releases.
Robert Greiner
Thanks but because of our in-house "controlled" environment this could well work. Thank you for a positive potential solution accompanied by a word of caution. A perfect SO answer!!
Refracted Paladin
Sure thing, being in a controlled situation will definitely improve your chances of getting a correct reading. This is definitely an interesting problem and I hope you get it working the way you want it. Good luck!
Robert Greiner
A: 

Maybe you can query for battery information?

Take a look at this

Francisco Soto
+1  A: 

Based on your updated information I have a couple of recommendations.

  1. Make it a configurable option. Either during installation or the first run ask them what they are. This is going to be a lot more accurate than guessing.

  2. If you already have merge replication in place... Why not treat everyone as disconnected / remote user?

Chris Lively
**1 -** It IS a configurable option that I can switch at will. The problem is our users CANNOT be trusted to toggle this accordingly. **2 -** Because it seems pointless overhead to replicate to a tower that can NEVER be in the field. Why have the extra complexity and overhead?
Refracted Paladin
"Why have extra complexity and OH?" Because it is the right thing to do - GUESSING based on the hardware is pretty much guaranteed to be wrong and you are going to have the original problem anyway. Basing a decision on hardware type doesn't really solve your problem - at least not as I understand it.
Tim