Search code examples
c++windows-serviceswindows-firewall-api

Restricting a Service using Windows Firewall APIs not finding service shortname


I am using the example to restrict all except one port for a specific windows service. I took the example from msdn and tried it for OpenVPN windows service. Basically I just edited these two lines:

BSTR bstrServiceName = SysAllocString(L"OpenVPNServiceInteractive"); 
BSTR bstrAppName = SysAllocString(L"C:\\Program Files\\OpenVPN\\bin\\openvpnserv.exe");

As it needs the shortname and not the display name, I did sc query in my console and found for OpenVPNServiceInteractive, but when I run it doesn't find the service shortname (it fails the handle and says: RestrictService failed: Make sure you specified a valid service shortname)

So it basically can't find the service shortname which I specified. Does it prints (sc query) the real shortname of a service? Why doesn't it finds it?


Solution

  • It failed to restrict the service because I lacked administrator privileges. Ran it as administrator and worked.