本帖最后由 pcl_test 于 2017-4-12 22:47 编辑
- Set ws = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
- ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 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 '结果
-
- 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(""Caps:""+((GetKeyState(0x14) & 0xffff) != 0?1:0)+" & vbCrLf & _
- " "" Num:""+((GetKeyState(0x90) & 0xffff) != 0?1:0)+" & vbCrLf & _
- " "" Scroll:""+((GetKeyState(0x91) & 0xffff) != 0?1:0));" & vbCrLf & _
- "}}"
- End Function
复制代码
|