如何将图标修改脚本与脚本集成到切换代理?

时间:2016-01-05 21:52:09

标签: vbscript icons

我指的是this post。就像在原始帖子中我有一个代理开/关脚本。

我需要帮助的地方是包含"图标更改脚本" (参见推荐帖子)到我已经存在的脚本中,即哪里

Set sh = CreateObject("WScript.Shell")

lnkfile = sh.SpecialFolders("Desktop") & "\your.lnk"

Set lnk = sh.CreateShortcut(lnkfile)
If lnk.IconLocation = "C:\path\to\some.ico" Then
  sh.IconLocation = "C:\path\to\.ico"
Else
  sh.IconLocation = "C:\path\to\some.ico"
End If
lnk.Save

适合

Option Explicit 
Dim WSHShell, strSetting
Set WSHShell = CreateObject("WScript.Shell")

'Determine current proxy setting and toggle to oppisite setting
strSetting = WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If strSetting = 1 Then 
  NoProxy
Else
  Proxy
End If

'Subroutine to Toggle Proxy Setting to ON
Sub Proxy
  WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
  WScript.Echo "Proxy is On"
End Sub

'Subroutine to Toggle Proxy Setting to OFF
Sub NoProxy 
  WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
  WScript.Echo "Proxy is Off"
End Sub

我对你答案的解释安斯加

Option Explicit 
Dim WSHShell, strSetting
Set WSHShell = WScript.CreateObject("WScript.Shell")

'Determine current proxy setting and toggle to oppisite setting
strSetting = WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")

lnkfile = WSHShell.SpecialFolders("Desktop") & "\proxypal.lnk"
Set lnk = WSHShell.CreateShortcut(lnkfile)
If strSetting = 1 Then
  WSHShell.IconLocation = "C:\path\to\on.ico"
  NoProxy
Else
  WSHShell.IconLocation = "C:\path\to\off.ico"
  Proxy
End If
lnk.Save

'Subroutine to Toggle Proxy Setting to ON
Sub Proxy 
  WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
  Wscript.echo "Proxy is On"
End Sub

'Subroutine to Toggle Proxy Setting to OFF
Sub NoProxy 
  WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
  Wscript.echo "Proxy is Off"
End Sub

然而,这会返回此错误

  

第9行   变量未定义:linkfile
  800A01F4
  MS VBScript运行时错误

1 个答案:

答案 0 :(得分:0)

这不是太复杂。只需更改调用修改代理设置的功能的图标:

...
strSetting = WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
lnkfile = WSHShell.SpecialFolders("Desktop") & "\your.lnk"
Set lnk = WSHShell.CreateShortcut(lnkfile)
If strSetting = 1 Then
  WSHShell.IconLocation = "C:\path\to\enable.ico"
  NoProxy
Else
  WSHShell.IconLocation = "C:\path\to\disable.ico"
  Proxy
End If
lnk.Save
...