powershell to bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Posts: 1
Joined: 30 Sep 2019 17:20

powershell to bat

#1 Post by robkof97 » 30 Sep 2019 17:28

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"

Posts: 176
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France

Re: powershell to bat

#2 Post by jfl » 01 Oct 2019 04:47

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.

Post Reply