ActiveXObject functions in detail __ functions

Source: Internet
Author: User
Tags access properties
What is an ActiveX control. ActiveX controls are widely used on the Internet. They can add to the fun of browsing by providing video, animated content, and so on. However, these programs may have problems or provide you with unwanted content. In some cases, these programs can be used to collect information from your computer in ways you do not allow, to destroy data on your computer, to install software on your computer without your consent, or to allow others to remotely control your computer. With these risks in mind, you should install these programs without fully trusting the publisher. What you should do when Windows blocks ActiveX controls from being installed. You might not want to install the ActiveX control. Installing Windows blocked ActiveX controls is an extremely risky thing to do. If the Internet Explorer security setting is at the default level, and the ActiveX control does not have a valid digital signature, Windows blocks the ActiveX control from being installed. A valid digital signature confirms the identity of the publisher (the company, website, or person distributing the file) and confirms that the document has not been tampered with since it was signed. If the file does not have a valid digital signature, you cannot determine whether the file is actually from the source it declares, or if it has not been tampered with (for example, a virus may be inserted into the control). You should not open a file unless you trust the publisher and know that the content will be secure when the file is opened. ActiveXObject Object Usage Description: The ActiveXObject object in JavaScript is a reference that enables and returns automation objects. How to use: NEWOBJ = new ActiveXObject (servername.typename[, Location]) ActiveXObject object syntax has these parts: NEWOBJ is the required option. The name of the variable to assign to ActiveXObject. ServerName is a required option. The name of the application that provided the object. TypeName is a required option. The type or class of the object to create. Location is optional. The name of the network server on which the object was created. The Automation server provides at least one class of objects, such as a word-processing application that might provide application objects, document objects, and toolbar objects. For example, to create the application and sheet objects for Excel, the code is as follows:
var excelapp = new ActiveXObject ("Excel.Application");
var excelsheet = new ActiveXObject ("Excel.Sheet")

Once an object is created, it can be referenced in code with the defined object variable. Here we'll look at references to objects and methods, using object variables ExcelSheet to access properties and methods of new objects and other Excel objects, including application objects and ActiveSheet.Cells collections. The code is as follows:
ExcelSheet.Application.Visible = true;
ExcelSheet.ActiveSheet.Cells (1,1). Value = "This is column A, row 1";
Excelsheet.saveas ("C:\\test.") XLS ");
ExcelSheet.Application.Quit ();

Let's look at how to create objects in a remote server, but there is a prerequisite to shutting down Internet security. To create an object on a remote network computer, you can pass the name of the computer to the activexobject servername parameter. The name is the same as the machine name part of the share name. For example, share the network named "\\MyServer\Public", servername is "MyServer". Alternatively, you can specify ServerName in DNS format or IP address. The following code returns the version number of an instance of Excel running on a remote network computer named "MyServer":

function Getappversion () {
     var xlapp = new ActiveXObject ("Excel.Application", "MyServer");
     return (xlapp.version);
}
If the specified remote server does not exist or cannot be found, an error occurs.
javascript get the machine name, username, read and write the registry, start the application//javascript has a special object ActiveXObject,     
    
It allows access to Windows ' local file systems and applications, such as: sometimes we need to get the user's machine name, username, get information about a file, read or write to the registry, or launch applications such as calculators, Outlook, and so on.     
Here are some common methods, each of which has been tested. <script language= "JavaScript" >//Get machine name, login domain and login username function getusername () {var wshnetwork = new      
ActiveXObject ("Wscript.Network");      
Alert ("Domain =" + Wshnetwork.userdomain);      
Alert ("Computer Name =" + Wshnetwork.computername);      
Alert ("User Name =" + Wshnetwork.username);      
        //Get system directory function Getprocessnum () {var pnsys=new activexobject ("Wscript.Shell"); Pn=pnsys.      
        Environment ("PROCESS");     
Alert (PN ("windir")); }//return path function GetSpecialFolder () {
for special directories in the system
    var mygetfolder=new activexobject ("Wscript.Shell"); if (Mygetfolder. Specialfolders ("Fonts")!=null) {alert (mygetfolder.     
     Specialfolders ("Fonts")); }//Get disk information incoming parameters such as: Getdiskinfo (' C ') function Getdiskinfo (para) {var fs=new activexobject ("SC      
    Ripting.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 system directory 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 value 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 value read) does not exist."     
     ");      
    ///write Registry 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 ("Write path is incorrect.")     
     ");      
    }///delete registry function DelReg () {var mydelreg=new activexobject ("Wscript.Shell"); if (confirm () is really deleted. ")) {try{Mydelreg.     
    RegDelete ("Hkey_local_machine\\software\\microsoft\\windows\\currentversion\\run\\mytest"); Alert ("Delete succeeded.")     
");     
catch (E) {alert ("Incorrect delete path"); //Get file information call way like: geTfileinfo (' c:\\test.pdf ') function GetFileInfo (para) {var myfile=new activexobject ("Scripting.filesyst      
    Emobject "); var fi=myfile.      
    GetFile (para); Alert (file type: +fi.type+ file size: +fi.size/1024/1024+ "M" + "Last accessed:" +fi.     
datelastaccessed); //Get Client Information 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>//Save as Excel file and write value function SaveAs () {var excelapp = new ActiveXObject ("exc El.      
Application ");      
var excelsheet = new ActiveXObject ("Excel.Sheet") ExcelSheet.Application.Visible = true; ExcelSheet.ActiveSheet.Cells (1,1).      
Value = "This is column A, row 1"; Excelsheet.saveas ("C:\\test.")     
XLS ");     
ExcelSheet.Application.Quit (); 
 Alert (' OK ');}


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.