Jump to content

Recommended Posts

Posted

So this is my first attempt at a UDF so apologies if it is terrible or if this has been posted before.

I've seen this question asked a few times and as of yet, I dont think there's a way to do this in Autoit3, so i've had to implement the use of an externally made program.

This requires the presence of the nircmd.exe tool in the C:\windows folder, this may be obtained here:

http://www.nirsoft.net/utils/nircmd.html

Once this has been inserted, you should be able to use the UDF:

SetVol

#include <Process.au3>

;-----------------------------------------------------------------------
;Syntax: _SetSysVol(*Percentage of Total Volume to set*)
;-----------------------------------------------------------------------

Func _SetSysVol($sPercent)
While 1
If $sPercent > 100 Then
MsgBox(0, "Error", "Percentage Value Exceeded")
ExitLoop
EndIf
If Not FileExists("C:\Windows\nircmd.exe") Then
MsgBox(0, "Error", "Nircmd.exe is not present in the Windows Directory")
ExitLoop
EndIf
Global $sDecimal = ($sPercent * 0.01)
Global $newVol = ($sDecimal * 65535)
If StringIsDigit($newVol) Then
Global $sCommand = "nircmd setsysvolume " & $newVol
Global $run = _RunDos($sCommand)
ExitLoop
ElseIf StringInStr($newVol, ".") <> 0 Then
$newVol1 = StringSplit($newVol, ".")
Global $sCommand1 = "nircmd setsysvolume " & $newVol1[1]
Global $run1 = _RunDos($sCommand1)
ExitLoop
Else
MsgBox(0, "", "Percentage is not Valid")
ExitLoop
EndIf
WEnd
EndFunc   ;==>_setSysVol

Example

#include <SetVol.au3>
_setSysVol(40)

Again, I am but a mere novice in Autoit (Hence the name) and there are probably neater ways of doing this, but it works for me :)

note: I do not own nircmd, all credit goes to the Nirsoft team for this utility.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...