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:skypeSkype4COM-1.0.32Skype4COM.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:tempSetSkypeStatus_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.
Allen Hyde says
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%system32WindowsPowerShellv1.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.
Eric Wroolie says
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.
Garth says
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:SkypeSetSkypeStatus_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:SkypeSetSkypeStatus_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:SkypeSetSkypeStatus_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!
Eric Wroolie says
Thanks Garth.
It looks to me like the Skype Com component is not registered properly. Can you re-register it? User Regsvr32.
Eric
Garth says
Thank you for your quick reply, Eric!
I tried to re-register the Skype Com component by running “regsvr32 c:SkypeSkype4COM.dll” as administrator. I received the success message again, but it still does not work.
DLLRegisterServer in c:SkypeSkype4COM.dll succesfully registered.
Anything else I can try?
Fija says
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:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe
so run my script in task manager I use :
C:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe -command “& ‘c:tempSetSkypeStatus_on.ps1’ ”
Eric,
Great post works a charm. I’ll never forget to online when I leave work again 😀
Eric Wroolie says
Thanks Fija. I’m glad its working for you. And thanks for answering Garth’s query.
asaf.nahshon says
on the new powershell 2.0 you need to allow customs scripts to run on the computer by this command: “powershell.exe set-executionpolicy remotesigned”
if you aren’t allowing, the scripts will not run.
uwe says
Hi Eric, I registered the dll and tried the code however I get the following error each time I run the script
PS C:Dokumente und EinstellungenUwe> $onlineStatus = $skype.Convert.TextToUserStatus(“OFFLINE”)
You cannot call a method on a null-valued expression.
At line:1 char:48
+ $onlineStatus = $skype.Convert.TextToUserStatus <<<< ("OFFLINE")
+ CategoryInfo : InvalidOperation: (TextToUserStatus:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I also get no question from Skype if I want to allow the access.
Uwe
Uwe says
Hi, great Posting. Helped me a lot to write some simple C# code, you can find here: http://uweziegenhagen.de/?p=1429
Thanks, Uwe
Eric Wroolie says
Thanks Uwe. Your app looks very cool. I’m glad it helped.
Yorgo Petsas says
Hi,
I want to use your script but I have a small problem, I am simultaneously using two skypes at the same time – one personal and one for client services. I want to schedule the one for client services. In the script I see you have step
#Get the logged in user
Well if I have two logged in users it will ether change the status of both or of none? The option to change the status of both is still acceptable but I prefer to be able to set only on the company – do you think I have a solution.
If it helps – I use this to run 2 skype at a time
SkypePhoneSkype.exe” /secondary
Thank you !
Eric Wroolie says
Hi Yorgo. I’m afraid I’ve only ever used Skype with one logon. I’m not sure how to get around your problem. However, I appreciate your pointing out how to use two Skype accounts simultaneously. That’s very cool.
Chris says
Sorry to revive an old post, but this is awesome! And to anyone else who finds this, it still works perfectly.
I’ve been looking for something like this for a long time and never took the time to go through all this before, but now it is working perfectly!
Thanks Eric, and thanks to Fijaan too, and maybe asaf too (not sure if that command was required or not, but I did it anyways).
wroolie says
Hi Chris. Wow! This is an old post. I’m glad it still works. Thanks for letting me know.