Link to home
Start Free TrialLog in
Avatar of analliah
analliahFlag for United States of America

asked on

Shell String in VB.net

I have a VB.Net to perform encryption of files using PGP.

The line of argument,that is passed in the DOS Window is as below.
gpg  --recipient  "XXX"  --output "C:\Filename.zip.gpg"  --encrypt "C:\Filename.zip"

Here is my Function in VB.net.

            Dim GPG As New FileInfo("C:\Program Files\GNU\GnuPG\gpg.exe")
            Dim sGPGLocation As String
            Dim sCommandLine As String = Nothing
            Dim extension = ".gpg"
            'gpgEncryptName would be passed from a function eventually
            Dim gpgEncryptName As String = "C:\Testing.zip"
            Dim publicKey As String = "XXX"
            '-------Ensure we can find GPG.exe------
            If GPG.Exists = True Then
                sGPGLocation = "C:\Program Files\GNU\GnuPG\gpg.exe"
            Else
                Console.WriteLine("Error: Couldn't find GPG.EXE")
                'Return False
            End If
sCommandLine = """ & --recipient & """" """" "" & publicKey & "" """" """" & --output & """" """" "" & gpgEncryptName & extension & "" """" """" & --encrypt & """" """" "" & gpgEncryptName & """
Console.WriteLine(sCommandLine)
Shell("""--recipient & """ """ & publicKey & """ """ & --output & """ """ & gpgEncryptName """" & """" extension & """" --encrypt """" & """" gpgEncryptName """)
            'Return True
        Catch ex As IOException
            Console.WriteLine("Unable to locate GPG Software")

How can I represent gpg  --recipient  "XXX"  --output "C:\Filename.zip.gpg"
--encrypt "C:\Filename.zip"
in the Shell.Im not very familiar on how to represent empty space and [""] in the String.


Avatar of sirbounty
sirbounty
Flag of United States of America image

I usually use the chr(34) equivalent...less confusing...have you tried something like this?

sCommandLine = " --recipient " & chr(34) &  publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)
Avatar of analliah

ASKER

This is what I get
" --recipient "XXX" --output "C:\Testing.zip.gpg" --encrypt "C:\Testing.zip""

There is an extra " " at the very begining and end.
What does chr(34) represent ?
Is there a special character for space as well?
chr(34) is the equivalent of "If you don't need the others, simply remove them, but I think these are actually in the next line...no?sCommandLine = " --recipient " & chr(34) &  publicKey & chr(34) & " --output " & chr(34) & gpgEncryptName & extension & chr(34) & " --encrypt " & chr(34) & gpgEncryptName & chr(34)Console.WriteLine(sCommandLine)'Changing this next line work?Shell(sCommandLine)
My bad.It works fine.Thank You
What does chr(34) represent ?
Is there a special character for space as well?
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial