Work summary for the last two weeks

Source: Internet
Author: User
Tags server installation and configuration

This project is finally completed. Because the Server installation and configuration process in a certain national department is too complicated, the system uses the image restoration method to modify the configuration for deployment;

The code in this article follows the wtfpl protocol, reprinted please note Source: http://www.cnblogs.com/zaiyuzhong/p/3935155.html

 

1. Stop/disable services

1 var P = new process (); 2 p. startinfo = new processstartinfo ("cmd.exe") 3 {4 useshellexecute = false, 5 createnowindow = true, 6 redirectstandardinput = true 7}; 8 p. start (); 9 invokechangetext ("stop the ibmwebsphere service... "); 10 p. standardinput. writeline ("SC stop ibmwebsphere ");
Call the CMD command SC for implementation.

Note: I. Disable the addition of P. standardinput. writeline ("SC config service name start = Disable ");

II. I don't know how to get the first character in each line of the CMD window. It is always garbled, so a space is added;

III. if there are multiple (XX related services are stopped), you need to traverse the system cyclically. serviceprocess. servicecontroller. getservices ()/* seems to add a reference */returned set. The service name is determined based on the servicename attribute of the element and then the service name is stopped/disabled;

2. Modify the machine name

1 var key = registry. localmachine; 2 using (VAR activecomputername = key. createsubkey ("System \ CurrentControlSet \ Control \ computername \ activecomputername") 3 activecomputername. setvalue ("computername", new machine name); 4 using (VAR computername = key. createsubkey ("System \ CurrentControlSet \ Control \ computername") 5 computername. setvalue ("computername", new machine name); 6 using (VAR hostname = key. createsubkey ("System \ CurrentControlSet \ Services \ Tcpip \ Parameters \") 7 {8 hostname. setvalue ("hostname", new machine name); 9 hostname. setvalue ("NV hostname", new machine name); 10}
The modification takes effect after the registry is restarted.

Note: I. Mainly use the Microsoft. win32.registry class. Seven static fields correspond to the Registry's base items;

Ii. You can also call the opensubkey method of the registrykey class to find the key, but pay attention to the write permission;

3. Modify the Registry(See figure 2. This is a bit full. Sorry)

4. Modify the shortcut target

 There are two methods for this. The test through iwshshortcut has no effect. I don't know if I call the API wrong or how to drop it;

A. iwshsortcut

Note: I. You need to reference the Windows Script Host Object Model in COM;

Ii. do not include any characters that cannot be used by the file name in the targetpath attribute; otherwise, argumentexception is triggered;

Iii. If you need to add parameters to the target, assign them to the arguments attribute;

1 var wshshell = new wshshell (); 2 var shortcut = default (iwshshortcut); 3 shortcut = (iwshshortcut) wshshell. createshortcut (@ "C: \ Users \ rainierw \ Desktop \ console. lnk "); 4 shortcut cut. targetpath = "% WINDIR % \ system32 \ cmd.exe"; 5 shortcut. arguments = "/C start/B http: // 127.0.0.1: 9060/IBM/console"; 6 shortcut cut. save ();
Iwshsortcut

B. The cmd command. For the complete code, see 1;

CMD command: "MSHTA VBScript: Execute (" set a = Createobject ("" wscript. shell ""): Set B =. createshortcut ("" lnk file fullname ""): B. arguments = ("target parameter" "): B. targetpath = ("" target fullname ""): B. save: Close ")";

Note: I. Pay attention to the number of quotation marks and special characters in various languages;

5. rename a folder

 I think my method is not very good: Get the folder name from the directoryinfo object, replace string to get the new folder name, create a new folder, move all the content in the original folder to the new folder, delete the original folder; hope to enlighten me;

6. Extend the disk space to the maximum.

Because the image is used for restoration, the disk size is large and small, and the disk space needs to be extended after restoration;

 1 var p = new Process(); 2 p.StartInfo = new ProcessStartInfo("cmd.exe") 3 { 4     UseShellExecute = false, 5     CreateNoWindow = true, 6     RedirectStandardInput = true, 7     Arguments = "diskpart /s ExtendDisk.txt" 8 }; 9 p.Start();10 p.StandardInput.WriteLine("exit");
CMD command diskpart call external command
 1 sele disk 0 2 sele part 0 3 exte 4 sele part 1 5 exte 6 sele disk 1 7 sele part 0 8 exte 9 sele part 110 exte11 exit
Extenddisk.txt

7. Modify Nic Configuration

This task took three or four days. First, check whether there is an available Nic. If no prompt is displayed, modify the NIC. You can select more than one Nic; to display the NIC information, try to change the adapter page like windows;

A. determine whether a network adapter is available to call networkinterface. getisnetworkavailable ()

B. Obtain the NIC information through managementclass (in fact, more than the NIC, CPU information can also be obtained from this class). You need to add system. Management reference;

C. Because netconnectionid must be displayed again and IPaddress must be displayed again.

1 var adapters = new managementclass ("win32_networkadapterconfiguration"). getinstances (); 2 foreach (managementobject A in adapters) 3 {4 If (! (Bool) A ["ipenabled"]) continue; 5 _ adapters. add (uint) A ["Index"], a); 6} 7 8 If (_ adapters. count <= 1) return; 9 10 var MOC = new managementclass ("win32_networkadapter "). getinstances (); 11 foreach (managementobject Mo in MoC) 12 {13 if (! (Bool) Mo ["physicaladapter"]) continue; 14 var IP = string. empty; 15 uint I; 16 if (uint. tryparse (string) Mo ["DeviceID"], out I) & _ adapters. containskey (I) 17 IP = (string []) (_ adapters [I] ["IPaddress"]) [0]; 18 var r = new radiobutton () {autosize = true, tag = Mo}; 19 R. TEXT = string. format ("{0} \ r \ n {1} \ r \ n {2}", Mo ["netconnectionid"], IP, substringname (Mo ["name"]); 20 R. checkedchanged + = new eventhandl Er (Object sender, eventargs e) => 21 {22 var radio = sender as radiobutton; 23 if (! Radio. Checked) return; 24 if (MessageBox. Show ("this operation will overwrite the network configuration of this Nic. Are you sure you want to modify it? "," Prompt ", messageboxbuttons. okcancel, messageboxicon. Question )! = Dialogresult. OK) return; 25 invokechangeflpenabledvisible (false, true); 26 This. cursor = cursors. waitcursor; 27 changeadapter (managementobject) radio. tag, _ address, _ subnetmask, _ gateway); 28 invokechangeflpenabledvisible (false, false); 29}); 30 this. flowlayoutpanel1.controls. add (r); 31}
View code

Among them: managementclass ("win32_networkadapterconfiguration "). the instance obtained by getinstances () does not include netconnectionid and name. It has name and index (this attribute is described later), while managementclass ("win32_networkadapter "). the instance obtained by getinstances () has no IPaddress, including netconnectionid, name, and DeviceID;

I found that the index and DeviceID are the same, so...

Finally, restart the computer.

Well, system. diagnostics. process. start ("shutdown", @ "/R/T 0/d p: 1: 4"); the second parameter is required for the command. Ask cmd for the specific meaning;

Work summary for the last two weeks

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.