'控制某个进程音量（XP系统为整个系统）
'SetVolumePId(ByVal PId as ULong ,音量  ) as Long '
'成功返回 1
'dwVolume
'新的音量设置。 低位字包含左声道音量设置，高位字包含右声道设置。 值0xFFFF表示满量程，值0x0000为静音。
'如果设备不支持左右音量控制，则dwVolume的低位字指定音量级别，忽略高位字。
   

Function SetVolumePId(ByVal PId As ULong, ByVal V As Long) As Long '
   Dim As HANDLE  hProcess,DohThread,lResult
   Dim lpThreadAttributes As SECURITY_ATTRIBUTES
   Dim As UInteger  pfnStartAddr
   Dim By() As UByte, tmp_Addr As LPVOID
   ChrToByte("55 89 E5 83 EC 04 53 56 57 C7 45 FC 00 00 00 00 BB E8 52 26 71 FF 75 08 6A 00 FF D3 8B 45 FC 5F 5E 5B 89 EC 5D C2 04 00 90 ", by())
   hProcess = OpenProcess(&H1F0FFF, False, PId)
   If hProcess <> 0 Then
      tmp_Addr = VirtualAllocEx(hProcess, Null, Ubound(by) + 1, MEM_COMMIT Or MEM_RESERVE, PAGE_EXECUTE) '申请内存空间
      If tmp_Addr <> 0 Then
         pfnStartAddr = DLL_Fun_Add("winmm.dll", "waveOutSetVolume")
         MemCpy @by(17), @pfnStartAddr, 4
         If WriteProcessMemory(hProcess, tmp_Addr, @by(0), Ubound(by) + 1, 0) > 0 Then
            DohThread = CreateRemoteThread(hProcess, @lpThreadAttributes, Null, tmp_Addr, Cast(LPVOID, V), 0, 0) '运行远程线程
            WaitForSingleObject DohThread, 5000
            CloseHandle DohThread '关闭线程句柄
            VirtualFreeEx(hProcess, tmp_Addr, Null, &H8000&)  '清理内存
            Function = 1
         End If
      End If
      CloseHandle hProcess '关闭
   End If
   
End Function

'Project1.exe+5ED0 - 55                    - push ebp
'Project1.exe+5ED1 - 89 E5                 - mov ebp,esp
'Project1.exe+5ED3 - 83 EC 04              - Sub esp,04
'Project1.exe+5ED6 - 53                    - push ebx
'Project1.exe+5ED7 - 56                    - push esi
'Project1.exe+5ED8 - 57                    - push edi
'Project1.exe+5ED9 - C7 45 FC 00000000     - mov [ebp-04],00000000
'Project1.exe+5EE0 - BB E8522671           - mov ebx,WINMM.waveOutGetVolume
'Project1.exe+5EE5 - FF 75 08              - push [ebp+08]
'Project1.exe+5EE8 - 6A 00                 - push 00
'Project1.exe+5EEA - FF D3                 - Call ebx
'Project1.exe+5EEC - 8B 45 FC              - mov eax,[ebp-04]
'Project1.exe+5EEF - 5F                    - pop edi
'Project1.exe+5EF0 - 5E                    - pop esi
'Project1.exe+5EF1 - 5B                    - pop ebx
'Project1.exe+5EF2 - 89 EC                 - mov esp,ebp
'Project1.exe+5EF4 - 5D                    - pop ebp
'Project1.exe+5EF5 - C2 0400               - ret 0004