Automate Skype Status with PowerShell
One of the big problems I have with Skype is its lack of a scheduling feature. I have a Skype dual phone which will ring when someone calls me on Skype, but I don’t want the phone ringing in the middle of the night because someone from another time zone sees my status as “Online” decides to call. I use Skype frequently for work with virtual teams, so I can’t just turn it off because I don’t want to forget to turn it back on. My status should show as “Away” when I haven’t used my PC for a while, but this isn’t always consistent and it doesn’t cater for insomnia-induced tinkering on the pc.
Ideally, Skype would have a feature to set “Opening Hours” on your account—I only want to show up as available between 8am and 8pm. I bought the Pamela extra which does some scheduling, but you can set only one event per day—ie. I can set it to go offline at 8pm, but not to turn back on at 8am.
Since Skype offers a client API component, it is possible to create a scheduler to set your online status at different times using Windows Scheduler and a scripting tool. I wrote this before in VBScript, but this being the dawn of Windows 7 with pre-installed PowerShell, I rewrote it as a PowerShell script.
If you are on XP or Vista and haven’t installed PowerShell, you will need to do this before you can run these scripts. Installation instructions for PowerShell are here. You will also need to set the execution policy. You can find instructions for this here. I am running XP.
I hope this helps . . .
Step 1: Install the Skype4Com component
Skype still uses a COM component called Skype4Com which needs to be downloaded and registered on your local PC. The component can be found at https://developer.skype.com/Download. I’m using version 1.0.32, but you can probably use a later version.
Download the component, extract it to a directory (ie. "c:\skype\") and type the following into the Run window:
regsvr32 c:\skype\Skype4COM-1.0.32\Skype4COM.dll
Make sure the directory point to the actual dll file to you downloaded. You should get a response that it was registered successfully:
Step 2: Write the PowerShell script
Now, write the PowerShell script to use the component. I’ve created two scripts—one sets my status to “Online”, the other sets it to “Offline”. You can probably create a single script with a parameter passed in if you wish (but I couldn’t be bothered to figure out how to do this).
In the script, you have to create the Skype object, identify the current user, and change the status.
In my first script, I use the following code:
1: #Create Skype Object
2: $skype = New-Object -COM "Skype4COM.Skype"
3:
4: #Get the logged in user
5: $currentUser = $skype.CurrentUserProfile
6:
7: #Get the Status vars
8: $onlineStatus = $skype.Convert.TextToUserStatus("ONLINE")
9:
10: #Now Change your status
11: $skype.ChangeUserStatus($onlineStatus)
The main Skype call here is the “ChangeUserStatus” method. I named the first script “SetSkypeStatus_on.ps1”.
The second script is almost identical, but it sets the status to “Offline”:
1: #Create Skype Object
2: $skype = New-Object -COM "Skype4COM.Skype"
3:
4: #Get the logged in user
5: $currentUser = $skype.CurrentUserProfile
6:
7: #Get the Status vars
8: $offlineStatus = $skype.Convert.TextToUserStatus("OFFLINE")
9:
10: #Now Change your status
11: $skype.ChangeUserStatus($offlineStatus)
I named the second script “SetSkypeStatus_off.ps1”.
There are several other parameters you can pass into the “ChangeUserStatus” method. Here are the values I know about:
| Status | Code Sample |
| OFFLINE | $skype.Convert.TextToUserStatus("OFFLINE") |
| ONLINE | $skype.Convert.TextToUserStatus("ONLINE") |
| RINGING | $skype.Convert.TextToUserStatus("RINGING") |
| INPROGRESS | $skype.Convert.TextToUserStatus("INPROGRESS") |
| BUSY | $skype.Convert.TextToUserStatus("BUSY") |
Of course, you can automate most actions on the Skype client using the component (not just setting your online status). You can schedule calls, send text messages, etc. But I’m only concerned with my online status.
Step 3: Set up Windows Scheduled Tasks
Now you have two scripts to go Offline and Online. You just need to have something trigger them. I use Windows Scheduled Tasks. In Control Panel, go to the Scheduled Tasks window. You’ll see a list of scheduled tasks for your pc. Right client and select “Add”—>”Scheduled Task” (Don’t go through the “Add Scheduled Task” wizard). Name your task “SkypeStatusOn”. Right-click the task and choose “Properties”.
Now, in the “Run:” box, type the following command:
powershell -command "& 'c:\temp\SetSkypeStatus_on.ps1' "
Make sure the path is pointed to you PowerShell script you’ve created.
You can now use the “Schedule” tab to schedule when you want the script to run. Click “OK”.
Now do the same for the other script. You can test these scripts by right-clicking the task and selecting “Run”. You should be able to watch your Skype status go from offline to online.
By the way, the first time you run this, Skype will ask if you want PowerShell to have access to Skype. Click “Allow”.
If everything works successfully, your pc should set your online status and give you the “Opening Hours” that Skype forgot.
I hope you find this useful.
Related posts:


March 17th, 2010 - 01:35
I was googling around for something to schedule my Skype status and found your page. Thanks for this very useful starting point for me as well as introducing me to Powershell which I have never worked with before. I have not dabbled with any form of scripting before. I couldn’t get it to work to start with and then after a little research and thought etc, I checked to see if I needed something in the “Start In” field for my scheduled tasks. In my case, it seems that it did, as it did not work for me until I put something in there.
I needed to specify the location of the Powershell.exe file. I found this quickly by going Start > All Programs > Accessories and then found the link for Windows Powershell then right click on Properties and selected and copied everything except the file name itself. So you would get something like:
%SystemRoot%\system32\WindowsPowerShell\v1.0\
(I am sure you know how to do that last bit, but if you are adding this to your page, then I am sure some may need this hint)
I then pasted this into the “Start In” field for each of the scheduled tasks that you mention above. I tested as suggested using right click and Run and this time they both briefly opened up the shell prompted me to allow access to Skype and they ran fine after that. Thank you very much for this once again.
March 17th, 2010 - 09:06
Thanks for the help Allen. I’m glad it’s working well for you.
Powershell can do a lot, but it is a bit over-hyped in the industry I think. Still, you can automate a lot of routine tasks with it.
May 26th, 2010 - 11:01
This is exactly what I need. Unfortunately I was not able to get it to work. When I run the script in powershell gui, I already receive errors. I am using Windows 7, Skype 4 and a USB RJ45 box for connecting my regular phone. My system language is not English, so I had to translate some messages.
New-Object : Die COM-classfactory for the component with CLSID {830690FC-BF2F-47A6-AC2D
-330BCB402664} could not be run due to following error: 80040154.
At C:\Skype\SetSkypeStatus_on.ps1:2 Character:20
+ $skype = New-Object <<<< -COM "Skype4COM.Skype"
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObje
ctCommand
You cannot run a method for an expression with the value NULL.
At C:\Skype\SetSkypeStatus_on.ps1:8 Character:48
+ $onlineStatus = $skype.Convert.TextToUserStatus <<<< ("ONLINE")
+ CategoryInfo : InvalidOperation: (TextToUserStatus:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot run a method for an expression with the value NULL.
At C:\Skype\SetSkypeStatus_on.ps1:11 Zeichen:24
+ $skype.ChangeUserStatus <<<< ($onlineStatus)
+ CategoryInfo : InvalidOperation: (ChangeUserStatus:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull
Do you have a clue, what the problem is? Thank you!
May 26th, 2010 - 11:07
Thanks Garth.
It looks to me like the Skype Com component is not registered properly. Can you re-register it? User Regsvr32.
Eric
May 26th, 2010 - 12:01
Thank you for your quick reply, Eric!
I tried to re-register the Skype Com component by running “regsvr32 c:\Skype\Skype4COM.dll” as administrator. I received the success message again, but it still does not work.
DLLRegisterServer in c:\Skype\Skype4COM.dll succesfully registered.
Anything else I can try?
July 1st, 2010 - 22:59
Garth,
Use 32Bit Powershell and all should be good as 64 bit PS cant interact with 32 Bit COM objects.
32Bit powershell lives in C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
so run my script in task manager I use :
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -command “& ‘c:\temp\SetSkypeStatus_on.ps1′ ”
Eric,
Great post works a charm. I’ll never forget to online when I leave work again
July 2nd, 2010 - 06:17
Thanks Fija. I’m glad its working for you. And thanks for answering Garth’s query.