I am using a batch file for shrewsoft VPN connect-disconnect, my requirements are
1. I am doing a ping test, if ping is failed (internet failure or disconnection issues) then VPN should disconnect and the moment the Internet is ON and ping starts, VPN should connect automatically. So I am looking for an infinite ping loop which will connect or disconnect VPN
I want to run shrew VPN minimsed all the time or better in system tray
I am using this batch but when internet is off (connection failure) VPN disconnects, but I want code to reconnect the VPN once internet connection is reinstated.
#echo off
start /min "vpn" "C:\Program Files\ShrewSoft\VPN Client\ipsecc.exe" -r "testVPN.vpn" -u username -p password -a
:loop
echo testing IP address
ping 121.244.116.222 >nul || (
echo ping failure - disconnecting
taskkill /T /F /IM "ipsecc.exe"
)
timeout /t 30 /nobreak
goto :loop
I've built and open sourced an app to do exactly that, Check it out at https://github.com/CamW/shrew-reconnect if you're interested. You can build from code or just download the installer.
Hope that helps.
try using "expect" as described in https://sakhnik.com/2016/11/21/automatic-vpn.html
Maybe you can adopt this.
Related
We use kerberos authentication for connecting to our on-prem computing environment. I'd like to use visual studio code remote to do development directly on that server. Based on this section in the vscode remote documentation, it seems like it's possible to use password-based authentication, which works for me, but it would be nice if I could use existing kerberos authentication, instead of having to type my password every time I start up a vscode session.
I've tried searching through the documentation above, but I can't figure out if kerberos is supported. I would like to know if I should respectfully raise an issue on the issue tracker.
Update from March 2020.
I've used plain PuTTY (plink.exe) to connect from VsCode with kerberos using those simple steps.
Define a session inside PuTTY that opens a ssh shell to your remote machine, save it as remote.
Create "C:\Users\< youruser >\ssh.bat" with the contents below. You need echo to fool VsCode that it's OpenSSH client.
echo OpenSSH
SET mypath=%~dp0
powershell %mypath%ssh.ps1 %*
Create powershell script ssh.ps1 in the same folder with these contents:
$ArgArray = [System.Collections.ArrayList]$Args
$ind = $ArgArray.IndexOf("-F")
if ($ind -ge 0) {
$ArgArray.RemoveAt($ind)
$ArgArray.RemoveAt($ind)
}
Write-Host $ArgArray
& 'C:\Program Files\PuTTY\plink.exe' $ArgArray
Theoretically you can write it in batch language but I did not want to suffer.
Set "remote.SSH.path" setting in VsCode to your ssh.bat path.
Finally, add ssh host configuration in vscode and use session name as host:
Host remote
HostName remote
User <you ssh user>
My tweak on #Roman's batch script
#echo off
for %%x in (%*) do (
REM Handle -V
IF "%%x" == "-V" GOTO :version
REM Handle vscode remote as special for plink only
IF "%%x" == "remote" GOTO :plink
)
REM use the built in ssh by default
GOTO :default_ssh
:version
echo OpenSSH
GOTO :eof
:plink
powershell -NoProfile -ExecutionPolicy Bypass %~dp0ssh.ps1 %*
GOTO :eof
:default_ssh
ssh.exe %*
GOTO :eof
It allows you to only use plink for the vscode "remote" server name (I have my reasons), so everything behaves as normal unless you choose hostname remote
Currently this is not possible. There is a feature request about this which has been closed because it will not be implemented in the foreseeable future.
If you have a Kerberos-integrated SSH client for Windows it should work.
I'm not sure if the Microsoft openSSH for Windows 10 / Server 2019 is Kerberos-integrated or not. The one that comes with Git for Windows is not.
If you have a Kerberos-enabled version of PuTTY, you can make a small hack to use plink.
This broke with the June release
Create the file C:\Program Files\Microsoft VS Code\bin\ssh.bat
The file location will be different if VScode is installed in your home directory.
Put the following in the file. Adjust the plink path to your PuTTY directory.
"C:\Program Files (x86)\Centrify\Centrify PuTTY\plink.exe" -ssh -K %*
I wrote a very tiny wrapper for plink.exe.
(It just fakes version string with openssl's and remove unsupported '-T' option.)
I don't use with kerberos but it might help with settings like aviso's answer.
Please give it a try.
I would have commented on Roman answer, but it appears I do not have enough reputation.
I followed his steps, except that I put the plink.exe path for "remote.SSH.path" instead of the "ssh.bat". My path to plink.exe is simply "C:\Program Files\PuTTY\plink.exe".
I tried multiple things and to date, this is the only one that worked for me.
Another tweek for #Roman's and #Andy's ssh.bat script that worked for me; I specify several hosts to use plink.
#echo off
if %1 == -V GOTO :version
if %4 == "myFirst.remoteHost.address" GOTO :plink
if %4 == "mySecond.remoteHost.address" GOTO :plink
if %4 == "myThird.remoteHost.address" GOTO :plink
REM use the built in ssh by default
GOTO :default_ssh
:version
echo OpenSSH
GOTO :eof
:plink
powershell -NoProfile -ExecutionPolicy Bypass %~dp0ssh.ps1 %*
GOTO :eof
:default_ssh
ssh.exe %*
GOTO :eof
i am trying to write a batch script to automate some task and ecocide next command or output according to the response or output from previous command.
adb connect %IP%:5555
if errorlevel 1 (
echo Not Able To connect With Provided Ip Address
goto getip
) else (
echo Connected Over Wifi
goto menu2
)
But it's not working because i think in every case error level is 0
as device connected successfully or not output is same "Connected Over wifi".
Generaly when we enter command adb connect <IP> the outputs are
1)connection is successful output is
connected to 192.168.10.13:5555
2) when android device is in wifi lan and enterd "ip" is correct but "5555" port is not open then output is
unable to connect to 192.168.10.13:5555: cannot connect to 192.168.10.13:5555: No connection could be made because the target machine actively refused it. (10061)
3)when laptops wifi is off
unable to connect to 192.168.10.13:5555: cannot connect to 192.168.10.13:5555: A socket operation was attempted to an unreachable host. (10065)
4) when android's wifi is off
unable to connect to 192.168.10.2:5555: cannot connect to 192.168.10.2:5555: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
i want to define only two case "connection Successful" or "Not Successful"
what should i do to automate task according to the adb over wifi connection setup. please help
You can pipe the output of adb to FIND and search for a telltale token that indicates success or failure, like "unable to" or "connected to".
#echo off & setlocal
set IP=192.168.10.13:5555
adb connect %IP% | find /i "connected to" >nul
if errorlevel 1 (
echo Not successful
) else (
echo Successful
)
im tyring to write a bat file to ensure i am logged into a remote pc by a certain time so that some other auto processes can run on that pc.
heres where i am
cmdkey /generic:TERMSRV/server /user:**** /pass:*****
mstsc /v:server
ping 8.8.8.8 -n 10
taskkill /im mstsc.exe /f
problem im facing is that after lauching the remote pc is doesnt move to the ping until i manually close the cmd window
seems really simple, im just blanking. and if i could schedule it and save my creds in task scheduler i would, current gp doesnt allow me to.
thanks in advance.
You can call mstsc with start to run mstsc independently of the batch script.
start "" mstsc /v:server
The WIA service(stisvc) on my friend's win8 computer quite often stops working properly. When stopping/restarting from MMC it returns error "Service didn't respond in time", so I kill it from the Task Manager and then start it from within MMC.
Is there a way to make a script to kill the stisvc and then start it again?
This works for you (You should have Admin rights on your system):
#echo off
taskkill /F /IM svchost.exe /FI "SERVICES eq stisvc"
sc query stisvc | find /i "running"
if errorlevel 1 (
echo Not running...
echo Starting Windows Image Acquisition (WIA) service....
net start stisvc
)
Dependencies:
Windows Image Acquisition (WIA) will not start, if the following services are stopped or disabled:
Remote Procedure Call (RPC)
Shell Hardware Detection
I am trying to install SQL Server 2008 and during the pre requisite check its always fails on
WMI service "Failed".
I went to the event viewer and found this error in there.
"Failed to Initialize WMI Core or Provider SubSystem or Event SubSystem with error number 0x80040154. This could be due to a badly installed version of WMI, WMI repository upgrade failure, insufficient disk space or insufficient memory."
I know there is a lot of space available in my hard drive. Also i tried a few things after googling like WMIFIX.bat file. The file ran fine but did not fix the problem.
Has anyone had this problem? If so do you have a solution?
if you have a domain so Run this Command with administrator Privilege
you can copy this Command and Past in Notbat with .bat extention. and run them.
Rundll32 setupapi,InstallHinfSection Ndi-Steelhead 132 %windir%\inf\netrass.inf
Netsh firewall reset
sc config SharedAccess obj= LocalSystem password= "" type= interact type= own
sc config RpcSs obj= LocalSystem password= "" type= interact type= own
sc config RpcLocator obj= LocalSystem password= "" type= interact type= own
sc config winmgmt obj= LocalSystem password= "" type= interact type= own
sc config Wmi obj= LocalSystem password= "" type= interact type= own
net start winmgmt
net start Wmi
net start RpcSs
net start RpcLocator
net start WmiApSrv
netsh firewall add portopening TCP 135 "Open Port 135"
netsh firewall add portopening TCP 445 "Open Port 445"
netsh firewall add portopening TCP 139 "Open Port 139"
netsh firewall set opmode mode=DISABLE
shutdown /r
if your problem did not solve you Can execute this Command in Command Prompt with admin privilege.. you can just copy and paste them in notepad and rename it with .bat extention an run the file..
net stop winmgmt
C:
cd %systemroot%\system32\wbem
rd /S /Q repository
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
mofcomp cimwin32.mof
mofcomp cimwin32.mfl
mofcomp rsop.mof
mofcomp rsop.mfl
for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
for /f %%s in ('dir /b *.mof') do mofcomp %%s
for /f %%s in ('dir /b *.mfl') do mofcomp %%s
echo DONE reboot
pause
just it and have a good day !!!!!
Run the WMI Diag Utility. Here are the instructions how to do this:
Download WMIDiag.
To run the WMIDiag tool:
1. Open a command prompt window.
(Use "Run As Administrator", if applies to your Operating System version)
2. Navigate to the wmidiag folder that was created when you ran Wmidiag.exe.
3. Type cscript wmidiag.vbs.
View what the output of that is and post what it says. That'll give you a better indication of what's happening.
Here is a reference for the above instructions.
I faced this issue when I tried to install SQL Express
For me, following steps worked out which I referred from http://mikeymurph.me/fix-wmi-service-error/
Run the following in Powershell in Administrator mode
PS C:\Windows\system32> winmgmt /verifyrepository
WMI repository verification failed
Error code: 0x80041002
Facility: WMI
Description: Not found
PS C:\Windows\system32> Winmgmt /resetrepository
WMI repository has been reset
Now try to install SQL Server again.