Author Topic: Hal pc control  (Read 16560 times)

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« on: March 01, 2010, 09:06:37 pm »
I would like to explore the possibilities of being able to control your pc via voice through the use of Hal, is it possible? If so Could anyone point me in the right direction. Here are a few things I would like to be able to do. Could a plug-in work for any one of these?

1: control system volume
2: control a program like winamp, to (stop, pause, play, next, close, etc.)
3: shut down system
4: restart system
5: on demand go to a specified web address, is a plug-in made for this already? I thought I might have seen one a while back but can't seem to find it.
6: give stats on our system, like cpu usage, memory usage, and maybe upload and download speeds.  

most of these can be done using Microsoft speech, but I think it would be great if we could do all these within our Hals.

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #1 on: March 02, 2010, 12:42:39 pm »
quote:
Originally posted by sybershot

I would like to explore the possibilities of being able to control your pc via voice through the use of Hal, is it possible? If so Could anyone point me in the right direction. Here are a few things I would like to be able to do. Could a plug-in work for any one of these?

1: control system volume
2: control a program like winamp, to (stop, pause, play, next, close, etc.)
3: shut down system
4: restart system
5: on demand go to a specified web address, is a plug-in made for this already? I thought I might have seen one a while back but can't seem to find it.
6: give stats on our system, like cpu usage, memory usage, and maybe upload and download speeds.  

most of these can be done using Microsoft speech, but I think it would be great if we could do all these within our Hals.



Hi sybershot.

UPDATED: TUESDAY, MARCH 2 2010, 12:04PM

I wrote this script for HAL that gives CPU usage percent and hard disk free space info. I tried to get it to function in a plugin but it doesn't seem to function as a plugin.

but it does work when directly placed into the HAL brain which is kind of weird but at least it works.

you'll have to place the script into the Hal Brain directly below this area: Rem PLUGIN: POST-PROCESS

here is the code:
Code: [Select]
'Constants for drive types
Const Unknown = 0
Const Removable = 1
Const Fixed = 2
Const Remote = 3
Const CDROM = 4
Const RAMDisk = 5
Const strComputer = "."

'THIS WILL GET CPU USAGE INFORMATION
If InStr(1, InputString, "processor usage", 1) > 0 Or InStr(1, InputString, "processor time", 1) > 0 Or _
InStr(1, InputString, "cpu time", 1) > 0 Or InStr(1, InputString, "cpu usage", 1) > 0 Then
Set oWsh = CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\rootCIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
UltraHal = " Processor usage is " & objItem.PercentProcessorTime & "  %"
Next
End If

'THIS WILL GET AVAILABLE PHYSICAL MEMORY INFORMATION
If InStr(1, InputString, "physical memory", 1) > 0 Then
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "\rootcimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colSettings
UltraHal = " Available Physical Memory: " & _
        objOperatingSystem.FreePhysicalMemory & " MB "
Next
End If

'THIS WILL GET TOTAL PHYSICAL MEMORY INFORMATION
If InStr(1, InputString, "physical memory", 1) > 0 Then
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer In colSettings
UltraHal = UltraHal & " Total Physical Memory: " & _
        objComputer.TotalPhysicalMemory & " MB "
Next
End If

'THIS WILL GET CPU CURRENT SPEED INFORMATION
If InStr(1, InputString, "processor usage", 1) > 0 Or InStr(1, InputString, "processor time", 1) > 0 Or _
InStr(1, InputString, "cpu time", 1) > 0 Or InStr(1, InputString, "cpu usage", 1) > 0 Or InStr(1, InputString, "clock speed", 1) > 0 Then
Set oWsh = CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\rootCIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem In colItems
UltraHal = UltraHal & " Current Clock Speed: " & objItem.CurrentClockSpeed & " MHz"
Next
End If

'THIS WILL GET THE HARD DISK SPACE INFORMATION
If InStr(1, InputString, "hard disk space", 1) > 0 Or InStr(1, InputString, "harddisk space", 1) > 0 Or _
InStr(1, InputString, "free space", 1) > 0 Or InStr(1, InputString, "storage space", 1) > 0 Then
Set oFs = CreateObject("Scripting.FileSystemObject")
         Set oDrives = oFs.Drives
          For Each oDrive In oDrives
         Select Case oDrive.DriveType
      Case Fixed
GetFreeSpaceReport = GetFreeSpaceReport & oDrive.DriveLetter & ": " & Round(oDrive.FreeSpace/(1024*1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace/oDrive.TotalSize),2) & "%)" & vbcrlf
End Select
Next
Str = GetFreeSpaceReport
UltraHal = Str
End If

'THIS WILL ALLOW A USER TO SHUT DOWN THE COMPUTER
'THIS SCRIPT WILL WORK WELL WITH ASSISTANT BUT MAY CAUSE
'PROBLEMS WITH AIM BOT USERS BECAUSE ANYONE USING AIM
'COULD SHUT DOWN YOUR COMPUTER ON COMMAND.
If InStr(1, InputString, "shut down computer", 1) > 0 Or InStr(1, InputString, "shut down system", 1) > 0 Then
Set oWshX = CreateObject("WScript.Shell")
Set oWshSysEnvX = oWshX.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnvX("COMPUTERNAME")
    strShutdown = "shutdown -s -t 0 -f -m \" & GetCurrentComputerName
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run strShutdown
End If


Have fun and I will try to work on the rest of your requests when I get time.

this code will come default in the Quantum Child Brain I am developing but won't be done for a while.
Jerry[8D]
« Last Edit: March 02, 2010, 03:04:33 pm by onthecuttingedge2005 »

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #2 on: March 02, 2010, 01:04:24 pm »
you can also use this plugin I designed called WebSurfer, it allows HAL more flexibility in opening up Web Maps, Pictures, Sites. you can peer into the plugin to see how it functions to give you a better idea of how it works.

here is the plugin web surfer:

Download Attachment: WebSurf.uhp
5.81 KB

you can say things like; please open up www.zabaware.com and the site will open, you can say find a picture or a portrait of an eagle and it will load a page with pictures of an eagle and or eagles.
you can also say find a map on new york and it will open a map of new york and so on.

place the plugin in your Ultra Hal Assistant 6 folder and then choose the plugin from your brain options.

Jerry[8D]

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #3 on: March 02, 2010, 04:23:28 pm »
onthecuttingedge2005 Thanks a million, "Quantum Child Brain"  That is a great name, it grabs my attention and got me curious. Let me know if you need any help testing with different operating systems. I know have 3 computers with 3 different operating systems. xp home 32 bit, vista home 64bit, and windows7 home 64bit.

Any other coder needing testing on any of the above operating systems let me know, I'm more than glad to help.

Thanks again sincerely Sybershot

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #4 on: March 03, 2010, 02:10:35 pm »
onthecuttingedge2005 I created a second default brain file today named Trinity to try your
quote:
UPDATED: TUESDAY, MARCH 2 2010, 12:04PM
. It was the first time I ever did that, and it was very simple. in my new brain under "Rem PLUGIN: POST-PROCESS" and after all of Roberts comments for that area I placed your code.

Here are the results

Processor usage is = error
HalScript Error- 2147217375 on line 303 in column 0:

Available Physical Memory = error
HalScript Error- 2147217375 on line 312 in column 0:

Total Physical Memory = error
HalScript Error- 2147217375 on line 312 in column 0:

current clock speed = error
HalScript Error- 2147217375 on line 338 in column 0:

Get Free Space Report
C:177146MB free (60%) F:425645MB free (89.37%) G: 153447MB free (50.28%)

just for a reference of accuracy my system shows this info
C: Total Size 288GB, free space 172GB
F: Total Size 465GB, free space 415GB
G: Total Size 298GB, free space 149GB

shut down computer
popped up 3 DOS windows and they closed within a few seconds, and system did not shut down

Tested on a gateway FX Laptop with vista 64bit home premium and two WD Passport usb Portable Hard Drives

If and when you have the time could you please look into this for me?
If you want the DBG file let me know

I have not tried the WebSurf.uhp yet, I will later tonight if I have time.
EDIT: Just tried WebSurf.uhp and works perfect, Thanks you
EDIT2: been looking at the code and Win32 looks to be a possible culprit, I will try Win64 and post results
EDIT3: just changing 32 to 64 on all paths/files, did not work. I found out with other plug-ins that paths are different in 64bit[:(] is this maybe the issue here?
« Last Edit: March 03, 2010, 04:47:19 pm by sybershot »

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #5 on: March 03, 2010, 06:10:45 pm »
quote:
Originally posted by sybershot

onthecuttingedge2005 I created a second default brain file today named Trinity to try your
quote:
UPDATED: TUESDAY, MARCH 2 2010, 12:04PM
. It was the first time I ever did that, and it was very simple. in my new brain under "Rem PLUGIN: POST-PROCESS" and after all of Roberts comments for that area I placed your code.

Here are the results

Processor usage is = error
HalScript Error- 2147217375 on line 303 in column 0:

Available Physical Memory = error
HalScript Error- 2147217375 on line 312 in column 0:

Total Physical Memory = error
HalScript Error- 2147217375 on line 312 in column 0:

current clock speed = error
HalScript Error- 2147217375 on line 338 in column 0:

Get Free Space Report
C:177146MB free (60%) F:425645MB free (89.37%) G: 153447MB free (50.28%)

just for a reference of accuracy my system shows this info
C: Total Size 288GB, free space 172GB
F: Total Size 465GB, free space 415GB
G: Total Size 298GB, free space 149GB

shut down computer
popped up 3 DOS windows and they closed within a few seconds, and system did not shut down

Tested on a gateway FX Laptop with vista 64bit home premium and two WD Passport usb Portable Hard Drives

If and when you have the time could you please look into this for me?
If you want the DBG file let me know

I have not tried the WebSurf.uhp yet, I will later tonight if I have time.
EDIT: Just tried WebSurf.uhp and works perfect, Thanks you
EDIT2: been looking at the code and Win32 looks to be a possible culprit, I will try Win64 and post results
EDIT3: just changing 32 to 64 on all paths/files, did not work. I found out with other plug-ins that paths are different in 64bit[:(] is this maybe the issue here?



you are right, the codes I wrote are for a 32 bit operating system not 64 bit, since I don't have a 64 bit system I will have to wait till I get one to rewrite the codes to work for you, sorry.

do you have a 32 bit system you can try it on? I know it works flawlessly on my 32 O/S

thanks for informing of your error so I can make a note to 64 bit users.

Jerry

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #6 on: March 04, 2010, 01:18:11 am »
yes I have xp home 32bit on a desktop, I will test it on that one and get back to you.

quote:
since I don't have a 64 bit system I will have to wait till I get one to rewrite the codes to work for you, sorry.
 

I will try and see what I can do, Maybe I'll get lucky an figure it out. this way 32 and 64 bit users can enjoy this. I will keep you posted.

quote:
thanks for informing of your error so I can make a note to 64 bit users.

your welcome, anytime

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #7 on: March 05, 2010, 09:25:37 am »
I asked for help with this on a vb forum, I got a reply saying that it is not a 32-bit vs 64-bit issue, but is user permissions and potentially the information provided by the motherboard too.
he suggested a couple of things and An alternative to get the information via API's
http://www.vbforums.com/showthread.php?t=606023 is where the thread can be located

I will test on xp 32 home premium service pack 3 this weekend, and let you know
« Last Edit: March 05, 2010, 03:02:14 pm by sybershot »

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #8 on: March 05, 2010, 08:34:50 pm »
onthecuttingedge2005 I am sorry  I went ahead and posted your code else where, I was not really thinking straight, alot has been going on here. I should of asked first. again sorry, I will not do it again. sincerely Sybershot

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #9 on: March 08, 2010, 09:35:11 pm »
I tested on my windows XP home premium32 bit over the weekend and here are the results

Processor usage is = error
HalScript Error- 2147217375 on line 301 in column 0:

Available Physical Memory = error
HalScript Error- 2147217375 on line 310 in column 0:

Total Physical Memory = error
HalScript Error- 2147217375 on line 310 in column 0:

current clock speed = error
HalScript Error- 2147217375 on line 336 in column 0:

Get Free Space Report
C:4576MB free (5.17%) D: 470MB free (6.89%)

shut down system
a few dos boxes and a request from my firewall for Windows Remote Shutdown Tool to get access to the internet

I allowed shutdown tool access and the system did not shut down, then I tried with out letting it have access and it still did not shut down

if you want/need any further testing any either os let me know. I will be glad to help

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #10 on: March 09, 2010, 09:07:34 am »
quote:
Originally posted by sybershot

I tested on my windows XP home premium32 bit over the weekend and here are the results

Processor usage is = error
HalScript Error- 2147217375 on line 301 in column 0:

Available Physical Memory = error
HalScript Error- 2147217375 on line 310 in column 0:

Total Physical Memory = error
HalScript Error- 2147217375 on line 310 in column 0:

current clock speed = error
HalScript Error- 2147217375 on line 336 in column 0:

Get Free Space Report
C:4576MB free (5.17%) D: 470MB free (6.89%)

shut down system
a few dos boxes and a request from my firewall for Windows Remote Shutdown Tool to get access to the internet

I allowed shutdown tool access and the system did not shut down, then I tried with out letting it have access and it still did not shut down

if you want/need any further testing any either os let me know. I will be glad to help




Hi sybershot.

could you send me a copy of the brain you are using with the code inserted the way you had it so I can see if it runs on my system.

I am not sure yet but it sounds like your administration security is somehow messing up the script. are you running it as a full administrator?

Jerry

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #11 on: March 10, 2010, 03:38:04 am »
quote:
are you running it as a full administrator

yes (Compaq-Owner Computer administrator) displays under User Account, with no other users, guest account is turned off.
if helps my system is a Hp Compaq Presario model sr1810nx windows xp
quote:
could you send me a copy of the brain you are using

Download Attachment: trail2.uhp
139.53 KB

Edit: I thought maybe my anti virus (avast) and firewall (zone alarm) might have been a culprit, I shut them both down and i still got the same results
« Last Edit: March 10, 2010, 03:57:44 am by sybershot »

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #12 on: March 15, 2010, 02:16:38 am »
Hi Sybershot.

would you create a file called Tester.vbs onto your desktop and then right click on the vbs file and choose edit, then copy and paste this code into the vbs file then save it, click on it to run the code.



does the code run? it should give you your computers name via a message box.

Code: [Select]
Set oWsh = CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
MsgBox GetCurrentComputerName

if you get an error then I think it is related to Wscript and I will investigate further whether Wscript is causing your errors here.

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Hal pc control
« Reply #13 on: March 15, 2010, 09:02:13 am »
I got a window that opened Stating my computers name "SYBERSHOT-PC"

onthecuttingedge2005

  • Guest
Hal pc control
« Reply #14 on: March 15, 2010, 12:23:40 pm »
quote:
Originally posted by sybershot

I got a window that opened Stating my computers name "SYBERSHOT-PC"



Hi Sybershot.

now could you do the same thing with this code, add it to your tester.vbs file and then see if it runs on your system.

Code: [Select]
'Constants for drive types
Const Unknown = 0
Const Removable = 1
Const Fixed = 2
Const Remote = 3
Const CDROM = 4
Const RAMDisk = 5
Const strComputer = "."

'THIS WILL GET CPU USAGE INFORMATION

Set oWsh = CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\rootCIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
MsgBox " Processor usage is " & objItem.PercentProcessorTime & "  %"
Next


'THIS WILL GET AVAILABLE PHYSICAL MEMORY INFORMATION

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\" & strComputer & "\rootcimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colSettings
MsgBox " Available Physical Memory: " & _
        objOperatingSystem.FreePhysicalMemory & " MB "
Next


'THIS WILL GET TOTAL PHYSICAL MEMORY INFORMATION

Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer In colSettings
MsgBox " Total Physical Memory: " & _
        objComputer.TotalPhysicalMemory /10241024+1 & "MB"
Next


'THIS WILL GET CPU CURRENT SPEED INFORMATION

Set oWsh = CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\rootCIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem In colItems
MsgBox " Current Clock Speed: " & objItem.CurrentClockSpeed & " MHz"
Next


'THIS WILL GET THE HARD DISK SPACE INFORMATION

Set oFs = CreateObject("Scripting.FileSystemObject")
         Set oDrives = oFs.Drives
          For Each oDrive In oDrives
         Select Case oDrive.DriveType
      Case Fixed
GetFreeSpaceReport = GetFreeSpaceReport & oDrive.DriveLetter & ": " & Round(oDrive.FreeSpace/(1024*1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace/oDrive.TotalSize),2) & "%)"
End Select
Next
MsgBox GetFreeSpaceReport



'THIS WILL ALLOW A USER TO SHUT DOWN THE COMPUTER
'THIS SCRIPT WILL WORK WELL WITH ASSISTANT BUT MAY CAUSE
'PROBLEMS WITH AIM BOT USERS BECAUSE ANYONE USING AIM
'COULD SHUT DOWN YOUR COMPUTER ON COMMAND.

'Set oWshX = CreateObject("WScript.Shell")
'Set oWshSysEnvX = oWshX.Environment("PROCESS")
'GetCurrentComputerName = oWshSysEnvX("COMPUTERNAME")
    'strShutdown = "shutdown -s -t 0 -f -m \" & GetCurrentComputerName
    'Set objShell = CreateObject("WScript.Shell")
    'objShell.Run strShutdown



you should get several message boxes showing properties of your computer's memory and CPU

Thanks.
Jerry