PowerShell turn on or off the optical drive _powershell

Source: Internet
Author: User

The chassis is not selected, the CD out/Receive key is blocked, it is awkward to use. Remember that there is a small software can control the optical drive out of the warehouse and the receiving bin. Searched for the Windows API used. Write the following code, I hope you like:

PS c:\users\eden> $a = add-type-memberdefinition @ "
>> [DllImport (" Winmm.dll ", CharSet = CharSet.Ansi)]
   >> public static extern int Mcisendstringa (
>> string lpstrcommand,
>> string lpstrreturnstring,
>> int ureturnlength,
>> IntPtr hwndcallback);
>> @-passthru-name mcisendstring
>>
PS c:\users\eden> $a:: Mcisendstringa (' Set CDAudio door Open ', $null, 0,0); # Open Optical drive
0
PS c:\users\eden> $a:: Mcisendstringa (' Set cdaudio door closed ', $null, 0,0); # Turn off Optical drive
0

Finally, we are attaching all the shortcuts in the console that we summarized today for everyone to use PowerShell. These shortcuts are actually supported by Cmd.exe or any console.

Keys

Function

The cursor moves one character to the left

Ctrl + ←

The cursor moves one word to the left

The cursor moves one character to the right

Ctrl + →

The cursor moves one word to the right

Home Key

The cursor moves to the beginning of the line

End Key

The cursor moves to the end of the line

Delete Key

Delete the character that the cursor points to

Backspace Key or Ctrl + H

Deletes the first character to the left of the cursor

Ctrl + End Key

Remove all characters from the cursor to the end of the line

ESC Key

Clears all characters that are currently entered

Insert Key

Insert and Overwrite mode toggle

Tab Key

Tab The key automatically completes the command, for example: the name of the AutoComplete command , cmdlet the parameter and path of the command. If the first prompt is not the result you expect, continuing to enter the Tab Key will automatically display the next candidate.

Query history command up

Query history commands down

F7 Key

displays command history, gives all commands you have entered in the form of a graphical list window, and is available the UP and DOWN ARROW keys Select to execute the command again.

F8 Key

Search for the history of the command, after entering part of the command on the command, press F8 key, you can get a history command that matches that input. If you have more than one match, press F8repeatedly, and you can loop through all the commands you've entered. If the command behavior is empty, the command that matches all history entries is defaulted.

F9 Key

Select a History command by number, which requires you to enter a number for the command (from 0 starts) and displays the command on the screen.

Enter Key or Ctrl + M

Carriage return ( Enter )

Ctrl + C

Terminate the currently executing command

Ctrl + Break

Terminate the currently executing command

Alt + F7 Key

Clears all previously entered command history

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.