如果当前指示灯不亮,则打开num lock键盘指示灯.vbs- Set ws = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
- If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
- ws.run "cscript """ & WScript.ScriptFullName & chr(34), 0
- WSH.Quit
- End If
- Set tmp = fso.GetSpecialFolder(2)
- Set systemroot = fso.GetSpecialFolder(0)
- net = systemroot&"\Microsoft.NET\Framework"
- Call CreateCs
- Set SubFolders = fso.GetFolder(net).SubFolders
- For Each Folder In SubFolders
- If fso.FileExists(Folder&"\csc.exe") Then
- cscpath = Folder&"\csc.exe"
- Exit For
- End If
- Next
- If cscpath = "" Then
- 'Msgbox "未安装Microsoft .NET Framework 2.0及以上版本组件或是相关程序缺失!"
- WSH.Quit
- Else
- If not fso.FileExists(tmp&"\$CheckKeyLocked.exe") Then
- ws.Run cscpath&" /out:"""&tmp&"\$CheckKeyLocked.exe"" """&tmp&"\$CheckKeyLocked.cs""", 0, True
- End If
- End If
- Set oExec = ws.Exec(tmp&"\$CheckKeyLocked.exe")
- 'Msgbox oExec.StdOut.ReadAll '结果
- if oExec.StdOut.ReadAll = 0 Then
- ws.SendKeys"{NUMLOCK}"
- End If
- Function CreateCs
- Set cs = fso.CreateTextFile(tmp&"\$CheckKeyLocked.cs", 2)
- cs.Write _
- "using System;using System.Runtime.InteropServices;" & vbCrLf & _
- "public class CheckKeyLocked{" & vbCrLf & _
- " [DllImport(""user32.dll"", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]" & vbCrLf & _
- " public static extern ushort GetKeyState(int keyCode);" & vbCrLf & _
- " public static void Main(){" & vbCrLf & _
- " Console.WriteLine(((GetKeyState(0x90) & 0xffff) != 0?1:0));" & vbCrLf & _
- "}}"
- End Function
复制代码
|