[How-To] Powershell okienko – part 2

On 7. júla 2011, in How To, by admin

Enable / Disable Cisco AnyConnect Service + Set Proxy

$VPNService = Get-Service -DisplayName "Cisco AnyConnect Secure Mobility Agent"
$VPNName = $VPNService.DisplayName

if ( $VPNService.Status -ne "Running" )
{
Start-Service $VPNService.DisplayName
[Diagnostics.Process]::Start('C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe')
$VPNServiceStatus = (Get-Service -DisplayName $VPNName).Status
$Message = "$VPNServiceStatus `n"
}
elseif ( $VPNService.Status -ne "Stopped" )
{
Stop-Service $VPNService.DisplayName
Remove-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run 'Cisco AnyConnect Secure Mobility Agent for Windows'
$VPNServiceStatus = (Get-Service -DisplayName $VPNName).Status
$Message = "$VPNServiceStatus `n"
}
else
{
$Message = "Error: $LASTEXITCODE"
}
if ((Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyEnable | Select-Object ProxyEnable).ProxyEnable -eq 0)
{
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyEnable -Value 1
if ((Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyEnable | Select-Object ProxyEnable).ProxyEnable -eq 1)
{
$Message = $Message + "Status: Proxy Enabled`n"
}
}
if ((get-process iexplore -erroraction silentlycontinue) -eq $null)
{}
else
{
Stop-Process -Name iexplore -PassThru
$Message = $Message + "`n- Restarting a browser.`n"
$IEStartPage = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Internet Explorer\Main' -Name "Start Page" | Select-Object "Start Page").'Start Page'
$IEApp = New-Object -ComObject InternetExplorer.Application
$IEApp.Navigate("$IEStartPage")
$IEApp.Visible = $true
$Message = $Message + "`nHome page: " + $IEStartPage
}
Start-Sleep -seconds 2

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
[Microsoft.VisualBasic.Interaction]::MsgBox("Status: $Message","OkOnly,Information", "$VPNName by Mikso")

## Clean ##
$Message = $null
$IEApp = $null
$IEStartPage = $null
$VPNName = $null
$VPNService = $null
$VPNServiceStatus = $null

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Facebook
  • LinkedIn
  • Twitter
 

Leave a Reply

Free WordPress Theme

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Weboy