Windows 脚本主机概述

本文详细介绍了Windows脚本主机(WSH)的基本概念及其提供的对象和服务,展示了如何利用WSH实现脚本的安全管理和执行控制,并通过示例代码演示了如何使用WSH进行实际操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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}"

 

转载于:https://www.cnblogs.com/flaaash/archive/2013/01/15/2861128.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值