如何将图标修改脚本与脚本集成以切换代理?
How to integrate icon modification script with script to toggle proxy?
我指的是this post。就像原来的 post 我有一个代理 on/off 脚本。
我需要帮助的地方是将 "icon change script"(参见推荐 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
我对 Ansgar 回答的解读
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
然而这个returns这个错误
line 9
Variable is undefined: linkfile
800A01F4
MS VBScript Runtime Error
这并不太复杂。只需更改调用修改代理设置的函数的图标即可:
...
strSetting = WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
<b>lnkfile = WSHShell.SpecialFolders("Desktop") & "\your.lnk"
Set lnk = WSHShell.CreateShortcut(lnkfile)</b>
If strSetting = 1 Then
<b>WSHShell.IconLocation = "C:\path\to\enable.ico"</b>
NoProxy
Else
<b>WSHShell.IconLocation = "C:\path\to\disable.ico"</b>
Proxy
End If
<b>lnk.Save</b>
...
我指的是this post。就像原来的 post 我有一个代理 on/off 脚本。
我需要帮助的地方是将 "icon change script"(参见推荐 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
我对 Ansgar 回答的解读
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
然而这个returns这个错误
line 9
Variable is undefined: linkfile
800A01F4
MS VBScript Runtime Error
这并不太复杂。只需更改调用修改代理设置的函数的图标即可:
...
strSetting = WSHShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
<b>lnkfile = WSHShell.SpecialFolders("Desktop") & "\your.lnk"
Set lnk = WSHShell.CreateShortcut(lnkfile)</b>
If strSetting = 1 Then
<b>WSHShell.IconLocation = "C:\path\to\enable.ico"</b>
NoProxy
Else
<b>WSHShell.IconLocation = "C:\path\to\disable.ico"</b>
Proxy
End If
<b>lnk.Save</b>
...