'''NetShare_Power.VBS by baomaboy
'''支持参数 i 开启,u 关闭,如:"wscript.exe NetShare_Power.VBS i"
Dim WshSHell
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set Args = WScript.Arguments
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,"SYSTEM\CurrentControlSet\Services\lanmanserver\Linkage","Route", arrValues
For Each strValue In arrValues
DuoString=DuoString&strValue
Next
NetShareState = InStr(DuoString,"{86522D76-E90D-4C8B-957E-FA3603378EA5}")
if Args.Count=0 then
intAnswer = MsgBox("【是】将开启“Microsoft 网络的文件和打印机共享”项,"&Chr(10)&Chr(10)&"【否】将关闭“Microsoft 网络的文件和打印机共享”项。", vbQuestion + vbYesNoCancel, "开/关Microsoft 网络的文件和打印机共享” - baomaboy")
If intAnswer = vbYes and NetShareState = 0 Then
Call Exc
end if
If intAnswer = vbNo and NetShareState <> 0 Then
Call Exc
end if
elseif LCase(Args(0)) = "i" and NetShareState = 0 then
Call Exc
elseif LCase(Args(0)) = "u" and NetShareState <> 0 then
Call Exc
end if
Sub Exc()
WshSHell.Run "control.exe ncpa.cpl"
WScript.Sleep 1000
WshSHell.SendKeys "{DOWN}{UP}"
WScript.Sleep 1000
WshSHell.SendKeys "%FR"
WScript.Sleep 1000
WshSHell.SendKeys "{DOWN}{ }"
WScript.Sleep 1000
WshSHell.SendKeys "{TAB 5}{Enter}"
WScript.Sleep 3000
WshSHell.SendKeys "%FC"
End Sub
Set WshSHell = Nothing
WScript.Quit |
|