<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="https://forum.yubico.com/feed.php?f=26&amp;t=1858" />

<title>Yubico Forum</title>
<subtitle>...visit our web-store at</subtitle>
<link href="https://forum.yubico.com/index.php" />
<updated>2015-04-27T18:47:34+01:00</updated>

<author><name><![CDATA[Yubico Forum]]></name></author>
<id>https://forum.yubico.com/feed.php?f=26&amp;t=1858</id>
<entry>
<author><name><![CDATA[mfaine]]></name></author>
<updated>2015-04-27T18:47:34+01:00</updated>
<published>2015-04-27T18:47:34+01:00</published>
<id>https://forum.yubico.com/viewtopic.php?t=1858&amp;p=7264#p7264</id>
<link href="https://forum.yubico.com/viewtopic.php?t=1858&amp;p=7264#p7264"/>
<title type="html"><![CDATA[[SOLVED] Sharing Violation with GPG2.1 and Windows 7]]></title>

<content type="html" xml:base="https://forum.yubico.com/viewtopic.php?t=1858&amp;p=7264#p7264"><![CDATA[
I have been fighting a battle with a sharing violation for about 3 days now and I finally solved the problem so I thought I'd document my solution here in case it is in any way helpful to others.<br /><br />I'm using GPG2.1 on Windows 7 with two other card readers in addition to the Yubikey Neo.  After a lot of searching the common consensus was that this is caused by another program blocking scdaemon's access.  But which one?  Through the process of elimination I found that, at least for me, the process is the service &quot;Certificate Propagation Service&quot;. <br /><br />I cobbled together a script from snippets I found online and set it to run (with highest privileges) on login using Task Scheduler.  It still isn't perfect, for example, I'd like for it to mount my flash drive if it's not already mounted, but I haven't figured out how to do that yet.  However, it will wait until I get around to doing it manually.  My GPG keyring is on a bitlocker encrypted flash drive, so it's important that it wait until the drive is accessible.  You may not need this part so you can of course modify it to suit your needs.  I'm sure there are different ways to accomplish this and most likely even better ways, and I'd appreciate any improvements, but it works for me as is, at least well enough.<br /><br />The script basically just stop the problem service, restarts the smart card service, runs gpg --card-status, then starts the certificate propagation service up again.<br /><br />Sources:<br /><!-- m --><a class="postlink" href="http://www.motobit.com/tips/detpg_vbs-wmi-restart-service/">http://www.motobit.com/tips/detpg_vbs-w ... t-service/</a><!-- m --><br /><!-- m --><a class="postlink" href="http://www.tek-tips.com/viewthread.cfm?qid=1619385">http://www.tek-tips.com/viewthread.cfm?qid=1619385</a><!-- m --><br /><!-- l --><a class="postlink-local" href="http://forum.yubico.com/viewtopic.php?f=26&amp;t=1718">viewtopic.php?f=26&amp;t=1718</a><!-- l --><br />* Some others I don't remember<br /><br /><div class="codetitle"><b>Code:</b></div><div class="codecontent">Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br />Set WshShell = CreateObject(&quot;WScript.Shell&quot; )<br /><br />' Make sure that the USB flash drive containing my GnuPG keyring is mounted.<br />' It's encrypted so we need to wait, since we don't want to do anything else until it is mounted.<br />Do<br />If fso.FolderExists(&quot;D:\private\gpg&quot;) Then<br />   'safe to continue<br />   Exit Do<br />Else<br />   WScript.Sleep 10000<br />End If<br />Loop<br /><br />StopService &quot;.&quot;, &quot;CertPropSvc&quot;, True<br />RestartServices &quot;.&quot;, &quot;SCardSvr&quot;<br />gpgagent = Quotes(&quot;C:\Program Files (x86)\GnuPG\bin\gpg.exe&quot;) &amp; _<br />&quot; --card-status &quot;<br />WshShell.Run gpgagent, 0<br />' Give it a chance to start the daemon and read from the smart card<br />WScript.Sleep 10000<br />StartService &quot;.&quot;, &quot;CertPropSvc&quot;, True<br />Set WshShell = Nothing<br /><br />Sub RestartServices(Computer, ServiceNames) <br />  Dim ServiceName, Counter, aServiceNames<br /><br />  'Get the array of service names  <br />  aServiceNames = split(ServiceNames,&quot;,&quot;)<br />  <br />  'loop services from beginning, stop them <br />  For Each ServiceName In aServiceNames <br />    StopService Computer, ServiceName, True<br />  Next <br /><br />  'loop services from end, start them <br />  For Counter = ubound(aServiceNames) To 0 Step -1 <br />    StartService Computer, aServiceNames(Counter), True <br />  Next <br />End Sub<br /><br />Function Quotes(ByVal strValue)<br />    Quotes = Chr(34) &amp; strValue &amp; Chr(34)<br />End Function<br /><br />Sub StopService(Computer, ServiceName, Wait)<br />  Dim cimv2, oService, Result<br /><br />  'Get the WMI administration object    <br />  Set cimv2 = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; _  <br />  Computer &amp; &quot;\root\cimv2&quot;)<br /><br />  'Get the service object<br />  Set oService = cimv2.Get(&quot;Win32_Service.Name='&quot; &amp; ServiceName &amp; &quot;'&quot;)<br />  <br />  'Check base properties<br />  If Not oService.Started Then<br />    ' the service is Not started<br />    'wscript.echo &quot;The service &quot; &amp; ServiceName &amp; &quot; is Not started&quot;<br />    exit Sub<br />  End If<br /><br />  If Not oService.AcceptStop Then<br />    ' the service does Not accept stop command<br />    'wscript.echo &quot;The service &quot; &amp; ServiceName &amp; &quot; does Not accept stop command&quot;<br />    exit Sub<br />  End If<br />  <br />  'wscript.echo oService.getobjecttext_<br /><br />  'Stop the service<br />  Result  = oService.StopService<br />  If 0 &lt;&gt; Result Then<br />    'wscript.echo &quot;Stop &quot; &amp; ServiceName &amp; &quot; error: &quot; &amp; Result<br />    exit Sub <br />  End If <br />  <br />  Do While oService.Started And Wait<br />    'get the current service state<br />    Set oService = cimv2.Get(&quot;Win32_Service.Name='&quot; &amp; ServiceName &amp; &quot;'&quot;)<br />    'wscript.echo now, &quot;StopService&quot;, ServiceName, oService.Started, _ <br />   'oService.State, oService.Status<br />    Wscript.Sleep 200<br />  Loop   <br />End Sub<br /><br /><br />Sub StartService(Computer, ServiceName, Wait)<br />  Dim cimv2, oService, Result<br /><br />  'Get the WMI administration object    <br />  Set cimv2 = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; _ <br />  Computer &amp; &quot;\root\cimv2&quot;)<br /><br />  'Get the service object<br />  Set oService = cimv2.Get(&quot;Win32_Service.Name='&quot; &amp; ServiceName &amp; &quot;'&quot;)<br />    <br />  'Path = &quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; Computer &amp; _<br />  '  &quot;\root\cimv2:Win32_Service.Name='&quot; &amp; ServiceName &amp; &quot;'&quot; <br /><br />  'Get the WMI administration object of the service    <br />  'Set oService = GetObject(Path)<br /><br />  'Check base properties<br />  If oService.Started Then<br />    ' the service is Not started<br />    'wscript.echo &quot;The service &quot; &amp; ServiceName &amp; &quot; is started.&quot;<br />    exit Sub<br />  End If<br />  <br />  'Start the service<br />  Result = oService.StartService<br />  If 0 &lt;&gt; Result Then<br />    'wscript.echo &quot;Start &quot; &amp; ServiceName &amp; &quot; error:&quot; &amp; Result<br />    exit Sub <br />  End If <br />  <br />  Do While InStr(1,oService.State,&quot;running&quot;,1) = 0 And Wait <br />    'get the current service state<br />    Set oService = cimv2.Get(&quot;Win32_Service.Name='&quot; &amp; ServiceName &amp; &quot;'&quot;)<br />    'wscript.echo now, &quot;StartService&quot;, ServiceName, oService.Started, _<br />   'oService.State, oService.Status<br />    Wscript.Sleep 200<br />  Loop   <br />End Sub<br /></div><br /><br />I hope this saves someone a little time and stress.<p>Statistics: Posted by <a href="https://forum.yubico.com/memberlist.php?mode=viewprofile&amp;u=1935">mfaine</a> — Mon Apr 27, 2015 6:47 pm</p><hr />
]]></content>
</entry>
</feed>