Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OT: how to detect OS and CPU type with javascript?

3,386 views
Skip to first unread message

Don84

unread,
Sep 25, 2009, 9:39:27 PM9/25/09
to
My apologies for the OT but quite a lot of genius here on this NG I
simply can't resist.

Did a bit of digging myself, neither navigator.userAgent nor
navigator.appVersion command would suffice for the CPU part. Hmm, is
javascript simply unable to or I simply don't know better?

As always many thanks.

Pegasus

unread,
Sep 26, 2009, 2:37:48 AM9/26/09
to

"Don84" <tatat...@gmail.com> wrote in message
news:c563a95f-52f2-4f33...@e34g2000vbm.googlegroups.com...

If VB Script is acceptable then Item 16 on this page will do the trick:
http://www.paulsxp.com/tweaksxp.html. Just remove the persistent
commercials.


Pegasus

unread,
Sep 26, 2009, 6:21:02 AM9/26/09
to

"Don84" <tatat...@gmail.com> wrote in message
news:c563a95f-52f2-4f33...@e34g2000vbm.googlegroups.com...

Here is a condensed version:

Const HKEY_LOCAL_MACHINE = &H80000002
Set wshShell = WScript.CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!" &_
"\\.\root\default:StdRegProv")
sKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
sValueName = "PROCESSOR_ARCHITECTURE"
oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,sValue
wscript.echo "Processor architecture:", sValue

sKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
sValueName = "PROCESSOR_IDENTIFIER"
oReg.GetStringValue HKEY_LOCAL_MACHINE,sKeyPath,sValueName,sValue
wscript.echo "Processor identifier:", sValue

For Each pm In GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("Select CurrentTimeZone, InstallDate From Win32_OperatingSystem")
With CreateObject("WbemScripting.SWbemDateTime")
.Value = pm.InstallDate
wscript.echo "Installation date:", DateAdd("n", - pm.CurrentTimeZone,
.GetVarDate)
End With
Next


>

unread,
Sep 26, 2009, 7:21:58 AM9/26/09
to
Pegasus said :

Technically this doesn't fulfill the task, it will only detect Windows
Operating Systems!
I'm guessing that javascript was requested specifically because it is
generally OS independent. For that reason the question should have been
posed in an appropriate group.

That aside, what is the reason for you to detect the OS and or
processor architecture? Which of those particular things is a must have
requirement for you? For example a 32 bit OS or process may be running
on a 64 bit processor. That processor may be IA64 or AMD64 is that
important or not?
Are you looking for Linux Mac etc. or just Windows? If Windows only are
there any specific OS's you aren't interested in 95, NT3.x, 98, NT4,
2000, ME, etc.


Don84

unread,
Sep 26, 2009, 10:16:36 AM9/26/09
to
On Sep 26, 7:21 am, ten.nig...@virgin.net < > wrote:
> Pegasus said :
>
> > "Don84" <tatata9...@gmail.com> wrote in message

Good point on the WHY part and its follow-up questions/comments. Here
I have a web app converted web desktop app ("web desktop app", a term
I coined myself), it supports Windows XP and Vista only and 32bit CPU
only. See, http://www.knowledgenotebook.com/readme.htm. Albeit clear
documentation, some users with 64bit CPU still download and try to
install the app (of course it failed to run). So, the thought is to
detect a user's OS and CPU architecture when he/she visits the page,
if not supported, warn him/her that "the app won't run on the computer
you're using right now" or something like that.

Don84

unread,
Sep 26, 2009, 10:17:32 AM9/26/09
to
On Sep 26, 6:21 am, "Pegasus" <I....@fly.com.oz> wrote:
> "Don84" <tatata9...@gmail.com> wrote in message

Pegasus, sorry I would have to forgo vb option. Don

Ted Davis

unread,
Sep 26, 2009, 12:19:22 PM9/26/09
to
On Sat, 26 Sep 2009 07:16:36 -0700, Don84 wrote:

>
> Good point on the WHY part and its follow-up questions/comments. Here I
> have a web app converted web desktop app ("web desktop app", a term I
> coined myself), it supports Windows XP and Vista only and 32bit CPU only.
> See, http://www.knowledgenotebook.com/readme.htm. Albeit clear
> documentation, some users with 64bit CPU still download and try to install
> the app (of course it failed to run). So, the thought is to detect a
> user's OS and CPU architecture when he/she visits the page, if not
> supported, warn him/her that "the app won't run on the computer you're
> using right now" or something like that.

If you have CGI rights on the server, you can examine the HTTP_USER_AGENT
server environment variable for clues: the OS version will be there, and
some of the other data my contain versions info that can be traced to
32/64 bit versions. The content of the string is specific to the browser,
but it would be difficult to run an incorrect browser version on a system.
You would need to examine the responses from all the common browsers under
all the acceptable (and some unacceptable) OSs to find out what the
strings mean.

Some of the information is available via Javascript, but the code is
different for different browsers. Search on
javascript "define browser"
to find examples.

The search string
javascript "determine operating system"
also returns some interesting code.

Google is your friend.


--

T.E.D. (tda...@mst.edu)

Don84

unread,
Sep 26, 2009, 2:26:41 PM9/26/09
to
On Sep 26, 12:19 pm, Ted Davis <tda...@mst.edu> wrote:
> On Sat, 26 Sep 2009 07:16:36 -0700, Don84 wrote:
>
> > Good point on the WHY part and its follow-up questions/comments.  Here I
> > have a web app converted web desktop app ("web desktop app", a term I
> > coined myself), it supports Windows XP and Vista only and 32bit CPU only.
> > See,http://www.knowledgenotebook.com/readme.htm.  Albeit clear

> > documentation, some users with 64bit CPU still download and try to install
> > the app (of course it failed to run).  So, the thought is to detect a
> > user's OS and CPU architecture when he/she visits the page, if not
> > supported, warn him/her that "the app won't run on the computer you're
> > using right now" or something like that.
>
> If you have CGI rights on the server, you can examine the HTTP_USER_AGENT
> server environment variable for clues: the OS version will be there, and
> some of the other data my contain versions info that can be traced to
> 32/64 bit versions.  The content of the string is specific to the browser,
> but it would be difficult to run an incorrect browser version on a system.
> You would need to examine the responses from all the common browsers under
> all the acceptable (and some unacceptable) OSs to find out what the
> strings mean.
>
> Some of the information is available via Javascript, but the code is
> different for different browsers.  Search on
>   javascript "define browser"
> to find examples.
>
> The search string
>   javascript "determine operating system"
> also returns some interesting code.
>
> Google is your friend.
>
> --
>
> T.E.D. (tda...@mst.edu)

For HTTP_USER_AGENT

With Firefox 3.5 I get:
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3) Gecko/
20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)

With IE7 I get:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR
2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR
3.0.30618)

hmm, I can't seem to see anything that could be translated into cpu
arch. What else could we try?

Thanks.

Ted Davis

unread,
Sep 26, 2009, 7:55:07 PM9/26/09
to
On Sat, 26 Sep 2009 11:26:41 -0700, Don84 wrote:
>
> With Firefox 3.5 I get:
> Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3) Gecko/
> 20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
>
> With IE7 I get:
> Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR
> 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
>
> hmm, I can't seem to see anything that could be translated into cpu arch.
> What else could we try?

What do you get from different CPUs? Under Linux I get a note from
Firefox that indicates it's a 64 bit system - maybe something like that
also exists under Windows, or there might be something in the rv or .net
numbers that indicates that. I don't have 64bit Windows available.

--

T.E.D. (tda...@mst.edu)

Scott Seligman

unread,
Sep 26, 2009, 11:46:28 PM9/26/09
to

For 32-bit IE running in Vista/64,
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0;
SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR
3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729)

And 64-bit IE
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64;
Trident/4.0; .NET CLR 2.0.50727; SLCC1; Media Center PC 5.0; Tablet PC
2.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729)

Neither Firefox or Chrome give any hint it's a 64-bit system.

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
We must believe in luck. For how else can we explain the success of
those we don't like?
-- Jean Cocteau

Ted Davis

unread,
Sep 27, 2009, 10:36:51 AM9/27/09
to
On Sat, 26 Sep 2009 20:46:28 -0700, Scott Seligman wrote:

> For 32-bit IE running in Vista/64,
> Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0;
> SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR
> 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
>
> And 64-bit IE
> Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Win64; x64;
> Trident/4.0; .NET CLR 2.0.50727; SLCC1; Media Center PC 5.0; Tablet PC
> 2.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
>
> Neither Firefox or Chrome give any hint it's a 64-bit system.

IE is clear enough, but what, exactly, do the 32bit and 64 bit FF and
Chrome versions report?

A search on
javascript detect "64 bit" windows
turned up a few suggestions, none of which are reliable.

Maybe you should just ask the user to run some utility that is always
present and indicates the OS and copy/paste the result into a form, or
copy/paste something from a right click menu item somewhere. My
Computer->Properties->General has a lot of non-copyable information -
maybe you could have the user type in the needed info.

--

T.E.D. (tda...@mst.edu)

Dr J R Stockton

unread,
Sep 27, 2009, 2:19:56 PM9/27/09
to
In alt.msdos.batch.nt message <c563a95f-52f2-4f33-ad92-0e525b4d7094@e34g
2000vbm.googlegroups.com>, Fri, 25 Sep 2009 18:39:27, Don84
<tatat...@gmail.com> posted:

If your interest includes JavaScript running in Web browsers, you should
ask in news:com.lang.javascript. Be aware that browsers may be
configured, even by default, to lie about the information you want.

If your interest includes JavaScript running in Windows Scripting Host,
you should ask in news:microsoft.public.scripting.wsh.

If your interest includes JavaScript running in an HTA, you should ask
in a news:microsoft.* HTA newsgroup.

If your interest includes JavaScript running in specific non-Windows
operating systems, you should ask in corresponding newsgroups.

A Bing search on detect OS using JavaScript will locate, currently,
1.8E6 Web pages that might help; consider what might be a better search
string.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

0 new messages