Sending dos commands

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi all,

I have to create a windows service in VB.NET. The service has to encrypt a
file using PGP. I have tried using NDSPGP component but out of 3 machines,
it only works on one (doesn't even work where I developed it, but I was
confident it should work so tried it on another developers machine and it
worked there.)

Anyhow, I have worked out the commands to encrypt using PGP from dos. This
appears to work fine when I use a command prompt.

So, I need to transfer that into vb.net.

Here, I have...


Proc = New Process
With Proc.StartInfo
.FileName = "cmd.exe"
.Arguments = "set PGPPASS=" & PGPSigningPhrase
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With

Proc.Start()
Proc.WaitForExit()

With Proc.StartInfo
.FileName = "pgp.exe"
.Arguments = "-es " & sInputFile & " " & PGPRecipientKey &
" -u " & PGPSigningKey
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With

Proc.Start()


but it is not working, nor is it erroring.

The first part sets the PGPPASS. This is required so that when running PGP,
it doesn't ask for the passphrase.

The second part is actually to run the PGP command.

Any ideas on how I can get this to work?

In my case, the pgp.exe file is in the path variable, so it doesn't need to
be explicitly referenced.


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
David said:
Hi all,

I have to create a windows service in VB.NET. The service has to encrypt a
file using PGP. I have tried using NDSPGP component but out of 3 machines,
it only works on one (doesn't even work where I developed it, but I was
confident it should work so tried it on another developers machine and it
worked there.)

Anyhow, I have worked out the commands to encrypt using PGP from dos. This
appears to work fine when I use a command prompt.

So, I need to transfer that into vb.net.

Here, I have...


Proc = New Process
With Proc.StartInfo
.FileName = "cmd.exe"
.Arguments = "set PGPPASS=" & PGPSigningPhrase
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With

Proc.Start()
Proc.WaitForExit()

With Proc.StartInfo
.FileName = "pgp.exe"
.Arguments = "-es " & sInputFile & " " & PGPRecipientKey &
" -u " & PGPSigningKey
.UseShellExecute = False
.RedirectStandardOutput = True
.CreateNoWindow = True
End With

Proc.Start()


but it is not working, nor is it erroring.

The first part sets the PGPPASS. This is required so that when running PGP,
it doesn't ask for the passphrase.

The second part is actually to run the PGP command.

Any ideas on how I can get this to work?

In my case, the pgp.exe file is in the path variable, so it doesn't need to
be explicitly referenced.


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

It is likely the tests you are doing from the command prompt are using a
typical user log in, but the service is running under a limited account, such
as Local System or Local Service. Make sure the appropriate service account
has access to the executable and folders needed, and that the full path to
pgp.exe is specified. I don't think service accounts can use a path
environment.
 
Hi,

Thanks for the advice...

I have fixed the issue of setting the PGPPASS. The Proc.Startinfo has a
..EnvironmentVariables that I can add the PGPPASS.

However, I have a new problem...

This now works fine on my development machine, wether I have the service
running under my user account or the local system. (I have tried both, it
seems that the path is not required, though I will try it.) However,
(subject to what I have just said about path), it doesn't work on the
destination machine. I will try the path, but not holding out much hope for
that. I will also look at the permissions on PGP.exe and the private/public
keyrings.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Back
Top