Solved

Shell String in VB.net

Posted on 2008-10-28
7
757 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now