Windows 指令碼主機概述

來源:互聯網
上載者:User

Windows 指令碼主機概述

 

首先,什麼是WSH?

http://search.microsoft.com/zh-cn/results.aspx?form=MSHOME&setlang=zh-cn&q=WSH

Windows Script Host (WSH) is a Windows administration tool.

http://technet.microsoft.com/zh-cn/subscriptions/shzd7dy4(v=vs.80).aspx

WSH creates an environment for hosting scripts. That is, when a script arrives at your computer, WSH plays the part of the host — it makes objects and services available for the script and provides a set of guidelines within which the script is executed. Among other things, Windows Script Host manages security and invokes the appropriate script engine.

WSH Objects and Services

Windows Script Host provides several objects for direct manipulation of script execution, as well as helper functions for other actions. Using these objects and services, you can accomplish tasks such as the following:

  • Print messages to the screen
  • Run basic functions such as CreateObject and GetObject
  • Map network drives
  • Connect to printers
  • Retrieve and modify environment variables
  • Modify registry keys
Windows Script Host Object Model

http://technet.microsoft.com/zh-cn/subscriptions/a74hyyw0(v=vs.80).aspx

 

關於WSH的架構資訊,這篇文章描述的不錯

http://technet.microsoft.com/zh-tw/library/dd180733.aspx

 

' WSHInfo.vbs 顯示 WSH 的若干訊息

Option Explicit

Dim strHostName,strHostFullPathName,strScriptFullName

Dim strMessage

strHostName = WScript.Name & " " & WScript.Version & vbCrLf

strHostFullPathName = "目前的 WSH 程式是由 " & WScript.FullName &

"所執行" & vbCrLf

strScriptFullName = "所執行的 WSH 程式是 " & WScript.ScriptFullName

strMessage = strHostName & vbCrLf & strHostFullPathName &

vbCrLf & strScriptFullName

MsgBox strMessage, vbInformation, "WSH 相關訊息"  

 

下面是我寫的一段測試代碼:

count=0

set shell=wscript.createObject("wscript.shell")

 

password = inputbox("pig pangpang, my password please:")

do while password<>"888888"

       count = count +1

       msgbox "error password,exit now " & count & " times",48,"authentication"

             

       if count=10 then

              msgbox "you are not lucky, little girl. evil is fallen!",0,"DEAD PC"

              shell.run "shutdown -r -t 60",1

              exit do

       elseif count =9 then

              msgbox "there is only 1 times, reaching to 10 your PC will restart!",48,"Critical!"

       end if

 

       password = inputbox("pig pangpang, my password please:")

loop

 

shell.run "notepad.exe",1

wscript.Sleep 200

shell.AppActivate "無標題 - 記事本"

wscript.Sleep 200

'set msg = shell.readkeys;

 

'對於需要與Shift、Ctrl、Alt三個修飾鍵組合的按鍵,SendKeys使用特殊字元來表示:Shift —— +;Ctrl —— ^;Alt —— %

shell.sendkeys "hello,pig pangpang!"

shell.sendKeys "{TAB}{TAB}"

shell.sendKeys "it's so amazing...."

shell.sendkeys "{enter}"

shell.sendkeys "{enter}"

shell.sendkeys "{f5}"

shell.sendkeys "{enter}"

shell.sendKeys "by Big Uncle"

shell.sendkeys "^%+{DEL}"

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.