Solved

Shell String in VB.net

Posted on 2008-10-28
7
759 Views
Last Modified: 2012-06-21
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.


0
Comment
Question by:analliah
  • 3
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22822020
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)
0
 
LVL 5

Author Comment

by:analliah
ID: 22822172
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?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22822228
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)
0
 
LVL 5

Author Comment

by:analliah
ID: 22822234
My bad.It works fine.Thank You
What does chr(34) represent ?
Is there a special character for space as well?
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 22822246
site messed up my quotes in that last post, but yes chr(34) is the equivalent of a double quote (chr(39) is a single quote).
I usually just drop the space inside the quotes...glad it's working for you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question