Page 1 of 1

powershell to bat

Posted: 30 Sep 2019 17:28
by robkof97
someone who can convert this powershell to batch?

$p1 = [System.Windows.Forms.Cursor]::Position
Start-Sleep -Seconds 2
$p2 = [System.Windows.Forms.Cursor]::Position
if($p1.X -ne $p2.X -and $p1.Y -ne $p2.Y) {
Stop-Service -Name "wifi driver"
Start-Sleep -Seconds 60
Start-Service -Name "wifi driver"

Re: powershell to bat

Posted: 01 Oct 2019 04:47
by jfl
Use PowerShell's get-service to get the correspondence between the one-word service name used by the net.exe and sc.exe commands, and the more descriptive name used by PowerShell service management commands.

Then simply use 'net start NAME' or 'net stop NAME' in your batch to start or stop the service.

The other part of your script about Windows forms is impossible to do in pure batch.
You'll need an external program, or a dual-language script, with VBS or JavaScript to manipulate system objects.