JavaScript gets the machine name, user name, read/write registry, launch application

Source: Internet
Author: User

JavaScript gets the machine name, user name, read/write registry, launch application
JavaScript has a special object ActiveXObject, which provides access to the local file system and applications of Windows.
For example: Sometimes we need to get the user's machine name, user name, get the information of a file, or read or write the registry, or start the calculator, Outlook and other applications.

Here are some common methods, each of which has been tested.
<script language= "JavaScript" >
Get machine name, login domain and login user name
function GetUserName ()
{
var wshnetwork = new ActiveXObject ("Wscript.Network");
Alert ("Domain =" + Wshnetwork.userdomain);
Alert ("Computer Name =" + Wshnetwork.computername);
Alert ("User Name =" + Wshnetwork.username);
}

Get the system catalog
function Getprocessnum ()
{
var pnsys=new activexobject ("Wscript.Shell");
Pn=pnsys. Environment ("PROCESS");
Alert (PN ("windir"));
}
Returns the path to a special directory in the system
function GetSpecialFolder ()
{
var mygetfolder=new activexobject ("Wscript.Shell");
if (Mygetfolder. Specialfolders ("Fonts")!=null)
{
Alert (Mygetfolder. Specialfolders ("Fonts"));
}
}
Get the disk information incoming parameters such as: Getdiskinfo (' C ')
function Getdiskinfo (para)
{
var fs=new activexobject ("Scripting.FileSystemObject");
D=fs. Getdrive (para);
S= "Volume Label:" + d.volumnname;
s+= "------" + "remaining space:" + d.freespace/1024/1024 + "M";
s+= "------" + "Disk serial number:" + d.serialnumber;
Alert (s)
}
Get the system catalog
function Getprocessnum ()
{
var pnsys=new activexobject ("Wscript.Shell");
Pn=pnsys. Environment ("PROCESS");
Alert (PN ("windir"));
}
Start Calculator
function Runcalc ()
{
var calc=new activexobject ("Wscript.Shell");
Calc. Run ("Calc");
}
Read the values in the registry
function Readreg ()
{
var myreadreg=new activexobject ("Wscript.Shell");
try{
Alert (Myreadreg. RegRead ("Hkey_local_machine\\software\\microsoft\\windows\\currentversion\\run\\nerocheck"));
}
catch (E)
{
Alert ("The Read value does not exist!") ");
}
}
Write the Registration form
function Writereg ()
{
var mywritereg=new activexobject ("Wscript.Shell");
try{
Mywritereg. RegWrite ("Hkey_local_machine\\software\\microsoft\\windows\\currentversion\\run\\mytest", "C:\\mytest.exe");
Alert ("Write succeeded!") ");
}
catch (E)
{
Alert ("The Write path is incorrect! ");
}
}
Delete Registry
function DelReg ()
{
var mydelreg=new activexobject ("Wscript.Shell");
if (Confirm ("Is it really deleted? "))
{
try{
Mydelreg. RegDelete ("Hkey_local_machine\\software\\microsoft\\windows\\currentversion\\run\\mytest");
Alert ("Delete succeeded! ");
}
catch (E)
{
Alert ("Delete path is incorrect");
}
}
}
Get file information call method: GetFileInfo (' c:\\test.pdf ')
function GetFileInfo (para)
{
var myfile=new activexobject ("Scripting.FileSystemObject");
var fi=myfile. GetFile (para);
Alert ("File type:" +fi.type+ "File Size:" +fi.size/1024/1024+ "M" + "Last Access time:" +fi. datelastaccessed);
}
Get information about the client
function Clientinfo ()
{
strclientinfo= "availheight=" +window.screen.availheight+ "\ n" +
"Availwidth=" +window.screen.availwidth+ "\ n" +
"Bufferdepth=" +window.screen.bufferdepth+ "\ n" +
"Colordepth=" +window.screen.colordepth+ "\ n" +
"colorenable=" +window.navigator.cookieenabled+ "\ n" +
"cpuclass=" +window.navigator.cpuclass+ "\ n" +
"height=" +window.screen.height+ "\ n" +
"Javaenable=" +window.navigator.javaenabled () + "\ n" +
"platform=" +window.navigator.platform+ "\ n" +
"systemlanguage=" +window.navigator.systemlanguage+ "\ n" +
"userlanguage=" +window.navigator.userlanguage+ "\ n" +
"Width=" +window.screen.width;
alert (strclientinfo);
}

</script>

JavaScript gets the machine name, user name, read/write registry, launch application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.